1 7 package org.jboss.samples.detection; 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.detection.multicast.MulticastDetector; 15 import org.jboss.remoting.network.NetworkRegistry; 16 import org.jboss.remoting.transport.Connector; 17 18 import javax.management.MBeanServer ; 19 import javax.management.MBeanServerFactory ; 20 import javax.management.ObjectName ; 21 22 28 public class SimpleDetectorServer 29 { 30 private static String transport = "socket"; 32 private static String host = "localhost"; 33 private static int port = 5400; 34 35 private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 37 38 39 public void setupDetector() throws Exception 40 { 41 MBeanServer server = MBeanServerFactory.createMBeanServer(); 42 43 NetworkRegistry registry = NetworkRegistry.getInstance(); 44 server.registerMBean(registry, new ObjectName ("remoting:type=NetworkRegistry")); 45 46 MulticastDetector detector = new MulticastDetector(); 47 server.registerMBean(detector, new ObjectName ("remoting:type=MulticastDetector")); 48 detector.start(); 49 } 50 51 public void setupServer(String locatorURI) throws Exception 52 { 53 InvokerLocator locator = new InvokerLocator(locatorURI); 54 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 55 Connector connector = new Connector(); 56 connector.setInvokerLocator(locator.getLocatorURI()); 57 connector.start(); 58 59 SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); 60 connector.addInvocationHandler("sample", invocationHandler); 62 } 63 64 70 public static void main(String [] args) 71 { 72 if(args != null && args.length == 2) 73 { 74 transport = args[0]; 75 port = Integer.parseInt(args[1]); 76 } 77 String locatorURI = transport + "://" + host + ":" + port; 78 SimpleDetectorServer server = new SimpleDetectorServer(); 79 try 80 { 81 server.setupDetector(); 82 server.setupServer(locatorURI); 83 84 Thread.sleep(10000); 86 87 } 88 catch(Exception e) 89 { 90 e.printStackTrace(); 91 } 92 } 93 94 97 public static class SampleInvocationHandler implements ServerInvocationHandler 98 { 99 106 public Object invoke(InvocationRequest invocation) throws Throwable 107 { 108 System.out.println("Invocation request is: " + invocation.getParameter()); 110 111 return RESPONSE_VALUE; 113 } 114 115 121 public void addListener(InvokerCallbackHandler callbackHandler) 122 { 123 } 125 126 132 public void removeListener(InvokerCallbackHandler callbackHandler) 133 { 134 } 136 137 142 public void setMBeanServer(MBeanServer server) 143 { 144 } 146 147 152 public void setInvoker(ServerInvoker invoker) 153 { 154 } 156 157 } 158 } | Popular Tags |