KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > marshall > dynamic > remote > socket > MarshallerLoadingServer


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.marshall.dynamic.remote.socket;
8
9 import javax.management.MBeanServer JavaDoc;
10 import org.jboss.jrunit.extensions.ServerTestCase;
11 import org.jboss.remoting.InvocationRequest;
12 import org.jboss.remoting.InvokerLocator;
13 import org.jboss.remoting.ServerInvocationHandler;
14 import org.jboss.remoting.ServerInvoker;
15 import org.jboss.remoting.callback.InvokerCallbackHandler;
16 import org.jboss.remoting.transport.Connector;
17
18 /**
19  * Simple remoting server. Uses inner class SampleInvocationHandler
20  * as the invocation target handler class.
21  *
22  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
23  */

24 public class MarshallerLoadingServer extends ServerTestCase implements MarshallerLoadingConstants
25 {
26    private Connector connector;
27
28    // String to be returned from invocation handler upon client invocation calls.
29
private static final String JavaDoc RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
30
31    public void setupServer() throws Exception JavaDoc
32    {
33       System.out.println("locatorURI: " + locatorURI);
34       InvokerLocator locator = new InvokerLocator(locatorURI);
35       System.out.println("Starting remoting server with locator uri of: " + locatorURI);
36       connector = new Connector();
37       connector.setInvokerLocator(locator.getLocatorURI());
38       connector.start();
39
40       SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
41       // first parameter is sub-system name. can be any String value.
42
connector.addInvocationHandler("sample", invocationHandler);
43    }
44
45    public void setUp() throws Exception JavaDoc
46    {
47       setupServer();
48    }
49
50    public void tearDown() throws Exception JavaDoc
51    {
52       if(connector != null)
53       {
54          connector.stop();
55          connector.destroy();
56       }
57    }
58
59
60    /**
61     * Simple invocation handler implementation.
62     */

63    public static class SampleInvocationHandler implements ServerInvocationHandler
64    {
65       /**
66        * called to handle a specific invocation
67        *
68        * @param invocation
69        * @return
70        * @throws Throwable
71        */

72       public Object JavaDoc invoke(InvocationRequest invocation) throws Throwable JavaDoc
73       {
74          // Print out the invocation request
75
System.out.println("Invocation request is: " + invocation.getParameter());
76
77          // Just going to return static string as this is just simple example code.
78
return RESPONSE_VALUE;
79       }
80
81       /**
82        * Adds a callback handler that will listen for callbacks from
83        * the server invoker handler.
84        *
85        * @param callbackHandler
86        */

87       public void addListener(InvokerCallbackHandler callbackHandler)
88       {
89          // NO OP as do not handling callback listeners in this example
90
}
91
92       /**
93        * Removes the callback handler that was listening for callbacks
94        * from the server invoker handler.
95        *
96        * @param callbackHandler
97        */

98       public void removeListener(InvokerCallbackHandler callbackHandler)
99       {
100          // NO OP as do not handling callback listeners in this example
101
}
102
103       /**
104        * set the mbean server that the handler can reference
105        *
106        * @param server
107        */

108       public void setMBeanServer(MBeanServer JavaDoc server)
109       {
110          // NO OP as do not need reference to MBeanServer for this handler
111
}
112
113       /**
114        * set the invoker that owns this handler
115        *
116        * @param invoker
117        */

118       public void setInvoker(ServerInvoker invoker)
119       {
120          // NO OP as do not need reference back to the server invoker
121
}
122
123    }
124 }
Popular Tags