In this chapter we will describe the service calling methods without the need for server use while preserving a full flow of input/output data and other components including transaction manager, sequencers and exception handlers.
The example is illustrated in the following diagram.

As an example, we will take the code described in the service call chapter:
As a reminder:

Interface:

package com.jlupin.sampleapp.paramsfunction.service;

public interface DigestService {
    String getMD5Digest(String name, String surname) throws Throwable;
}

Class that implements the above interface:

package com.jlupin.sampleapp.paramsfunction.service.impl;

import com.jlupin.impl.util.security.JLupinSecurityUtil;
import com.jlupin.sampleapp.paramsfunction.service.DigestService;
import org.springframework.stereotype.Service;

@Service("digestService")
public class DigestServiceImpl implements DigestService {

    public DigestServiceImpl() {
    }

    @Override
    public String getMD5Digest(String name, String surname) throws Throwable {
        return JLupinSecurityUtil.getMD5DigestAsHexString(name+surname);
    }
}

Configuration file: spring-services.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <import resource="spring-jlupin-default-configuration.xml"/>

    <context:annotation-config/>
    <context:component-scan base-package="com.jlupin.sampleapp.paramsfunction.service.impl"/>
</beans>

Import file – spring-jlupin-default-configuration.xml is downloaded from the server (SERVERHOME/server-resources catalogue).

!Put this file (spring-jlupin-default-configuration.xml) to classpath on test project

Call (JUNIT test), remember about dependencies.

All required JLupin Next Server`s libraries (as JAR files) are available at jlupin-all-assembly-1.3.0.jar

<dependency>
    <groupId>com.jlupin</groupId>
    <artifactId>jlupin-all-assembly</artifactId>
    <version>${dependency.version.jlupin.ns}</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-asm</artifactId>
    <version>3.1.3.RELEASE</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.1.4.RELEASE</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>4.1.4.RELEASE</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.1.4.RELEASE</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>4.1.4.RELEASE</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>4.1.4.RELEASE</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>4.1.4.RELEASE</version>
    <scope>provided</scope>
</dependency>
 <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
 <dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.8.5</version>
</dependency>
<dependency>
    <groupId>de.ruedigermoeller</groupId>
    <artifactId>fst</artifactId>
    <version>2.40</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.1</version>
    <scope>test</scope>
</dependency>

Add libraries above by following commands (install MAVEN correctly before this)

mvn install:install-file -DgroupId=com.jlupin -DartifactId=jlupin-all-assembly -Dversion=1.3.0 -Dpackaging=jar -Dfile=jlupin-all-assembly-1.3.0.jar

In accordance with the principle of modularity and independence of components, the code that calls the service does not change.

Only the delegator (JLupinDefaultDelegatorImpl) will be different which instead of communicating with the server remotely will call the service directly in the implementation of the JLupinServiceProcessor.

Example:

package com.jlupin.test;

import com.jlupin.impl.client.delegator.JLupinDefaultDelegatorImpl;
import com.jlupin.impl.client.proxy.producer.JLupinDefaultProxyObjectProducerImpl;
import com.jlupin.impl.container.application.JLupinSingleApplicationContainerForLocalProcessImpl;
import com.jlupin.impl.invoker.JLupinDefaultApplicationInvokerImpl;
import com.jlupin.impl.logger.impl.simple.stdout.JLupinSimpleSystemOutLoggerImpl;
import com.jlupin.impl.processor.JLupinDefaultServiceProcessorImpl;
import com.jlupin.impl.processor.inner.JLupinDefaultInnerServiceProcessorImpl;
import com.jlupin.impl.serialize.JLupinFSTSerializerImpl;
import com.jlupin.interfaces.client.delegator.JLupinDelegator;
import com.jlupin.interfaces.client.proxy.producer.JLupinProxyObjectProducer;
import com.jlupin.interfaces.common.to.JLupinInputParameter;
import com.jlupin.interfaces.container.application.JLupinApplicationContainer;
import com.jlupin.interfaces.container.runtime.JLupinRuntimeContainer;
import com.jlupin.interfaces.logger.JLupinLogger;
import com.jlupin.interfaces.logger.enums.LogMode;
import com.jlupin.interfaces.processor.JLupinServiceProcessor;
import com.jlupin.interfaces.processor.inner.JLupinInnerServiceProcessor;
import com.jlupin.interfaces.serialize.JLupinSerializer;
import com.jlupin.sampleapp.paramsfunction.service.DigestService;

public class TestByLocal {

    private JLupinProxyObjectProducer jLupinProxyObjectProducer;
    private JLupinLogger jLupinLogger;

    @org.junit.Before
    public void before() throws Throwable {
        JLupinRuntimeContainer.buildJLupinRuntimeContainer();
        JLupinRuntimeContainer jLupinRuntimeContainer = JLupinRuntimeContainer.getInstance();

        jLupinRuntimeContainer.setApplicationName("testApplication");

        JLupinSimpleSystemOutLoggerImpl.initializeWithLogMode(LogMode.DEBUG);
        jLupinLogger = JLupinSimpleSystemOutLoggerImpl.getInstance();
        jLupinRuntimeContainer.setJLupinLogger(jLupinLogger);

        JLupinSerializer jLupinSerializer = JLupinFSTSerializerImpl.getInstance();
        jLupinRuntimeContainer.setJLupinSerializer(jLupinSerializer);

        JLupinServiceProcessor jLupinServiceProcessor = new JLupinDefaultServiceProcessorImpl();
        jLupinRuntimeContainer.setJLupinServiceProcessor(jLupinServiceProcessor);

        JLupinInnerServiceProcessor jLupinInnerServiceProcessor = new JLupinDefaultInnerServiceProcessorImpl();
        jLupinRuntimeContainer.setJLupinInnerServiceProcessor(jLupinInnerServiceProcessor);

        JLupinDelegator jLupinDelegator = new JLupinDefaultDelegatorImpl(jLupinServiceProcessor, jLupinLogger);
        jLupinRuntimeContainer.setJLupinApplicationInvoker(new JLupinDefaultApplicationInvokerImpl(jLupinDelegator));

        String[] configFiles = {"classpath:spring-jlupin-default-configuration.xml","classpath:spring-services.xml"};
        JLupinApplicationContainer jLupinApplicationContainer = new JLupinSingleApplicationContainerForLocalProcessImpl(configFiles);
        jLupinApplicationContainer.load();

        jLupinServiceProcessor.setJLupinApplicationContainer(jLupinApplicationContainer);
        jLupinServiceProcessor.after();

        jLupinRuntimeContainer.setJLupinApplicationContainer(jLupinApplicationContainer);
        jLupinProxyObjectProducer = new JLupinDefaultProxyObjectProducerImpl("testApplication", "testClientApplication",jLupinDelegator, jLupinLogger);
    }

    @org.junit.Test
    public void test() throws Throwable {
        JLupinInputParameter jLupinInputParameter = new JLupinInputParameter();
        jLupinInputParameter.setServiceName("digestService");
        DigestService digestService = jLupinProxyObjectProducer.produceObject(DigestService.class,jLupinInputParameter);
        String digest  = digestService.getMD5Digest("name", "surname");
        jLupinLogger.info("digest:" + digest);
    }

}

Description:

In before() method we prepare all needed object to call locally services.

First step is initiate the JLupinRuntimeContainer object - this step may be surprising, but in normal conditions, i.e. when running applications on the server, it is automatically initiated by the server. All creating object will be added to this runtime container.

JLupinRuntimeContainer.buildJLupinRuntimeContainer();
JLupinRuntimeContainer jLupinRuntimeContainer = JLupinRuntimeContainer.getInstance();
jLupinRuntimeContainer.setApplicationName("testApplication");

Next step is Logger creation:

JLupinSimpleSystemOutLoggerImpl.initializeWithLogMode(LogMode.DEBUG);
JLupinLogger jLupinLogger = JLupinSimpleSystemOutLoggerImpl.getInstance();
jLupinRuntimeContainer.setJLupinLogger(jLupinLogger);

Serializer creation:

JLupinSerializer jLupinSerializer = JLupinFSTSerializerImpl.getInstance();
jLupinRuntimeContainer.setJLupinSerializer(jLupinSerializer);

In the next step we initiate JLupinServiceProcessor and JLupinServiceInnerProcessor.

JLupinServiceProcessor jLupinServiceProcessor = new JLupinDefaultServiceProcessorImpl();
jLupinRuntimeContainer.setJLupinServiceProcessor(jLupinServiceProcessor);

JLupinInnerServiceProcessor jLupinInnerServiceProcessor = new JLupinDefaultInnerServiceProcessorImpl();
jLupinRuntimeContainer.setJLupinInnerServiceProcessor(jLupinInnerServiceProcessor);

The next step is the delegator:

JLupinDefaultDelegatorImpl communicates directly with JLupinProcessor for the purpose of calling a particular service at the level of the same JAVA VIRTUAL MACHINE.
As we remember from the chapter on service calling, the test that would call the services on the server differed only in the delegator implementation (reminder):

JLupinSocketDelegatorImpl jLupinDelegator = new JLupinSocketDelegatorImpl(jLupinLogger, jLupinSerializer);
jLupinDelegator.setSocketAddressToConnectServer(new InetSocketAddress("localhost", 9090));

In the next step we create application invoker (JLupinDefaultApplicationInvokerImpl with JLupinDefaultDelegatorImpl to communicate of the same JVM to communicare between services (Invoke Microservice from another Microservice chapter).

jLupinRuntimeContainer.setJLupinApplicationInvoker(new JLupinDefaultApplicationInvokerImpl(jLupinDelegator));

In the next step we initiate the application container (in operating conditions on the server it is loaded based on the application configuration file). The load method activates Spring's IOC mechanism:

String[] configFiles = {"classpath:spring-jlupin-default-configuration.xml","classpath:spring-services.xml"};
JLupinApplicationContainer jLupinApplicationContainer = new JLupinSingleApplicationContainerForLocalProcessImpl(configFiles);
jLupinApplicationContainer.load();

Next step is adding application container to JLupinServiceProcessor and call after() method to setting all references in inner JLupinServiceProcessor`s mechanisms.

jLupinServiceProcessor.setJLupinApplicationContainer(jLupinApplicationContainer);
jLupinServiceProcessor.after();

Last step is setting application container to runtime container and creating proxy to invoking services by interfaces (but this time on local JVM).

jLupinRuntimeContainer.setJLupinApplicationContainer(jLupinApplicationContainer);
jLupinProxyObjectProducer = new JLupinDefaultProxyObjectProducerImpl("testApplication", "testClientApplication",jLupinDelegator, jLupinLogger);

In test() method we call normally service - digestService:

@org.junit.Test
public void test() throws Throwable {
    JLupinInputParameter jLupinInputParameter = new JLupinInputParameter();
    jLupinInputParameter.setServiceName("digestService");
    DigestService digestService = jLupinProxyObjectProducer.produceObject(DigestService.class,jLupinInputParameter);
    String digest  = digestService.getMD5Digest("name", "surname");
    jLupinLogger.info("digest:" + digest);
}