1 7 package org.jboss.remoting.handler.mbean; 8 9 import org.jboss.remoting.AbstractInvokerTest; 10 import org.jboss.remoting.InvokerLocator; 11 import org.jboss.remoting.transport.Connector; 12 13 import javax.management.MBeanServer ; 14 import javax.management.MBeanServerFactory ; 15 import javax.management.ObjectName ; 16 17 20 public class ServerTest extends AbstractInvokerTest 21 { 22 private static String transport = "socket"; 24 private static String host = "localhost"; 25 private static int port = 5400; 26 27 private String locatorURI = null; 28 29 public static final String RESPONSE_VALUE = "This is the return from the TestServer invocation"; 31 32 public ServerTest(String name) 33 { 34 super(name); 35 } 36 37 public ServerTest(String name, String locatorURI) 38 { 39 super(name); 40 this.locatorURI = locatorURI; 41 } 42 43 public ServerTest(String name, int numberOfInstances) 44 { 45 super(name, numberOfInstances); 46 } 47 48 public ServerTest(String name, String transport, int port) 49 { 50 super(name, transport, port); 51 } 52 53 public ServerTest(String name, String transport, int port, int numberOfInstances) 54 { 55 super(name, transport, port, numberOfInstances); 56 } 57 58 59 public void setupServer() throws Exception 60 { 61 MBeanServer server = MBeanServerFactory.createMBeanServer(); 62 63 InvokerLocator locator = new InvokerLocator(locatorURI); 64 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 65 Connector connector = new Connector(); 66 connector.setInvokerLocator(locator.getLocatorURI()); 67 connector.start(); 68 69 server.registerMBean(connector, new ObjectName ("test:type=connector,transport=socket")); 70 71 MBeanHandler handler = new MBeanHandler(); 73 ObjectName objName = new ObjectName ("test:type=handler"); 74 server.registerMBean(handler, objName); 75 76 connector.addInvocationHandler("test", objName); 77 } 78 79 public void serverTest() throws Exception 80 { 81 try 82 { 83 setupServer(); 84 startup(getNumberOfInstances()); 85 shutdown(); 86 } 87 catch(Exception e) 88 { 89 throw e; 90 } 91 } 92 93 94 100 public static void main(String [] args) 101 { 102 if(args != null && args.length == 2) 103 { 104 transport = args[0]; 105 port = Integer.parseInt(args[1]); 106 } 107 String locatorURI = transport + "://" + host + ":" + port; 108 ServerTest serverTest = new ServerTest(ServerTest.class.getName(), locatorURI); 109 try 110 { 111 serverTest.serverTest(); 112 113 Thread.sleep(10000); 115 } 116 catch(Exception e) 117 { 118 e.printStackTrace(); 119 System.exit(1); 120 } 121 System.exit(0); 122 } 123 } | Popular Tags |