1
/***************************************
3
* JBoss: The OpenSource J2EE WebOS *
5
* Distributable under LGPL license. *
6
* See terms of license at gnu.org. *
8
***************************************/
9
package org.jboss.test.remoting.performance.spring.rmi;
11
import EDU.oswego.cs.dl.util.concurrent.Latch;
12
import junit.framework.Test;
13
import org.jboss.jrunit.decorators.ThreadLocalDecorator;
14
import org.jboss.logging.Logger;
15
import org.jboss.remoting.InvokerLocator;
16
import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
17
import org.jboss.test.remoting.performance.synchronous.PerformanceClientTest;
18
import org.springframework.beans.factory.BeanFactory;
19
import org.springframework.beans.factory.xml.XmlBeanFactory;
20
import org.springframework.context.ApplicationContext;
21
import org.springframework.context.support.FileSystemXmlApplicationContext;
22
import org.springframework.core.io.ClassPathResource;
23
import org.springframework.core.io.Resource;
24
import org.springframework.remoting.rmi.RmiServiceExporter;
26
import java.rmi.server.UID;
30
* @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
32
public class SpringRMIPerformanceClient extends PerformanceClientTest
35
private SpringRMIServer springRMIServerService;
36
private String clientSessionId = new UID().toString();
38
protected static final Logger log = Logger.getLogger(SpringRMIPerformanceClient.class);
40
public static Test suite()
42
return new ThreadLocalDecorator(SpringRMIPerformanceClient.class, 1);
45
public SpringRMIServer getSpringRMIServerService()
47
return springRMIServerService;
50
public void setSpringRMIServerService(SpringRMIServer springRMIServerService)
52
this.springRMIServerService = springRMIServerService;
58
Resource res = new ClassPathResource("SpringRMIClientService.xml", SpringRMIPerformanceClient.class);
59
BeanFactory factory = new XmlBeanFactory(res);
60
springRMIServerService = (SpringRMIServer)factory.getBean("springRMIServerService");
65
String name = "//localhost/RMIServer";
66
// RMIServer svr = (RMIServer) Naming.lookup(name);
70
//Registry regsitry = LocateRegistry.getRegistry("localhost", rmiPort);
71
Registry regsitry = LocateRegistry.getRegistry(rmiPort);
72
Remote remoteObj = regsitry.lookup(name);
73
rmiServer = (RMIServerRemote) remoteObj;
77
log.error("Error initializating rmi client.", e);
83
* This will be used to create callback server
89
protected InvokerLocator initServer(int port) throws Exception
94
protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
97
String springServiceXml = this.getClass().getResource("SpringRMIClientService.xml").getFile();
99
ApplicationContext context = null;
100
for (int i = 0; i < 10; i++)
104
context = new FileSystemXmlApplicationContext(springServiceXml);
114
SpringRMICallbackServer callbackServer = (SpringRMICallbackServer) context.getBean("springRMICallbackServerService");
115
callbackServer.setClientSessionId(clientSessionId);
116
callbackServer.setServerDoneLock(serverDoneLock);
119
Instead of exporting callback servers by injection, the following xml declaration is
120
carried out programmatically. Each callback server is registered under a name
121
ending in the sessionId.
123
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
124
<property name="serviceName" value="SpringRMICallbackServerService"/>
125
<property name="service" ref="springRMICallbackServerService"/>
126
<!--<property name="servicePort" value="1300"/>-->
127
<property name="serviceInterface" value="org.jboss.test.remoting.performance.spring.rmi.SpringRMICallbackServer"/>
128
<property name="registryPort" value="1299"/>
131
for (int i = 0; i < 10; i++)
135
RmiServiceExporter exporter = new RmiServiceExporter();
136
exporter.setServiceName("SpringRMICallbackServerService:" + clientSessionId);
137
exporter.setService(callbackServer);
138
exporter.setServiceInterface(org.jboss.test.remoting.performance.spring.rmi.SpringRMICallbackServer.class);
139
exporter.setRegistryPort(1299);
140
exporter.afterPropertiesSet();
141
log.info("exported SpringRMICallbackServerService:" + clientSessionId);
150
return callbackServer;
152
// RMICallbackServer callbackServer = new RMICallbackServer(clientSessionId, serverDoneLock);
153
// callbackServer.start();
154
// return callbackServer;
157
protected void populateMetadata(Map metadata)
159
super.populateMetadata(metadata);
160
metadata.put("transport", "spring_rmi");
161
metadata.put("serialization", "java");
164
protected Object getBenchmarkAlias()
166
String config = System.getProperty("alias");
167
if(config == null || config.length() == 0)
169
config = System.getProperty("jboss-junit-configuration");
170
if(config == null || config.length() == 0)
172
config = "spring_rmi" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
179
protected Object makeInvocation(String method, Object param) throws Throwable
181
if(method.equals(NUM_OF_CALLS))
183
return springRMIServerService.sendNumberOfCalls(clientSessionId, param);
185
else if(method.equals(TEST_INVOCATION))
187
return springRMIServerService.makeCall(clientSessionId, param);
191
throw new Exception("Was not able to find remote method call for " + method);
195
public static void main(String[] args)
197
SpringRMIPerformanceClient test = new SpringRMIPerformanceClient();
201
test.testClientCalls();
204
catch(Throwable throwable)
206
throwable.printStackTrace();
b'\\ No newline at end of file'