1 7 package org.jboss.remoting.samples.simple; 8 9 import javax.management.MBeanServer ; 10 import org.jboss.remoting.InvocationRequest; 11 import org.jboss.remoting.InvokerLocator; 12 import org.jboss.remoting.ServerInvocationHandler; 13 import org.jboss.remoting.ServerInvoker; 14 import org.jboss.remoting.callback.InvokerCallbackHandler; 15 import org.jboss.remoting.transport.Connector; 16 17 23 public class SimpleServer 24 { 25 private static String transport = "socket"; 27 private static String host = "localhost"; 28 private static int port = 5400; 29 30 private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 32 33 34 public void setupServer(String locatorURI) throws Exception 35 { 36 InvokerLocator locator = new InvokerLocator(locatorURI); 40 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 41 Connector connector = new Connector(); 42 connector.setInvokerLocator(locator.getLocatorURI()); 43 connector.create(); 45 46 SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); 48 connector.addInvocationHandler("sample", invocationHandler); 50 51 connector.start(); 54 55 } 56 57 63 public static void main(String [] args) 64 { 65 if(args != null && args.length == 3) 66 { 67 transport = args[0]; 68 host = args[1]; 69 port = Integer.parseInt(args[2]); 70 } 71 String locatorURI = transport + "://" + host + ":" + port; 72 SimpleServer server = new SimpleServer(); 73 try 74 { 75 server.setupServer(locatorURI); 76 77 while(true) 79 { 80 Thread.sleep(1000); 81 } 82 83 } 84 catch(Exception e) 85 { 86 e.printStackTrace(); 87 } 88 } 89 90 94 public static class SampleInvocationHandler implements ServerInvocationHandler 95 { 96 103 public Object invoke(InvocationRequest invocation) throws Throwable 104 { 105 System.out.println("Invocation request is: " + invocation.getParameter()); 107 System.out.println("Returning response of: " + RESPONSE_VALUE); 108 return RESPONSE_VALUE; 110 } 111 112 118 public void addListener(InvokerCallbackHandler callbackHandler) 119 { 120 } 122 123 129 public void removeListener(InvokerCallbackHandler callbackHandler) 130 { 131 } 133 134 139 public void setMBeanServer(MBeanServer server) 140 { 141 } 143 144 149 public void setInvoker(ServerInvoker invoker) 150 { 151 } 153 154 } 155 } | Popular Tags |