KickJava   Java API By Example, From Geeks To Geeks.

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

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

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