1 7 package org.jboss.remoting.marshall.dynamic.remote.socket; 8 9 import org.apache.log4j.Level; 10 import org.jboss.remoting.AbstractInvokerTest; 11 import org.jboss.remoting.InvocationRequest; 12 import org.jboss.remoting.InvokerCallbackHandler; 13 import org.jboss.remoting.InvokerLocator; 14 import org.jboss.remoting.ServerInvocationHandler; 15 import org.jboss.remoting.ServerInvoker; 16 import org.jboss.remoting.transport.Connector; 17 18 import javax.management.MBeanServer ; 19 20 26 public class MarshallerLoadingServer extends AbstractInvokerTest implements MarshallerLoadingConstants 27 { 28 29 private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 31 32 public MarshallerLoadingServer(String name) 33 { 34 super(name); 35 } 36 37 public MarshallerLoadingServer(String name, int numberOfInstances) 38 { 39 super(name, numberOfInstances); 40 } 41 42 public MarshallerLoadingServer(String name, String transport, int port) 43 { 44 super(name, transport, port); 45 } 46 47 public MarshallerLoadingServer(String name, String transport, int port, int numberOfInstances) 48 { 49 super(name, transport, port, numberOfInstances); 50 } 51 52 53 public void setupServer() throws Exception 54 { 55 String mylocatorURI = MarshallerLoadingConstants.transport + "://" + host + ":" + MarshallerLoadingConstants.port + "/?" + 56 InvokerLocator.DATATYPE + "=" + dataType + "&" + 57 InvokerLocator.LOADER_PORT + "=" + 5401 + "&" + 58 InvokerLocator.MARSHALLER + "=" + TestMarshaller.class.getName() + "&" + 59 InvokerLocator.UNMARSHALLER + "=" + TestUnMarshaller.class.getName(); 60 61 System.out.println("mylocatorURI: " + mylocatorURI); 62 System.out.println("locatorURI: " + locatorURI); 63 InvokerLocator locator = new InvokerLocator(mylocatorURI); 65 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 66 Connector connector = new Connector(); 67 connector.setInvokerLocator(locator.getLocatorURI()); 68 connector.start(); 69 70 SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); 71 connector.addInvocationHandler("sample", invocationHandler); 73 } 74 75 public void serverTest() throws Exception 76 { 77 setupServer(); 78 startup(getNumberOfInstances()); 79 shutdown(); 80 } 81 82 88 public static void main(String [] args) 89 { 90 org.apache.log4j.BasicConfigurator.configure(); 91 org.apache.log4j.Category.getRoot().setLevel(Level.INFO); 92 org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG); 93 95 102 MarshallerLoadingServer server = new MarshallerLoadingServer(MarshallerLoadingServer.class.getName()); 103 try 104 { 105 server.serverTest(); 106 107 Thread.sleep(10000); 109 } 110 catch(Exception e) 111 { 112 e.printStackTrace(); 113 System.exit(1); 114 } 115 System.exit(0); 116 } 117 118 121 public static class SampleInvocationHandler implements ServerInvocationHandler 122 { 123 130 public Object invoke(InvocationRequest invocation) throws Throwable 131 { 132 System.out.println("Invocation request is: " + invocation.getParameter()); 134 135 return RESPONSE_VALUE; 137 } 138 139 145 public void addListener(InvokerCallbackHandler callbackHandler) 146 { 147 } 149 150 156 public void removeListener(InvokerCallbackHandler callbackHandler) 157 { 158 } 160 161 166 public void setMBeanServer(MBeanServer server) 167 { 168 } 170 171 176 public void setInvoker(ServerInvoker invoker) 177 { 178 } 180 181 } 182 } | Popular Tags |