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.bisocket;
24
import java.net.InetAddress;
25
import java.util.HashMap;
27
import javax.management.MBeanServer;
29
import junit.framework.TestCase;
31
import org.jboss.logging.Logger;
32
import org.jboss.remoting.Client;
33
import org.jboss.remoting.InvocationRequest;
34
import org.jboss.remoting.InvokerLocator;
35
import org.jboss.remoting.ServerInvocationHandler;
36
import org.jboss.remoting.ServerInvoker;
37
import org.jboss.remoting.callback.Callback;
38
import org.jboss.remoting.callback.HandleCallbackException;
39
import org.jboss.remoting.callback.InvokerCallbackHandler;
42
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
43
* @version $Revision: 1702 $
45
* Copyright Nov 25, 2006
48
public class BisocketPerformanceTestClient extends TestCase
50
private static Logger log = Logger.getLogger(BisocketPerformanceTestClient.class);
51
private static String transport = "bisocket";
52
private static int invocations = 1000;
55
public void testBisocket() throws Throwable
57
String host = InetAddress.getLocalHost().getHostAddress();
58
int port = BisocketPerformanceTestServer.port;
59
String locatorURI = transport + "://" + host + ":" + port;
60
InvokerLocator serverLocator = new InvokerLocator(locatorURI);
61
System.out.println("Connecting to: " + serverLocator);
62
Client client = new Client(serverLocator);
64
System.out.println("client is connected");
65
InvokerCallbackHandler callbackHandler = new SampleCallbackHandler();
66
client.addListener(callbackHandler, new HashMap(), null, true);
67
System.out.println("client added callback handler");
69
long start = System.currentTimeMillis();
70
for (int i = 0; i < invocations; i++)
72
client.invoke("test");
74
long finish = System.currentTimeMillis();
75
System.out.println("time to make " + invocations + " invocations: " + (finish - start));
76
client.removeListener(callbackHandler);
82
* Can pass transport and port to be used as parameters.
86
public static void main(String[] args)
88
if(args != null && args.length > 0)
92
invocations = Integer.parseInt(args[1]);
94
BisocketPerformanceTestClient testCase = new BisocketPerformanceTestClient();
98
testCase.testBisocket();
101
System.out.println("done");
110
* Simple invocation handler implementation. When callback client's are registered, will
111
* generate callbacks periodically.
113
static class SampleInvocationHandler implements ServerInvocationHandler
115
public void addListener(InvokerCallbackHandler callbackHandler)
117
System.out.println("Adding callback listener.");
120
callbackHandler.handleCallback(new Callback("callback"));
122
catch (HandleCallbackException e)
124
log.error("Unable to send callback");
128
public Object invoke(InvocationRequest invocation) throws Throwable {return null;}
129
public void removeListener(InvokerCallbackHandler callbackHandler) {}
130
public void setMBeanServer(MBeanServer server) {}
131
public void setInvoker(ServerInvoker invoker) {}
135
static class SampleCallbackHandler implements InvokerCallbackHandler
139
public void handleCallback(Callback callback) throws HandleCallbackException
142
if ((counter + 1) % 1000 == 0)
144
System.out.println("received callback " + (counter + 1));