1 7 package org.jboss.test.remoting.oneway; 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 import org.jboss.test.remoting.TestUtil; 18 19 23 public class OnewayInvokerServer extends ServerTestCase { 25 private int serverPort = 8081; 26 private Connector connector = null; 27 private String transport = "socket"; 28 29 private static final Logger log = Logger.getLogger(OnewayInvokerServer.class); 30 31 public void init(Map metatdata) throws Exception 32 { 33 if(serverPort < 0) 34 { 35 serverPort = TestUtil.getRandomPort(); 36 } 37 log.debug("port = " + serverPort); 38 39 connector = new Connector(); 40 InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata)); 41 connector.setInvokerLocator(locator.getLocatorURI()); 42 connector.create(); 43 connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler()); 44 connector.start(); 45 } 46 47 private String buildLocatorURI(Map metadata) 48 { 49 if(metadata == null || metadata.size() == 0) 50 { 51 return transport + "://localhost:" + serverPort; 52 } 53 else 54 { 55 StringBuffer uriBuffer = new StringBuffer (transport + "://localhost:" + serverPort); 56 57 Set keys = metadata.keySet(); 58 Iterator itr = keys.iterator(); 59 while(itr.hasNext()) 60 { 61 String key = (String ) itr.next(); 62 String value = (String ) metadata.get(key); 63 uriBuffer.append(key + "=" + value + ","); 64 } 65 return uriBuffer.substring(0, uriBuffer.length() - 1); 66 } 67 } 68 69 protected ServerInvocationHandler getServerInvocationHandler() 70 { 71 return new OnewayServerInvocationHandler(); 72 } 73 74 protected String getSubsystem() 75 { 76 return "test"; 77 } 78 79 public void setUp() throws Exception 80 { 81 init(null); 82 } 83 84 public void tearDown() throws Exception 85 { 86 if(connector != null) 87 { 88 connector.stop(); 89 connector.destroy(); 90 } 91 } 92 93 94 } 95 | Popular Tags |