KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > 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.test.remoting.callback.pull.memory.callbackstore;
8
9 import org.jboss.jrunit.extensions.ServerTestCase;
10 import org.jboss.remoting.InvokerLocator;
11 import org.jboss.remoting.callback.CallbackStore;
12 import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
13 import org.jboss.remoting.transport.Connector;
14 import org.jboss.test.remoting.callback.pull.memory.CallbackInvocationHandler;
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 ServerTestCase
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 = transport + "://" + host + ":" + port + "/?" + ServerInvokerCallbackHandler.CALLBACK_STORE_KEY +
30                                "=" + CallbackStore.class.getName();
31
32    private Connector connector;
33
34    // String to be returned from invocation handler upon client invocation calls.
35
private static final String JavaDoc RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
36
37
38    public void setupServer() throws Exception JavaDoc
39    {
40       InvokerLocator locator = new InvokerLocator(locatorURI);
41       System.out.println("Starting remoting server with locator uri of: " + locatorURI);
42       connector = new Connector();
43       connector.setInvokerLocator(locator.getLocatorURI());
44       connector.start();
45
46       CallbackInvocationHandler invocationHandler = new CallbackInvocationHandler();
47       // first parameter is sub-system name. can be any String value.
48
connector.addInvocationHandler("sample", invocationHandler);
49    }
50
51    public void setUp() throws Exception JavaDoc
52    {
53       setupServer();
54    }
55
56    public void tearDown() throws Exception JavaDoc
57    {
58       if(connector != null)
59       {
60          connector.stop();
61          connector.destroy();
62       }
63    }
64
65    public static void main(String JavaDoc[] args)
66    {
67       CallbackTestServer server = new CallbackTestServer();
68       try
69       {
70          server.setUp();
71          Thread.currentThread().sleep(600000);
72          server.tearDown();
73       }
74       catch(Exception JavaDoc e)
75       {
76          e.printStackTrace();
77       }
78    }
79
80 }
Popular Tags