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.
23
package org.jboss.test.remoting.performance.synchronous;
25
import org.jboss.remoting.callback.Callback;
26
import org.jboss.remoting.callback.HandleCallbackException;
27
import org.jboss.remoting.callback.InvokerCallbackHandler;
29
import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
32
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
34
public class CallTracker
36
private String clientSessionId;
37
private int totalCount = 0;
38
private SynchronizedInt duplicateCount = new SynchronizedInt(0);
39
private SynchronizedInt receivedCount = new SynchronizedInt(0);
41
private boolean[] counterArray = null;
43
private InvokerCallbackHandler callbackHandler;
45
public CallTracker(String sessionId, InvokerCallbackHandler callbackHandler)
47
this.clientSessionId = sessionId;
48
this.callbackHandler = callbackHandler;
51
public synchronized void createTotalCount(int totalCount)
53
counterArray = new boolean[totalCount + 1];
54
this.totalCount = totalCount;
56
duplicateCount.set(0);
59
public void verifyClientInvokeCount(int clientInvokeCallCount)
61
boolean duplicate = addToReceivedCount(clientInvokeCallCount);
64
duplicateCount.increment();
68
receivedCount.increment();
71
int currentDuplicateCount = duplicateCount.get();
72
int currentReceivedCount = receivedCount.get();
73
if((currentReceivedCount % 100) == 0)
75
System.out.println(clientSessionId + " -- Received count: " + currentReceivedCount);
76
System.out.println(clientSessionId + " -- Duplicate count: " + currentDuplicateCount);
77
System.out.println(clientSessionId + " -- Total count: " + totalCount);
79
if((currentReceivedCount + currentDuplicateCount) == totalCount)
81
System.out.println("\n\n*****************************\n" +
83
"*****************************\n" +
84
" " + clientSessionId + " -- Received Count = " + currentReceivedCount + "\n" +
85
" " + clientSessionId + " -- Duplicate Count = " + currentDuplicateCount + "\n" +
86
"*****************************\n\n");
88
// now call back on client to indicate finished server processing
89
if(callbackHandler != null)
91
Callback callback = new Callback(new Integer[]{new Integer(currentReceivedCount),
92
new Integer(currentDuplicateCount)});
95
callbackHandler.handleCallback(callback);
97
catch(HandleCallbackException e)
106
private synchronized boolean addToReceivedCount(int localClientInvokeCount)
108
boolean isDuplicate = false;
109
if(counterArray == null)
111
System.out.println("Error! Have not received invoke for method 'totalCallCount', so can not process count.");
112
throw new RuntimeException("Error! Have not received invoke for method 'totalCallCount', so can not process count.");
118
isDuplicate = counterArray[localClientInvokeCount];
121
counterArray[localClientInvokeCount] = true;
124
catch(ArrayIndexOutOfBoundsException e)
126
System.err.println("Got ArrayIndexOutOfBoundsException");
127
System.err.println("Counter array size = " + counterArray.length);
128
System.err.println("Received count = " + localClientInvokeCount);
b'\\ No newline at end of file'