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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/performance/synchronous/PerformanceInvocationHandler.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
 
* 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.
6
 
*
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.
11
 
*
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.
16
 
*
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.
21
 
*/
22
 
 
23
 
package org.jboss.test.remoting.performance.synchronous;
24
 
 
25
 
import java.util.ArrayList;
26
 
import java.util.List;
27
 
import java.util.Map;
28
 
import javax.management.MBeanServer;
29
 
import org.jboss.logging.Logger;
30
 
import org.jboss.remoting.InvocationRequest;
31
 
import org.jboss.remoting.ServerInvocationHandler;
32
 
import org.jboss.remoting.ServerInvoker;
33
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
34
 
import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
35
 
import org.jboss.remoting.invocation.RemoteInvocation;
36
 
 
37
 
import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
38
 
import EDU.oswego.cs.dl.util.concurrent.FIFOReadWriteLock;
39
 
import EDU.oswego.cs.dl.util.concurrent.SyncList;
40
 
 
41
 
/**
42
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
43
 
 */
44
 
public class PerformanceInvocationHandler implements ServerInvocationHandler
45
 
{
46
 
   private ServerInvoker invoker;
47
 
 
48
 
   private List listeners = new SyncList(new ArrayList(), new FIFOReadWriteLock());
49
 
   private Map callTrackers = new ConcurrentHashMap();
50
 
 
51
 
   private static final Logger log = Logger.getLogger(PerformanceInvocationHandler.class);
52
 
 
53
 
 
54
 
   /**
55
 
    * set the mbean server that the handler can reference
56
 
    *
57
 
    * @param server
58
 
    */
59
 
   public void setMBeanServer(MBeanServer server)
60
 
   {
61
 
   }
62
 
 
63
 
   /**
64
 
    * set the invoker that owns this handler
65
 
    *
66
 
    * @param invoker
67
 
    */
68
 
   public void setInvoker(ServerInvoker invoker)
69
 
   {
70
 
      this.invoker = invoker;
71
 
   }
72
 
 
73
 
   /**
74
 
    * called to handle a specific invocation.  Please take care to make sure
75
 
    * implementations are thread safe and can, and often will, receive concurrent
76
 
    * calls on this method.
77
 
    *
78
 
    * @param invocation
79
 
    * @return
80
 
    * @throws Throwable
81
 
    */
82
 
   public Object invoke(InvocationRequest invocation) throws Throwable
83
 
   {
84
 
      Object param = invocation.getParameter();
85
 
      String sessionId = invocation.getSessionId();
86
 
      String methodName = "";
87
 
      Object[] params = null;
88
 
      String[] sig = null;
89
 
 
90
 
      if(param instanceof RemoteInvocation)
91
 
      {
92
 
         RemoteInvocation rminvo = (RemoteInvocation) param;
93
 
         methodName = rminvo.getMethodName();
94
 
         params = rminvo.getParameters();
95
 
      }
96
 
      else
97
 
      {
98
 
         throw new Exception("Unknown invocation payload (" + param + ").  " +
99
 
                             "Should be instance of RemoteInvocation.");
100
 
      }
101
 
 
102
 
      Object ret = null;
103
 
      if(methodName.equals(PerformanceClientTest.NUM_OF_CALLS))
104
 
      {
105
 
         Integer totalCountInteger = (Integer) params[0];
106
 
         int totalCount = totalCountInteger.intValue();
107
 
         System.out.println("received totalCallCount call with total count of " + totalCount + " from " + sessionId);
108
 
         CallTracker tracker = (CallTracker) callTrackers.get(sessionId);
109
 
         if(tracker != null)
110
 
         {
111
 
            tracker.createTotalCount(totalCount);
112
 
            ret = totalCountInteger;
113
 
         }
114
 
         else
115
 
         {
116
 
            log.error("Calling " + methodName + " but no call tracker exists for session id " + sessionId);
117
 
            throw new Exception("Calling " + methodName + " but no call tracker exists for session id " + sessionId);
118
 
         }
119
 
      }
120
 
      else if(methodName.equals(PerformanceClientTest.TEST_INVOCATION))
121
 
      {
122
 
         if(params != null)
123
 
         {
124
 
            Payload payload = (Payload) params[0];
125
 
            //System.out.println(payload);
126
 
            int clientInvokeCallCount = payload.getCallNumber();
127
 
 
128
 
            CallTracker tracker = (CallTracker) callTrackers.get(sessionId);
129
 
            if(tracker != null)
130
 
            {
131
 
               tracker.verifyClientInvokeCount(clientInvokeCallCount);
132
 
            }
133
 
            else
134
 
            {
135
 
               log.error("Calling " + methodName + " but no call tracker exists for session id " + sessionId);
136
 
               throw new Exception("Calling " + methodName + " but no call tracker exists for session id " + sessionId);
137
 
            }
138
 
            // just passing return, even though not needed
139
 
            ret = new Integer(clientInvokeCallCount);
140
 
         }
141
 
         else
142
 
         {
143
 
            log.error("no parameter passed for method call " + methodName);
144
 
         }
145
 
 
146
 
      }
147
 
      else
148
 
      {
149
 
         throw new Exception("Don't know what to do with call to " + methodName);
150
 
      }
151
 
 
152
 
      return ret;
153
 
 
154
 
   }
155
 
 
156
 
   private void createCallTracker(String sessionId, InvokerCallbackHandler callbackHandler)
157
 
   {
158
 
      CallTracker tracker = new CallTracker(sessionId, callbackHandler);
159
 
      callTrackers.put(sessionId, tracker);
160
 
   }
161
 
 
162
 
   /**
163
 
    * Adds a callback handler that will listen for callbacks from
164
 
    * the server invoker handler.
165
 
    *
166
 
    * @param callbackHandler
167
 
    */
168
 
   public void addListener(InvokerCallbackHandler callbackHandler)
169
 
   {
170
 
      ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler;
171
 
      String sessionId = handler.getClientSessionId();
172
 
      System.out.println("Adding callback listener.  Callback handler has session id: " + sessionId);
173
 
      createCallTracker(sessionId, callbackHandler);
174
 
      listeners.add(callbackHandler);
175
 
   }
176
 
 
177
 
   /**
178
 
    * Removes the callback handler that was listening for callbacks
179
 
    * from the server invoker handler.
180
 
    *
181
 
    * @param callbackHandler
182
 
    */
183
 
   public void removeListener(InvokerCallbackHandler callbackHandler)
184
 
   {
185
 
      //TODO: -TME Need to figure out how this should be handled.
186
 
      // Could look up CallTracker based on session id (as in addListener() method)
187
 
      // and then remove from tracker or kill tracker all together.
188
 
      listeners.remove(callbackHandler);
189
 
   }
190
 
}
 
 
b'\\ No newline at end of file'