<?xml version="1.0"?> <server xmlns="urn:jboss:remoting-ext:1.0"> <invoker protocol="rmi"/> <connector name="rmi"> <socket-binding name="rmi" port="1099"/> </connector> </server> <?xml version="1.0"?> <client xmlns="urn:jboss:remoting-ext:1.0"> <connector name="rmi"> <socket-binding name="rmi" port="1099"/> </connector> </client> <dependencies> <dependency> <groupId>jboss.remoting</groupId> <artifactId>jboss-remoting</artifactId> <version>4.0.0.Final</version> </dependency> </dependencies> import org.jboss.remoting.ServerInvoker; import org.jboss.remoting.ServerInvokerCallbackHandler; import java.util.HashMap; import java.util.Map; public class Server { public static void main(String[] args) throws Exception { Map<String, Object> context = new HashMap<>(); ServerInvoker serverInvoker = new RMIInvoker(); serverInvoker.setServerObjectName("RMIInvoker"); ServerInvokerCallbackHandler callbackHandler = new MyCallbackHandler(); serverInvoker.registerCallbackHandler(callbackHandler); serverInvoker.setInvocationContext(context); serverInvoker.start(); } } import org.jboss.remoting.proxy.RemotingProxyFactory; public class Client { public static void main(String[] args) throws Exception { RMIInvoker rmiInvoker = (RMIInvoker) RemotingProxyFactory.createProxy(RMIInvoker.class, "rmi://localhost:1099/"); String result = rmiInvoker.invokeMethod("Hello Remoting!"); System.out.println(result); } } <?xml version="1.0"?> <server xmlns="urn:jboss:remoting-ext:1.0"> <invoker protocol="rmi"> <attribute name="thread-pool"> <thread-pool> <name>my-pool</name> <max-pool-size>10</max-pool-size> <keep-alive-time>10000</keep-alive-time> </thread-pool> </attribute> </invoker> <connector name="rmi"> <socket-binding name="rmi" port="1099"/> </connector> </server> import org.jboss.remoting.callback.ResponseCallback; public class Client { public static void main(String[] args) throws Exception { RMIInvoker rmiInvoker = (RMIInvoker) RemotingProxyFactory.createProxy(RMIInvoker.class, "rmi://localhost:1099/"); ResponseCallback callback = new MyResponseCallback(); rmiInvoker.invokeMethodAsync("Hello Remoting!", callback); } } import org.jboss.remoting.ServerInvoker; import org.jboss.remoting.ServerInvokerCallbackHandler; import java.util.HashMap; import java.util.Map; public class Server { public static void main(String[] args) throws Exception { Map<String, Object> context = new HashMap<>(); ServerInvoker serverInvoker = new RMIInvoker(); serverInvoker.setServerObjectName("RMIInvoker"); ServerInvokerCallbackHandler callbackHandler = new MyCallbackHandler(); serverInvoker.registerCallbackHandler(callbackHandler); serverInvoker.setInvocationContext(context); serverInvoker.setExceptionHandler(new MyExceptionHandler()); serverInvoker.start(); } }


上一篇:
下一篇:
切换中文