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.soak;
24
import java.net.InetAddress;
25
import java.util.HashMap;
26
import java.util.HashSet;
27
import java.util.Iterator;
31
import javax.management.MBeanServer;
33
import org.apache.log4j.ConsoleAppender;
34
import org.apache.log4j.Level;
35
import org.apache.log4j.Logger;
36
import org.apache.log4j.PatternLayout;
37
import org.jboss.logging.XLevel;
38
import org.jboss.remoting.InvocationRequest;
39
import org.jboss.remoting.InvokerLocator;
40
import org.jboss.remoting.ServerInvocationHandler;
41
import org.jboss.remoting.ServerInvoker;
42
import org.jboss.remoting.callback.Callback;
43
import org.jboss.remoting.callback.InvokerCallbackHandler;
44
import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
45
import org.jboss.remoting.transport.Connector;
50
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
51
* @version $Revision: 1.1 $
53
* Copyright Mar 13, 2008
56
public class ServerLauncher extends SoakConstants
58
private static Logger log = Logger.getLogger(ServerLauncher.class);
59
private static Map locators = new HashMap();
60
private static Connector[] connectors = new Connector[4];
62
public static Map getLocators()
67
public static void main(String[] args)
71
Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
72
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
73
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
74
PatternLayout layout = new PatternLayout(pattern);
75
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
76
Logger.getRootLogger().addAppender(consoleAppender);
78
String host = InetAddress.getLocalHost().getHostAddress();
80
connectors[0] = setupServer(host, 6666, "bisocket");
81
locators.put("bisocket", connectors[0].getLocator().getLocatorURI());
83
connectors[1] = setupServer(host, 6667, "http");
84
locators.put("http", connectors[1].getLocator().getLocatorURI());
86
connectors[2] = setupServer(host, 6668, "rmi");
87
locators.put("rmi", connectors[2].getLocator().getLocatorURI());
89
connectors[3] = setupServer(host, 6669, "socket");
90
locators.put("socket", connectors[3].getLocator().getLocatorURI());
92
log.info("SERVERS CREATED: " + locators);
98
log.info("SHUTTING DOWN SERVERS");
99
for (int i = 0; i < connectors.length; i++)
101
connectors[i].stop();
103
log.info("SERVERS SHUT DOWN");
108
log.error("Error", e);
113
protected static Connector setupServer(String host, int port, String transport) throws Exception
115
String locatorURI = transport + "://" + host + ":" + port + "/?timeout=0";
116
InvokerLocator serverLocator = new InvokerLocator(locatorURI);
117
log.info("Starting remoting server with locator uri of: " + locatorURI);
118
HashMap config = new HashMap();
119
config.put(InvokerLocator.FORCE_REMOTE, "true");
120
Connector connector = new Connector(serverLocator, config);
122
TestInvocationHandler invocationHandler = new TestInvocationHandler();
123
connector.addInvocationHandler("test", invocationHandler);
129
static class TestInvocationHandler implements ServerInvocationHandler
131
Map listeners = new HashMap();
132
Object lock = new Object();
134
public void addListener(InvokerCallbackHandler callbackHandler)
136
log.debug("entering addListener()");
139
String id = ((ServerInvokerCallbackHandler)callbackHandler).getClientSessionId();
140
listeners.put(id, callbackHandler);
142
log.debug("added InvokerCallbackHandler: " + listeners);
145
public Object invoke(final InvocationRequest invocation) throws Throwable
147
String command = (String) invocation.getParameter();
148
log.debug("command: " + command);
150
if (COPY.equals(command))
152
Object o = invocation.getRequestPayload().get(PAYLOAD);
155
else if (SPIN.equals(command))
157
String s = (String) invocation.getRequestPayload().get(SPIN_TIME);
158
int spinTime = Integer.parseInt(s);
159
SpinThread t = new SpinThread();
161
Thread.sleep(spinTime);
165
else if (CALLBACK.equals(command))
167
String id = invocation.getSessionId();
168
Map requestPayload = invocation.getRequestPayload();
169
String s = (String) requestPayload.get(NUMBER_OF_CALLBACKS);
170
int callbacks = Integer.parseInt(s);
171
InvokerCallbackHandler callbackHandler = null;
175
callbackHandler = (InvokerCallbackHandler) listeners.get(id);
178
if (callbackHandler == null)
180
log.debug("sessionId: " + id);
181
log.debug("listeners: " + listeners);
183
Callback callback = new Callback("callback");
184
for (int i = 0; i < callbacks; i++)
186
callbackHandler.handleCallback(callback);
193
public void removeListener(InvokerCallbackHandler callbackHandler)
197
String id = ((ServerInvokerCallbackHandler) callbackHandler).getClientSessionId();
198
listeners.remove(id);
202
public void setMBeanServer(MBeanServer server) {}
203
public void setInvoker(ServerInvoker invoker) {}
206
static class SpinThread extends Thread
210
static Object lock = new Object();
216
setName("spinThread:" + counter++);
219
public void setStop()
222
log.debug(this + " stop = " + stop);
231
if ((n + 1) % 10000 == 0)
232
log.debug(this + "stop = " + stop);
234
log.debug("SpinThread done");