KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > mx > remoting > pingpong > PingPongTest


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 JavaDoc;
10
11 import javax.management.MBeanServer JavaDoc;
12 import javax.management.MBeanServerFactory JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
15 import java.io.ByteArrayInputStream JavaDoc;
16
17 /**
18  * a simple ping pong test that will send notifications and make remote
19  * JMX invocations back and forth to other ping pong mbeans on the network
20  *
21  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
22  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
23  * @version $Revision: 58097 $
24  */

25 public class PingPongTest
26 {
27
28     public static void main(String JavaDoc[] args)
29     {
30         try
31         {
32             //org.apache.log4j.BasicConfigurator.configure();
33
System.setProperty("jboss.identity",Identity.createUniqueID());
34             MBeanServer JavaDoc 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 JavaDoc("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 JavaDoc buf = new StringBuffer JavaDoc();
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 JavaDoc xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream JavaDoc(buf.toString().getBytes()));
52             connector.setInvokerLocator(locator.getLocatorURI());
53             connector.setConfiguration(xml.getDocumentElement());
54             ObjectName JavaDoc obj = new ObjectName JavaDoc("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 JavaDoc("remoting:type=Detector,transport=multicast"));
61             detector.start();
62
63             PingPong pp = new PingPong();
64             ObjectName JavaDoc objName = new ObjectName JavaDoc("test:type=PingPong");
65             server.registerMBean(pp, objName);
66         }
67         catch(Throwable JavaDoc e)
68         {
69             e.printStackTrace();
70         }
71     }
72 }
73
Popular Tags