1 7 package org.jboss.samples.simple; 8 9 import org.jboss.remoting.InvocationRequest; 10 import org.jboss.remoting.InvokerCallbackHandler; 11 import org.jboss.remoting.InvokerLocator; 12 import org.jboss.remoting.ServerInvocationHandler; 13 import org.jboss.remoting.ServerInvoker; 14 import org.jboss.remoting.transport.Connector; 15 16 import javax.management.MBeanServer ; 17 18 24 public class SimpleServer 25 { 26 private static String transport = "socket"; 28 private static String host = "localhost"; 29 private static int port = 5400; 30 31 private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 33 34 35 public void setupServer(String locatorURI) throws Exception 36 { 37 InvokerLocator locator = new InvokerLocator(locatorURI); 38 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 39 Connector connector = new Connector(); 40 connector.setInvokerLocator(locator.getLocatorURI()); 41 connector.start(); 42 43 SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); 44 connector.addInvocationHandler("sample", invocationHandler); 46 } 47 48 54 public static void main(String [] args) 55 { 56 if(args != null && args.length == 2) 57 { 58 transport = args[0]; 59 port = Integer.parseInt(args[1]); 60 } 61 String locatorURI = transport + "://" + host + ":" + port; 62 SimpleServer server = new SimpleServer(); 63 try 64 { 65 server.setupServer(locatorURI); 66 67 Thread.sleep(10000); 69 } 70 catch(Exception e) 71 { 72 e.printStackTrace(); 73 } 74 } 75 76 79 public static class SampleInvocationHandler implements ServerInvocationHandler 80 { 81 88 public Object invoke(InvocationRequest invocation) throws Throwable 89 { 90 System.out.println("Invocation request is: " + invocation.getParameter()); 92 93 return RESPONSE_VALUE; 95 } 96 97 103 public void addListener(InvokerCallbackHandler callbackHandler) 104 { 105 } 107 108 114 public void removeListener(InvokerCallbackHandler callbackHandler) 115 { 116 } 118 119 124 public void setMBeanServer(MBeanServer server) 125 { 126 } 128 129 134 public void setInvoker(ServerInvoker invoker) 135 { 136 } 138 139 } 140 } | Popular Tags |