Remote Reflection API
Remote Reflection is a Java API that makes it easier to call remote methods on remote JVM in a simple way without the need for any special configurations or common contract between client and server.
Test Service
package com.app.server;
public class Service {
public String hello(String name) {
return "Hello " + name + " from server";
}
}
Server
In the server application(the application which you want to expose its method remotely) , add the following after at the end of you main method:
package com.app.server;
import com.jk.core.reflection.server.ReflectionServer;
public class App {
public static void main(String[] args) {
ReflectionServer server = new ReflectionServer(7125);
server.start();
}
}
Thats it , now you can expose any method inside this application VM to your application client.
Client
In the client application(the application which should consume the remote method):
package com.app.client;
import com.jk.core.reflection.client.ReflectionClient;
import com.jk.core.reflection.common.MethodCallInfo;
public class App {
public static void main(String[] args) {
ReflectionClient client=new ReflectionClient("localhost", 7125);
MethodCallInfo info=new MethodCallInfo("com.app.server.Service", "hello", "Jalal");
client.callMethod(info);
String result = (String) info.getResult();
System.out.println(result);
}
}