org.apache.camel.util.concurrent
Class CountingLatch

java.lang.Object
  extended by org.apache.camel.util.concurrent.CountingLatch

public class CountingLatch
extends Object

An alternative to a CountDownLatch -- this implementation also supports incrementing the latch count while counting down. It can also be used to count up to 0 from a negative integer.


Constructor Summary
CountingLatch()
          Create a new counting latch (starting count is 0)
 
Method Summary
 void await()
          Await the latch reaching the count of 0
 boolean await(long timeout, TimeUnit unit)
          Wait for a given timeout while checking if the latch reached the count of 0
 void decrement()
          Decrement the count with 1
 int getCount()
          Get the current count
 void increment()
          Increment the count with 1
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CountingLatch

public CountingLatch()
Create a new counting latch (starting count is 0)

Method Detail

getCount

public int getCount()
Get the current count


increment

public void increment()
Increment the count with 1


decrement

public void decrement()
Decrement the count with 1


await

public void await()
           throws InterruptedException
Await the latch reaching the count of 0

Throws:
InterruptedException - if the threads gets interrupted while waiting

await

public boolean await(long timeout,
                     TimeUnit unit)
              throws InterruptedException
Wait for a given timeout while checking if the latch reached the count of 0

Parameters:
timeout - the value of the timeout
unit - the unit in which the timeout is expressed
Returns:
true if the latch has reached the count of 0 in the given time
Throws:
InterruptedException - if the thread gets interrupted while waiting


Copyright © 2008 IONA Open Source Community. All Rights Reserved.