1 7 package org.jboss.test.remoting.performance.synchronous; 8 9 import java.util.Iterator ; 10 import java.util.Map ; 11 import java.util.Set ; 12 import org.jboss.jrunit.extensions.ServerTestCase; 13 import org.jboss.logging.Logger; 14 import org.jboss.remoting.InvokerLocator; 15 import org.jboss.remoting.ServerInvocationHandler; 16 import org.jboss.remoting.transport.Connector; 17 18 21 public class PerformanceServerTest extends ServerTestCase 22 { 23 private String transport = "socket"; 25 private int serverPort = 9090; 26 27 private Connector connector = null; 28 29 private static final Logger log = Logger.getLogger(PerformanceServerTest.class); 30 31 public void init(Map metatdata) throws Exception 32 { 33 if(serverPort < 0) 34 { 35 throw new Exception ("port setting for server can not be null."); 37 } 38 log.debug("port = " + serverPort); 39 40 connector = new Connector(); 41 InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata)); 42 connector.setInvokerLocator(locator.getLocatorURI()); 43 connector.create(); 44 connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler()); 45 connector.start(); 46 log.info("Server started on " + locator.getLocatorURI()); 47 } 48 49 private String buildLocatorURI(Map metadata) 50 { 51 if(metadata == null || metadata.size() == 0) 52 { 53 return transport + "://localhost:" + serverPort; 54 } 55 else 56 { 57 StringBuffer uriBuffer = new StringBuffer (transport + "://localhost:" + serverPort); 58 59 Set keys = metadata.keySet(); 60 Iterator itr = keys.iterator(); 61 while(itr.hasNext()) 62 { 63 String key = (String ) itr.next(); 64 String value = (String ) metadata.get(key); 65 uriBuffer.append(key + "=" + value + ","); 66 } 67 return uriBuffer.substring(0, uriBuffer.length() - 1); 68 } 69 } 70 71 protected String getSubsystem() 72 { 73 return "performance"; 74 } 75 76 protected ServerInvocationHandler getServerInvocationHandler() 77 { 78 return new PerformanceInvocationHandler(); 79 } 80 81 protected void setUp() throws Exception 82 { 83 String newTransport = System.getProperty(PerformanceTestCase.REMOTING_TRANSPORT); 84 if(newTransport != null && newTransport.length() > 0) 85 { 86 transport = newTransport; 87 log.info("Using transport: " + transport); 88 } 89 90 init(null); 91 } 92 93 protected void tearDown() throws Exception 94 { 95 if(connector != null) 96 { 97 connector.stop(); 98 connector.destroy(); 99 } 100 } 101 102 public static void main(String [] args) 103 { 104 PerformanceServerTest test = new PerformanceServerTest(); 105 try 106 { 107 test.setUp(); 108 Thread.currentThread().sleep(300000); 109 test.tearDown(); 110 } 111 catch(Exception e) 112 { 113 e.printStackTrace(); 114 } 115 } 116 } | Popular Tags |