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

« back to all changes in this revision

Viewing changes to .pc/0001-convert-to-official-Java-concurrent-packages.patch/src/tests/org/jboss/test/remoting/performance/synchronous/CallTracker.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 org.jboss.remoting.callback.Callback;
 
26
import org.jboss.remoting.callback.HandleCallbackException;
 
27
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
28
 
 
29
import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
 
30
 
 
31
/**
 
32
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
33
 */
 
34
public class CallTracker
 
35
{
 
36
   private String clientSessionId;
 
37
   private int totalCount = 0;
 
38
   private SynchronizedInt duplicateCount = new SynchronizedInt(0);
 
39
   private SynchronizedInt receivedCount = new SynchronizedInt(0);
 
40
 
 
41
   private boolean[] counterArray = null;
 
42
 
 
43
   private InvokerCallbackHandler callbackHandler;
 
44
 
 
45
   public CallTracker(String sessionId, InvokerCallbackHandler callbackHandler)
 
46
   {
 
47
      this.clientSessionId = sessionId;
 
48
      this.callbackHandler = callbackHandler;
 
49
   }
 
50
 
 
51
   public synchronized void createTotalCount(int totalCount)
 
52
   {
 
53
      counterArray = new boolean[totalCount + 1];
 
54
      this.totalCount = totalCount;
 
55
      receivedCount.set(0);
 
56
      duplicateCount.set(0);
 
57
   }
 
58
 
 
59
   public void verifyClientInvokeCount(int clientInvokeCallCount)
 
60
   {
 
61
      boolean duplicate = addToReceivedCount(clientInvokeCallCount);
 
62
      if(duplicate)
 
63
      {
 
64
         duplicateCount.increment();
 
65
      }
 
66
      else
 
67
      {
 
68
         receivedCount.increment();
 
69
      }
 
70
 
 
71
      int currentDuplicateCount = duplicateCount.get();
 
72
      int currentReceivedCount = receivedCount.get();
 
73
      if((currentReceivedCount % 100) == 0)
 
74
      {
 
75
         System.out.println(clientSessionId + " -- Received count: " + currentReceivedCount);
 
76
         System.out.println(clientSessionId + " -- Duplicate count: " + currentDuplicateCount);
 
77
         System.out.println(clientSessionId + " -- Total count: " + totalCount);
 
78
      }
 
79
      if((currentReceivedCount + currentDuplicateCount) == totalCount)
 
80
      {
 
81
         System.out.println("\n\n*****************************\n" +
 
82
                            "  Test Finished\n" +
 
83
                            "*****************************\n" +
 
84
                            "  " + clientSessionId + " -- Received Count = " + currentReceivedCount + "\n" +
 
85
                            "  " + clientSessionId + " -- Duplicate Count = " + currentDuplicateCount + "\n" +
 
86
                            "*****************************\n\n");
 
87
 
 
88
         // now call back on client to indicate finished server processing
 
89
         if(callbackHandler != null)
 
90
         {
 
91
            Callback callback = new Callback(new Integer[]{new Integer(currentReceivedCount),
 
92
                  new Integer(currentDuplicateCount)});
 
93
            try
 
94
            {
 
95
               callbackHandler.handleCallback(callback);
 
96
            }
 
97
            catch(HandleCallbackException e)
 
98
            {
 
99
               e.printStackTrace();
 
100
            }
 
101
         }
 
102
      }
 
103
 
 
104
   }
 
105
 
 
106
   private synchronized boolean addToReceivedCount(int localClientInvokeCount)
 
107
   {
 
108
      boolean isDuplicate = false;
 
109
      if(counterArray == null)
 
110
      {
 
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.");
 
113
      }
 
114
      else
 
115
      {
 
116
         try
 
117
         {
 
118
            isDuplicate = counterArray[localClientInvokeCount];
 
119
            if(!isDuplicate)
 
120
            {
 
121
               counterArray[localClientInvokeCount] = true;
 
122
            }
 
123
         }
 
124
         catch(ArrayIndexOutOfBoundsException e)
 
125
         {
 
126
            System.err.println("Got ArrayIndexOutOfBoundsException");
 
127
            System.err.println("Counter array size = " + counterArray.length);
 
128
            System.err.println("Received count = " + localClientInvokeCount);
 
129
            e.printStackTrace();
 
130
         }
 
131
      }
 
132
      return isDuplicate;
 
133
   }
 
134
 
 
135
}
 
 
b'\\ No newline at end of file'