~ubuntu-branches/ubuntu/oneiric/libjboss-remoting-java/oneiric

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/performance/spring/rmi/SpringRMIPerformanceClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************
2
 
 *                                     *
3
 
 *  JBoss: The OpenSource J2EE WebOS   *
4
 
 *                                     *
5
 
 *  Distributable under LGPL license.  *
6
 
 *  See terms of license at gnu.org.   *
7
 
 *                                     *
8
 
 ***************************************/
9
 
package org.jboss.test.remoting.performance.spring.rmi;
10
 
 
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;
25
 
 
26
 
import java.rmi.server.UID;
27
 
import java.util.Map;
28
 
 
29
 
/**
30
 
 * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
31
 
 */
32
 
public class SpringRMIPerformanceClient extends PerformanceClientTest
33
 
{
34
 
 
35
 
   private SpringRMIServer springRMIServerService;
36
 
   private String clientSessionId = new UID().toString();
37
 
 
38
 
   protected static final Logger log = Logger.getLogger(SpringRMIPerformanceClient.class);
39
 
 
40
 
   public static Test suite()
41
 
   {
42
 
      return new ThreadLocalDecorator(SpringRMIPerformanceClient.class, 1);
43
 
   }
44
 
 
45
 
   public SpringRMIServer getSpringRMIServerService()
46
 
   {
47
 
      return springRMIServerService;
48
 
   }
49
 
 
50
 
   public void setSpringRMIServerService(SpringRMIServer springRMIServerService)
51
 
   {
52
 
      this.springRMIServerService = springRMIServerService;
53
 
   }
54
 
 
55
 
   public void init()
56
 
   {
57
 
 
58
 
      Resource res = new ClassPathResource("SpringRMIClientService.xml", SpringRMIPerformanceClient.class);
59
 
      BeanFactory factory = new XmlBeanFactory(res);
60
 
      springRMIServerService = (SpringRMIServer)factory.getBean("springRMIServerService");
61
 
 
62
 
      /*
63
 
      //super.init();
64
 
 
65
 
      String name = "//localhost/RMIServer";
66
 
//         RMIServer svr = (RMIServer) Naming.lookup(name);
67
 
 
68
 
      try
69
 
      {
70
 
         //Registry regsitry = LocateRegistry.getRegistry("localhost", rmiPort);
71
 
         Registry regsitry = LocateRegistry.getRegistry(rmiPort);
72
 
         Remote remoteObj = regsitry.lookup(name);
73
 
         rmiServer = (RMIServerRemote) remoteObj;
74
 
      }
75
 
      catch(Exception e)
76
 
      {
77
 
         log.error("Error initializating rmi client.", e);
78
 
      }
79
 
      */
80
 
   }
81
 
 
82
 
   /**
83
 
    * This will be used to create callback server
84
 
    *
85
 
    * @param port
86
 
    * @return
87
 
    * @throws Exception
88
 
    */
89
 
   protected InvokerLocator initServer(int port) throws Exception
90
 
   {
91
 
      return null;
92
 
   }
93
 
 
94
 
   protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
95
 
         throws Throwable
96
 
   {
97
 
      String springServiceXml = this.getClass().getResource("SpringRMIClientService.xml").getFile();
98
 
      
99
 
      ApplicationContext context = null;
100
 
      for (int i = 0; i < 10; i++)
101
 
      {
102
 
         try
103
 
         {
104
 
            context = new FileSystemXmlApplicationContext(springServiceXml);
105
 
            if (context != null)
106
 
               break;
107
 
         }
108
 
         catch (Exception e)
109
 
         {
110
 
            Thread.sleep(2000);
111
 
         }
112
 
      }
113
 
      
114
 
      SpringRMICallbackServer callbackServer = (SpringRMICallbackServer) context.getBean("springRMICallbackServerService");
115
 
      callbackServer.setClientSessionId(clientSessionId);
116
 
      callbackServer.setServerDoneLock(serverDoneLock);
117
 
      
118
 
/*
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.
122
 
    
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"/>
129
 
   </bean> 
130
 
*/
131
 
      for (int i = 0; i < 10; i++)
132
 
      {
133
 
         try
134
 
         {
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);
142
 
            break;
143
 
         }
144
 
         catch (Exception e)
145
 
         {
146
 
            Thread.sleep(2000);
147
 
         }
148
 
      }
149
 
      
150
 
      return callbackServer;
151
 
 
152
 
//      RMICallbackServer callbackServer = new RMICallbackServer(clientSessionId, serverDoneLock);
153
 
//      callbackServer.start();
154
 
//      return callbackServer;
155
 
   }
156
 
 
157
 
   protected void populateMetadata(Map metadata)
158
 
   {
159
 
      super.populateMetadata(metadata);
160
 
      metadata.put("transport", "spring_rmi");
161
 
      metadata.put("serialization", "java");
162
 
   }
163
 
 
164
 
   protected Object getBenchmarkAlias()
165
 
   {
166
 
      String config = System.getProperty("alias");
167
 
      if(config == null || config.length() == 0)
168
 
      {
169
 
         config = System.getProperty("jboss-junit-configuration");
170
 
         if(config == null || config.length() == 0)
171
 
         {
172
 
            config = "spring_rmi" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
173
 
         }
174
 
      }
175
 
      return config;
176
 
   }
177
 
 
178
 
 
179
 
   protected Object makeInvocation(String method, Object param) throws Throwable
180
 
   {
181
 
      if(method.equals(NUM_OF_CALLS))
182
 
      {
183
 
         return springRMIServerService.sendNumberOfCalls(clientSessionId, param);
184
 
      }
185
 
      else if(method.equals(TEST_INVOCATION))
186
 
      {
187
 
         return springRMIServerService.makeCall(clientSessionId, param);
188
 
      }
189
 
      else
190
 
      {
191
 
         throw new Exception("Was not able to find remote method call for " + method);
192
 
      }
193
 
   }
194
 
 
195
 
   public static void main(String[] args)
196
 
   {
197
 
      SpringRMIPerformanceClient test = new SpringRMIPerformanceClient();
198
 
      try
199
 
      {
200
 
         test.setUp();
201
 
         test.testClientCalls();
202
 
         test.tearDown();
203
 
      }
204
 
      catch(Throwable throwable)
205
 
      {
206
 
         throwable.printStackTrace();
207
 
      }
208
 
   }
209
 
 
210
 
}
 
 
b'\\ No newline at end of file'