2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.remoting.samples.simple;
25
import javax.management.MBeanServer;
26
import org.jboss.remoting.InvocationRequest;
27
import org.jboss.remoting.InvokerLocator;
28
import org.jboss.remoting.ServerInvocationHandler;
29
import org.jboss.remoting.ServerInvoker;
30
import org.jboss.remoting.callback.InvokerCallbackHandler;
31
import org.jboss.remoting.transport.Connector;
34
* Simple remoting server. Uses inner class SampleInvocationHandler
35
* as the invocation target handler class.
37
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
39
public class SimpleServer
41
// Default locator values
42
private static String transport = "socket";
43
private static String host = "localhost";
44
private static int port = 5400;
46
// String to be returned from invocation handler upon client invocation calls.
47
private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
50
public void setupServer(String locatorURI) throws Exception
52
// create the InvokerLocator based on url string format
53
// to indicate the transport, host, and port to use for the
55
InvokerLocator locator = new InvokerLocator(locatorURI);
56
System.out.println("Starting remoting server with locator uri of: " + locatorURI);
57
Connector connector = new Connector(locator);
58
// creates all the connector's needed resources, such as the server invoker
61
// create the handler to receive the invocation request from the client for processing
62
SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
63
// first parameter is sub-system name. can be any String value.
64
connector.addInvocationHandler("sample", invocationHandler);
66
// start with a new non daemon thread so
67
// server will wait for request and not exit
73
* Can pass transport and port to be used as parameters.
74
* Valid transports are 'rmi' and 'socket'.
78
public static void main(String[] args)
80
if(args != null && args.length == 3)
84
port = Integer.parseInt(args[2]);
86
String locatorURI = transport + "://" + host + ":" + port;
87
SimpleServer server = new SimpleServer();
90
server.setupServer(locatorURI);
92
// wait forever, let the user kill us at any point (at which point, the client will detect we went down)
106
* Simple invocation handler implementation.
107
* This is the code that will be called with the invocation payload from the client.
109
public static class SampleInvocationHandler implements ServerInvocationHandler
112
* called to handle a specific invocation
118
public Object invoke(InvocationRequest invocation) throws Throwable
120
// Print out the invocation request
121
System.out.println("Invocation request is: " + invocation.getParameter());
122
System.out.println("Returning response of: " + RESPONSE_VALUE);
123
// Just going to return static string as this is just simple example code.
124
return RESPONSE_VALUE;
128
* Adds a callback handler that will listen for callbacks from
129
* the server invoker handler.
131
* @param callbackHandler
133
public void addListener(InvokerCallbackHandler callbackHandler)
135
// NO OP as do not handling callback listeners in this example
139
* Removes the callback handler that was listening for callbacks
140
* from the server invoker handler.
142
* @param callbackHandler
144
public void removeListener(InvokerCallbackHandler callbackHandler)
146
// NO OP as do not handling callback listeners in this example
150
* set the mbean server that the handler can reference
154
public void setMBeanServer(MBeanServer server)
156
// NO OP as do not need reference to MBeanServer for this handler
160
* set the invoker that owns this handler
164
public void setInvoker(ServerInvoker invoker)
166
// NO OP as do not need reference back to the server invoker
b'\\ No newline at end of file'