1 7 package org.jboss.test.remoting.connection; 8 9 import javax.management.MBeanServer ; 10 import org.jboss.jrunit.extensions.ServerTestCase; 11 import org.jboss.remoting.InvocationRequest; 12 import org.jboss.remoting.InvokerLocator; 13 import org.jboss.remoting.ServerInvocationHandler; 14 import org.jboss.remoting.ServerInvoker; 15 import org.jboss.remoting.callback.InvokerCallbackHandler; 16 import org.jboss.remoting.samples.simple.SimpleServer; 17 import org.jboss.remoting.transport.Connector; 18 19 22 public class ConnectionValidationServer extends ServerTestCase 23 { 24 private static String transport = "socket"; 26 private static String host = "localhost"; 27 private static int port = 5400; 28 private String locatorURI = transport + "://" + host + ":" + port; 29 30 private Connector connector = null; 31 32 private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 34 35 36 public void setupServer() throws Exception 37 { 38 InvokerLocator locator = new InvokerLocator(locatorURI); 39 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 40 connector = new Connector(); 41 connector.setInvokerLocator(locator.getLocatorURI()); 42 connector.create(); 43 SimpleServer.SampleInvocationHandler invocationHandler = new SimpleServer.SampleInvocationHandler(); 44 connector.addInvocationHandler("sample", invocationHandler); 46 connector.start(); 47 } 48 49 public void testShutdown() throws Exception 50 { 51 Thread.currentThread().sleep(10000); 53 connector.stop(); 54 connector.destroy(); 55 connector = null; 56 } 57 58 public void setUp() throws Exception 59 { 60 setupServer(); 61 } 62 63 public void tearDown() throws Exception 64 { 65 if(connector != null) 66 { 67 connector.stop(); 68 connector.destroy(); 69 } 70 } 71 72 78 public static void main(String [] args) 79 { 80 if(args != null && args.length == 3) 81 { 82 transport = args[0]; 83 host = args[1]; 84 port = Integer.parseInt(args[2]); 85 } 86 ConnectionValidationServer server = new ConnectionValidationServer(); 87 try 88 { 89 server.setupServer(); 90 server.testShutdown(); 91 } 92 catch(Exception e) 93 { 94 e.printStackTrace(); 95 } 96 } 97 98 101 public static class SampleInvocationHandler implements ServerInvocationHandler 102 { 103 110 public Object invoke(InvocationRequest invocation) throws Throwable 111 { 112 System.out.println("Invocation request is: " + invocation.getParameter()); 114 115 return RESPONSE_VALUE; 117 } 118 119 125 public void addListener(InvokerCallbackHandler callbackHandler) 126 { 127 } 129 130 136 public void removeListener(InvokerCallbackHandler callbackHandler) 137 { 138 } 140 141 146 public void setMBeanServer(MBeanServer server) 147 { 148 } 150 151 156 public void setInvoker(ServerInvoker invoker) 157 { 158 } 160 161 } 162 163 } | Popular Tags |