KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > marshall > dynamic > remote > http > 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.http;
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    public static void main(String JavaDoc[] args)
60    {
61       MarshallerLoadingServer server = new MarshallerLoadingServer();
62       try
63       {
64          server.setUp();
65       }
66       catch(Exception JavaDoc e)
67       {
68          e.printStackTrace();
69       }
70    }
71
72
73    /**
74     * Simple invocation handler implementation.
75     */

76    public static class SampleInvocationHandler implements ServerInvocationHandler
77    {
78       /**
79        * called to handle a specific invocation
80        *
81        * @param invocation
82        * @return
83        * @throws Throwable
84        */

85       public Object JavaDoc invoke(InvocationRequest invocation) throws Throwable JavaDoc
86       {
87          // Print out the invocation request
88
System.out.println("Invocation request is: " + invocation.getParameter());
89
90          // Just going to return static string as this is just simple example code.
91
return RESPONSE_VALUE;
92       }
93
94       /**
95        * Adds a callback handler that will listen for callbacks from
96        * the server invoker handler.
97        *
98        * @param callbackHandler
99        */

100       public void addListener(InvokerCallbackHandler callbackHandler)
101       {
102          // NO OP as do not handling callback listeners in this example
103
}
104
105       /**
106        * Removes the callback handler that was listening for callbacks
107        * from the server invoker handler.
108        *
109        * @param callbackHandler
110        */

111       public void removeListener(InvokerCallbackHandler callbackHandler)
112       {
113          // NO OP as do not handling callback listeners in this example
114
}
115
116       /**
117        * set the mbean server that the handler can reference
118        *
119        * @param server
120        */

121       public void setMBeanServer(MBeanServer JavaDoc server)
122       {
123          // NO OP as do not need reference to MBeanServer for this handler
124
}
125
126       /**
127        * set the invoker that owns this handler
128        *
129        * @param invoker
130        */

131       public void setInvoker(ServerInvoker invoker)
132       {
133          // NO OP as do not need reference back to the server invoker
134
}
135
136    }
137 }
Popular Tags