KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > callback > pull > memory > nullstore > CallbackTestServer


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.remoting.callback.pull.memory.nullstore;
8
9 import org.jboss.remoting.AbstractInvokerTest;
10 import org.jboss.remoting.InvokerLocator;
11 import org.jboss.remoting.callback.pull.memory.CallbackInvocationHandler;
12 import org.jboss.remoting.transport.Connector;
13
14 /**
15  * Simple remoting server. Uses inner class SampleInvocationHandler
16  * as the invocation target handler class.
17  *
18  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
19  */

20 public class CallbackTestServer extends AbstractInvokerTest
21 {
22    // Default locator values
23
private static String JavaDoc transport = "socket";
24    private static String JavaDoc host = "localhost";
25    private static int port = 5411;
26
27    private String JavaDoc locatorURI = null;
28
29    // String to be returned from invocation handler upon client invocation calls.
30
private static final String JavaDoc RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
31
32    public CallbackTestServer(String JavaDoc name)
33    {
34       super(name);
35    }
36
37    public CallbackTestServer(String JavaDoc name, String JavaDoc locatorURI)
38    {
39       super(name);
40       this.locatorURI = locatorURI;
41    }
42
43    public CallbackTestServer(String JavaDoc name, int numberOfInstances)
44    {
45       super(name, numberOfInstances);
46    }
47
48    public CallbackTestServer(String JavaDoc name, String JavaDoc transport, int port)
49    {
50       super(name, transport, port);
51    }
52
53    public CallbackTestServer(String JavaDoc name, String JavaDoc transport, int port, int numberOfInstances)
54    {
55       super(name, transport, port, numberOfInstances);
56    }
57
58
59    public void setupServer() throws Exception JavaDoc
60    {
61       InvokerLocator locator = new InvokerLocator(locatorURI);
62       System.out.println("Starting remoting server with locator uri of: " + locatorURI);
63       Connector connector = new Connector();
64       connector.setInvokerLocator(locator.getLocatorURI());
65       connector.start();
66
67       CallbackInvocationHandler invocationHandler = new CallbackInvocationHandler();
68       // first parameter is sub-system name. can be any String value.
69
connector.addInvocationHandler("sample", invocationHandler);
70    }
71
72    public void serverTest() throws Exception JavaDoc
73    {
74       try
75       {
76          setupServer();
77          startup(getNumberOfInstances());
78          // sleep the thread for 15 seconds while waiting for client to call
79
Thread.sleep(15000);
80          shutdown();
81       }
82       catch(Exception JavaDoc e)
83       {
84          throw e;
85       }
86    }
87
88    /**
89     * Can pass transport and port to be used as parameters.
90     * Valid transports are 'rmi' and 'socket'.
91     *
92     * @param args
93     */

94    public static void main(String JavaDoc[] args)
95    {
96       if(args != null && args.length == 2)
97       {
98          transport = args[0];
99          port = Integer.parseInt(args[1]);
100       }
101       String JavaDoc locatorURI = transport + "://" + host + ":" + port;
102       CallbackTestServer server = new CallbackTestServer(CallbackTestServer.class.getName(), locatorURI);
103       try
104       {
105          server.serverTest();
106          // sleep the thread for 15 seconds while waiting for client to call
107
Thread.sleep(15000);
108       }
109       catch(Exception JavaDoc e)
110       {
111          e.printStackTrace();
112          System.exit(1);
113       }
114       System.exit(0);
115    }
116
117 }
Popular Tags