KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > oneway > OnewayInvokerServer


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.oneway;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Set JavaDoc;
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 /**
20  * @author <a HREF="mailto:telrod@vocalocity.net">Tom Elrod</a>
21  * @version $Revision: 1.3 $
22  */

23 public class OnewayInvokerServer extends ServerTestCase //implements ShutdownListener
24
{
25    private int serverPort = 8081;
26    private Connector connector = null;
27    private String JavaDoc transport = "socket";
28
29    private static final Logger log = Logger.getLogger(OnewayInvokerServer.class);
30
31    public void init(Map JavaDoc metatdata) throws Exception JavaDoc
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 JavaDoc buildLocatorURI(Map JavaDoc metadata)
48    {
49       if(metadata == null || metadata.size() == 0)
50       {
51          return transport + "://localhost:" + serverPort;
52       }
53       else
54       {
55          StringBuffer JavaDoc uriBuffer = new StringBuffer JavaDoc(transport + "://localhost:" + serverPort);
56
57          Set JavaDoc keys = metadata.keySet();
58          Iterator JavaDoc itr = keys.iterator();
59          while(itr.hasNext())
60          {
61             String JavaDoc key = (String JavaDoc) itr.next();
62             String JavaDoc value = (String JavaDoc) 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 JavaDoc getSubsystem()
75    {
76       return "test";
77    }
78
79    public void setUp() throws Exception JavaDoc
80    {
81       init(null);
82    }
83
84    public void tearDown() throws Exception JavaDoc
85    {
86       if(connector != null)
87       {
88          connector.stop();
89          connector.destroy();
90       }
91    }
92
93
94 }
95
Popular Tags