ozeigermann    2004/12/28 13:11:12

  Modified:    transaction/src/test/org/apache/commons/transaction/locking
                        GenericLockTest.java
  Added:       transaction/src/java/org/apache/commons/transaction/util
                        SequenceBarrier.java
  Removed:     transaction/src/java/org/apache/commons/transaction/util
                        CounterBarrier.java
  Log:
  Renamed CounterBarrier to SequenceBarrier
  
  Revision  Changes    Path
  1.1                  
jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/SequenceBarrier.java
  
  Index: SequenceBarrier.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/SequenceBarrier.java,v
 1.1 2004/12/28 21:11:12 ozeigermann Exp $
   * $Revision: 1.1 $
   * $Date: 2004/12/28 21:11:12 $
   *
   * ====================================================================
   *
   * Copyright 1999-2002 The Apache Software Foundation 
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  package org.apache.commons.transaction.util;
  
  /**
   * Simple counter barrier to make a sequence of calls from different threads 
deterministic.
   * This is very useful for testing where you want to have a contious flow 
throughout 
   * different threads. The idea is to have an ordered sequence of steps where 
step n can not be 
   * executed before n-1.
   * 
   * @version $Revision: 1.1 $
   */
  public class SequenceBarrier {
  
      public static final int DEFAULT_TIMEOUT = 20000;
  
      protected final String name;
  
      protected int currentNumber;
  
      protected long timeout;
  
      protected LoggerFacade logger;
  
      public SequenceBarrier(String name, long timeout, LoggerFacade logger) {
          this.name = name;
          this.timeout = timeout;
          this.logger = logger;
          currentNumber = 0;
      }
  
      /**
       * Compares the number to the the internal counter. If it is greater than 
the counter
       * it's not our turn and we wait. If it is eqaul we increment the 
internal counter and let
       * others check if it is their turn now. 
       */
      public synchronized void count(int number) throws InterruptedException {
          if (number > currentNumber) {
              long started = System.currentTimeMillis();
              for (long remaining = timeout; remaining > 0 && number > 
currentNumber; remaining = timeout
                      - (System.currentTimeMillis() - started)) {
                  wait(remaining);
              }
          }
          if (number == currentNumber) {
              currentNumber++;
              notifyAll();
          }
      }
  
      public synchronized void reset() {
          currentNumber = 0;
          notifyAll();
      }
  }
  
  
  1.9       +9 -9      
jakarta-commons/transaction/src/test/org/apache/commons/transaction/locking/GenericLockTest.java
  
  Index: GenericLockTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/transaction/src/test/org/apache/commons/transaction/locking/GenericLockTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GenericLockTest.java      19 Dec 2004 10:35:55 -0000      1.8
  +++ GenericLockTest.java      28 Dec 2004 21:11:12 -0000      1.9
  @@ -29,7 +29,7 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  -import org.apache.commons.transaction.util.CounterBarrier;
  +import org.apache.commons.transaction.util.SequenceBarrier;
   import org.apache.commons.transaction.util.LoggerFacade;
   import org.apache.commons.transaction.util.PrintWriterLogger;
   import org.apache.commons.transaction.util.RendezvousBarrier;
  @@ -268,7 +268,7 @@
   
           final RendezvousBarrier restart = new RendezvousBarrier("restart", 
3, TIMEOUT, sLogger);
   
  -        final CounterBarrier cb = new CounterBarrier("cb1", TIMEOUT, 
sLogger);
  +        final SequenceBarrier cb = new SequenceBarrier("cb1", TIMEOUT, 
sLogger);
   
           for (int i = 0; i < CONCURRENT_TESTS; i++) {
               
  @@ -385,7 +385,7 @@
        * 8                                released   or   released
        * 
        * 
  -     * In CounterBarrierNotation this looks like
  +     * In SequenceBarrier notation this looks like
        * 
        *                  Owner           Owner           Owner
        *                  #1              #2              #3
  @@ -413,7 +413,7 @@
   
           final RendezvousBarrier restart = new RendezvousBarrier("restart", 
3, TIMEOUT, sLogger);
   
  -        final CounterBarrier cb = new CounterBarrier("cb1", TIMEOUT, 
sLogger);
  +        final SequenceBarrier cb = new SequenceBarrier("cb1", TIMEOUT, 
sLogger);
   
           for (int i = 0; i < CONCURRENT_TESTS; i++) {
               
  @@ -496,7 +496,7 @@
   
           final RendezvousBarrier restart = new RendezvousBarrier("restart", 
2, TIMEOUT, sLogger);
   
  -        final CounterBarrier cb = new CounterBarrier("cb1", TIMEOUT, 
sLogger);
  +        final SequenceBarrier cb = new SequenceBarrier("cb1", TIMEOUT, 
sLogger);
   
           for (int i = 0; i < CONCURRENT_TESTS; i++) {
               
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to