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.
22
package org.jboss.test.remoting.transport.socket.socketpool;
24
import org.jboss.jrunit.extensions.ServerTestCase;
25
import org.jboss.logging.Logger;
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;
33
import javax.management.MBeanServer;
36
* See SocketPoolTestCase for description.
38
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
39
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
41
* @version $Revision: 2911 $
43
* Copyright Nov 2, 2006
46
public class SocketPoolTestServer extends ServerTestCase
48
public final static int NUMBER_OF_CALLS = 5;
49
private static Logger log = Logger.getLogger(SocketPoolTestServer.class);
50
private static Object lock = new Object();
51
private static Object stopLock = new Object();
52
private static int callCounter;
53
private static boolean done;
55
// Default locator values
56
private static String transport = "socket";
57
private static String host = "localhost";
58
private static int port = 6413;
60
private Connector connector = null;
62
public void setupServer(String locatorURI) throws Exception
64
log.warn("EXCEPTIONS ARE EXPECTED");
65
log.info("Starting remoting server with locator uri of: " + locatorURI);
67
InvokerLocator locator = new InvokerLocator(locatorURI);
68
connector = new Connector(locator);
70
SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
71
connector.addInvocationHandler("sample", invocationHandler);
74
// This thread will stop the Connector when NUMBER_OF_CALLS
75
// invocations have been received.
88
catch (InterruptedException e)
99
log.info("Connector stopped");
101
synchronized(stopLock)
111
public void tearDown()
115
public void setUp() throws Exception
117
String locatorURI = getTransport() + "://" + host + ":" + getPort();
118
setupServer(locatorURI);
122
* Can pass transport and port to be used as parameters.
123
* Valid transports are 'rmi' and 'socket'.
127
public static void main(String[] args)
129
if(args != null && args.length == 2)
132
port = Integer.parseInt(args[1]);
134
SocketPoolTestServer server = new SocketPoolTestServer();
139
synchronized (stopLock)
148
catch (InterruptedException ignored) {}
158
protected String getTransport()
163
protected int getPort()
169
* Simple invocation handler implementation.
170
* This is the code that will be called with the invocation payload from the client.
172
public static class SampleInvocationHandler implements ServerInvocationHandler
174
public Object invoke(InvocationRequest invocation) throws Throwable
179
log.info("callCounter: " + callCounter);
182
// Waiting for 4 seconds will cause the client to timeout.
187
if (callCounter == NUMBER_OF_CALLS)
196
public void addListener(InvokerCallbackHandler callbackHandler)
199
public void removeListener(InvokerCallbackHandler callbackHandler)
202
public void setMBeanServer(MBeanServer server)
205
public void setInvoker(ServerInvoker invoker)
b'\\ No newline at end of file'