1 package org.jboss.test.mx.remoting.pingpong; 2 3 import org.jboss.remoting.InvokerLocator; 4 import org.jboss.remoting.detection.multicast.MulticastDetector; 5 import org.jboss.remoting.ident.Identity; 6 import org.jboss.remoting.network.NetworkRegistry; 7 import org.jboss.remoting.transport.Connector; 8 import org.jboss.remoting.transport.PortUtil; 9 import org.w3c.dom.Document ; 10 11 import javax.management.MBeanServer ; 12 import javax.management.MBeanServerFactory ; 13 import javax.management.ObjectName ; 14 import javax.xml.parsers.DocumentBuilderFactory ; 15 import java.io.ByteArrayInputStream ; 16 17 25 public class PingPongTest 26 { 27 28 public static void main(String [] args) 29 { 30 try 31 { 32 System.setProperty("jboss.identity",Identity.createUniqueID()); 34 MBeanServer server = MBeanServerFactory.createMBeanServer(); 35 36 System.out.println("my identity is: "+Identity.get(server)); 37 38 39 NetworkRegistry registry = NetworkRegistry.getInstance(); 40 server.registerMBean(registry, new ObjectName ("remoting:type=NetworkRegistry")); 41 42 int port = PortUtil.findFreePort("localhost"); 43 44 Connector connector = new Connector(); 45 InvokerLocator locator = new InvokerLocator("socket://localhost:" + port); 46 StringBuffer buf = new StringBuffer (); 47 buf.append("<?xml version=\"1.0\"?>\n"); 48 buf.append("<handlers>\n"); 49 buf.append(" <handler subsystem=\"JMX\">org.jboss.mx.remoting.JMXSubsystemInvocationHandler</handler>\n"); 50 buf.append("</handlers>\n"); 51 Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream (buf.toString().getBytes())); 52 connector.setInvokerLocator(locator.getLocatorURI()); 53 connector.setConfiguration(xml.getDocumentElement()); 54 ObjectName obj = new ObjectName ("jboss.remoting:type=Connector,transport=" + locator.getProtocol()); 55 server.registerMBean(connector, obj); 56 57 connector.start(); 58 59 MulticastDetector detector = new MulticastDetector(); 60 server.registerMBean(detector, new ObjectName ("remoting:type=Detector,transport=multicast")); 61 detector.start(); 62 63 PingPong pp = new PingPong(); 64 ObjectName objName = new ObjectName ("test:type=PingPong"); 65 server.registerMBean(pp, objName); 66 } 67 catch(Throwable e) 68 { 69 e.printStackTrace(); 70 } 71 } 72 } 73 | Popular Tags |