Application proxies in the Infor Grid

Here is how to create and invoke application proxies of the Infor Grid.

What is an application proxy?

An application proxy is an interface for a Grid application that other applications of the Grid or client applications outside the Grid can invoke; it is inter-process communication in a distributed environment.

Example. The proxy for Grid application C is invoked from grid application A of a different host, from grid application D of the same host, and from client application K outside the Grid.

How to create an application proxy?

To create a proxy for a Grid application:

package net.company.your;

import com.lawson.grid.node.application.ApplicationEntryPoint;
import com.lawson.grid.node.application.ModuleContext;
import com.lawson.grid.proxy.ProxyException;
import com.lawson.grid.proxy.ProxyServer;

public interface HelloWorldProxy {
    public String hello(String name) throws ProxyException;
}

public class HelloWorld implements HelloWorldProxy {
    public String hello(String name) {
        return "Hello, " + name;
    }
}

public class HelloWorldApp implements ApplicationEntryPoint {
    public boolean startModule(ModuleContext context) {
        ProxyServer.registerProxy(HelloWorldProxy.class, new HelloWorld());
        return true;
    }
    public void stopModule() {
    }
}

Note: For details on how to create a Grid application, refer to the previous post on the subject.

The proxy is now ready to be invoked:
8

How to call the proxy from a Grid application?

To invoke the proxy from a Grid application:

The short source code is:

Registry registry = Node.getRegistry();
HelloWorldProxy proxy = registry.getProxy(HelloWorldProxy.class);
String result = proxy.hello("Thibaud");

The long source code is:

package net.company2.your;

import com.lawson.grid.node.application.ApplicationEntryPoint;
import com.lawson.grid.node.application.ModuleContext;
import com.lawson.grid.node.Node;
import com.lawson.grid.proxy.ProxyException;
import com.lawson.grid.registry.Registry;
import net.company.your.HelloWorldProxy;

public class HelloWorldApp2 implements ApplicationEntryPoint {
	public boolean startModule(ModuleContext context) {
		// connect
		Registry registry = Node.getRegistry();
		if (!registry.isConnected()) {
			System.err.println("failed to connect");
			return false;
		} else {
			System.out.println("connected to " + registry.getGridName());
		}
		// get the proxy
		HelloWorldProxy proxy = (HelloWorldProxy)registry.getProxy(HelloWorldProxy.class);
		if (proxy == null) {
			System.err.println("failed to get proxy...exiting");
			return false;
		} else {
			System.out.println("got proxy");
		}
		// invoke the proxy
		try {
			String result = proxy.hello("Thibaud");
			System.out.println(result);
		} catch (ProxyException e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public void stopModule() {
	}

}

How to call the proxy from a client application?

To invoke the application proxy from a client application outside the Grid:

First, choose a Grid registry’s hostname and port number (a registry is a special node that keeps track of all nodes in a Grid):

Then, connect to the Grid, get the proxy and invoke its methods.

The short source code is:

ClientRegistry registry = new ClientRegistry("Test");
registry.connect(hostname, portNumber);
HelloWorldProxy proxy = registry.getProxy(HelloWorldProxy.class);
String result = proxy.hello("Thibaud");

The long source code is:

import com.lawson.grid.proxy.ProxyConnectionFailedException;
import com.lawson.grid.proxy.ProxyException;
import com.lawson.grid.proxy.access.GridPrincipal;
import com.lawson.grid.proxy.access.SessionId;
import com.lawson.grid.proxy.access.SessionProvider;
import com.lawson.grid.proxy.access.SessionUtils;
import com.lawson.grid.registry.ClientRegistry;
import net.company.your.HelloWorldProxy;

public class Test {
    public static void main(String[] args) {

        // connect
        ClientRegistry registry = new ClientRegistry("Test");
        try {
            registry.connect("host1623", 22102);
        } catch (ProxyConnectionFailedException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            return;
        }
        if (!registry.isConnected()) {
            System.err.println("failed to connect");
            return;
        } else {
            System.out.println("connected to " + registry.getGridName());
        }

        // get the proxy
        HelloWorldProxy proxy = (HelloWorldProxy)registry.getProxy(HelloWorldProxy.class);
        if (proxy == null) {
            System.err.println("failed to get proxy...exiting");
            return;
        } else {
            System.out.println("got proxy");
        }

        // invoke the proxy
        try {
            String result = proxy.hello("Thibaud");
            System.out.println(result);
        } catch (ProxyException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            return;
        }

        // disconnect
        registry.close();
        if (!registry.isClosed()) {
            System.err.println("failed to close");
        } else {
            System.out.println("registry closed");
        }
    }

}

That’s it. Please like, subscribe, share.

Published by

thibaudatwork

M3 Technical Consultant

2 thoughts on “Application proxies in the Infor Grid”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s