1 7 package org.jboss.remoting.marshall.dynamic.local; 8 9 import org.apache.log4j.Level; 10 import org.jboss.logging.Logger; 11 import org.jboss.remoting.AbstractInvokerTest; 12 import org.jboss.remoting.InvocationRequest; 13 import org.jboss.remoting.InvokerCallbackHandler; 14 import org.jboss.remoting.InvokerLocator; 15 import org.jboss.remoting.ServerInvocationHandler; 16 import org.jboss.remoting.ServerInvoker; 17 import org.jboss.remoting.transport.Connector; 18 19 import javax.management.MBeanServer ; 20 import java.io.IOException ; 21 import java.util.Enumeration ; 22 23 29 public class MarshallerLoadingServer extends AbstractInvokerTest implements MarshallerLoadingConstants 30 { 31 private static final Logger log = Logger.getLogger(MarshallerLoadingServer.class); 32 33 private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 35 36 public MarshallerLoadingServer(String name) 37 { 38 super(name); 39 } 40 41 public MarshallerLoadingServer(String name, int numberOfInstances) 42 { 43 super(name, numberOfInstances); 44 } 45 46 public MarshallerLoadingServer(String name, String transport, int port) 47 { 48 super(name, transport, port); 49 } 50 51 public MarshallerLoadingServer(String name, String transport, int port, int numberOfInstances) 52 { 53 super(name, transport, port, numberOfInstances); 54 } 55 56 57 public void setupServer() throws Exception 58 { 59 try 60 { 61 log.info("2"); 62 InvokerLocator locator = new InvokerLocator(locatorURI); 63 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 64 log.info("Starting remoting server with locator uri of: " + locatorURI); 65 Connector connector = new Connector(); 66 log.info("3"); 67 connector.setInvokerLocator(locator.getLocatorURI()); 68 connector.start(); 69 70 SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); 71 connector.addInvocationHandler("sample", invocationHandler); 73 } 74 catch(Exception e) 75 { 76 e.printStackTrace(); 77 log.error("Error starting server.", e); 78 throw e; 79 } 80 } 81 82 public void serverTest() throws Exception 83 { 84 log.info("1"); 85 setupServer(); 86 startup(getNumberOfInstances()); 87 88 Thread.sleep(5000); 89 90 shutdown(); 91 } 92 93 public void setLogging() 94 { 95 org.apache.log4j.BasicConfigurator.configure(); 96 org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG); 97 org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG); 98 org.apache.log4j.Category.getInstance("org.jboss.remoting.marshall.dynamic.local").setLevel(Level.DEBUG); 99 org.apache.log4j.Category.getInstance("org.jboss.dtf").setLevel(Level.DEBUG); 100 org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.FATAL); 101 102 org.apache.log4j.SimpleLayout layout = new org.apache.log4j.SimpleLayout(); 103 try 104 { 105 org.apache.log4j.FileAppender fileAppender = new org.apache.log4j.FileAppender(layout, getClass().getName() + "_output.log"); 106 fileAppender.setThreshold(Level.DEBUG); 107 org.apache.log4j.Category.getRoot().addAppender(fileAppender); 108 } 109 catch(IOException e) 110 { 111 e.printStackTrace(); 112 } 113 114 118 Enumeration appenders = org.apache.log4j.Category.getRoot().getAllAppenders(); 120 while(appenders.hasMoreElements()) 121 { 122 org.apache.log4j.Appender appender = (org.apache.log4j.Appender) appenders.nextElement(); 123 if(appender instanceof org.apache.log4j.ConsoleAppender) 125 { 126 ((org.apache.log4j.ConsoleAppender) appender).setThreshold(Level.INFO); 127 } 128 } 129 } 130 131 137 public static void main(String [] args) 138 { 139 146 MarshallerLoadingServer server = new MarshallerLoadingServer(MarshallerLoadingServer.class.getName()); 147 148 server.setLogging(); 150 151 try 152 { 153 server.serverTest(); 154 } 155 catch(Exception e) 156 { 157 e.printStackTrace(); 158 System.exit(1); 159 } 160 System.exit(0); 161 } 162 163 166 public static class SampleInvocationHandler implements ServerInvocationHandler 167 { 168 175 public Object invoke(InvocationRequest invocation) throws Throwable 176 { 177 System.out.println("Invocation request is: " + invocation.getParameter()); 179 180 return RESPONSE_VALUE; 182 } 183 184 190 public void addListener(InvokerCallbackHandler callbackHandler) 191 { 192 } 194 195 201 public void removeListener(InvokerCallbackHandler callbackHandler) 202 { 203 } 205 206 211 public void setMBeanServer(MBeanServer server) 212 { 213 } 215 216 221 public void setInvoker(ServerInvoker invoker) 222 { 223 } 225 226 } 227 } | Popular Tags |