com.hazelcast.core
Interface ICountDownLatch

All Superinterfaces:
Instance

public interface ICountDownLatch
extends Instance

ICountDownLatch is a backed-up distributed implementation of java.util.concurrent.CountDownLatch.

Hazelcast's ICountDownLatch is a cluster-wide synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes.

Unlike Java's implementation, Hazelcast's ICountDownLatch count can be re-set after a countdown has finished but not during an active count. This allows the same proxy instance to be reused.

The Hazelcast member that successfully invokes setCount(int) becomes the owner of the countdown and is responsible for staying connected to the cluster until the count reaches zero. If the owner becomes disconnected prior to count reaching zero all awaiting threads will be notified. This provides a safety mechanism in the distributed environment.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.hazelcast.core.Instance
Instance.InstanceType
 
Method Summary
 void await()
          Causes the current thread to wait until the latch has counted down to zero or an exception is thrown.
 boolean await(long timeout, TimeUnit unit)
          Causes the current thread to wait until the latch has counted down to zero, an exception is thrown, or the specified waiting time elapses.
 void countDown()
          Decrements the count of the latch, releasing all waiting threads if the count reaches zero.
 LocalCountDownLatchStats getLocalCountDownLatchStats()
           
 String getName()
          Returns the name of this ICountDownLatch instance.
 boolean hasCount()
          Returns whether the current count is greater than zero.
 boolean setCount(int count)
          Sets the count to the given value if the current count is zero.
 
Methods inherited from interface com.hazelcast.core.Instance
destroy, getId, getInstanceType
 

Method Detail

getName

String getName()
Returns the name of this ICountDownLatch instance.

Returns:
name of this instance

await

void await()
           throws InstanceDestroyedException,
                  MemberLeftException,
                  InterruptedException
Causes the current thread to wait until the latch has counted down to zero or an exception is thrown.

If the current count is zero then this method returns immediately.

If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of four things happen:

If the ICountDownLatch instance is destroyed while waiting then InstanceDestroyedException will be thrown.

If the countdown owner becomes disconnected while waiting then MemberLeftException will be thrown.

If the current thread:

then InterruptedException is thrown and the current thread's interrupted status is cleared.

Throws:
InstanceDestroyedException - if the instance is destroyed while waiting
MemberLeftException - if the countdown owner becomes disconnected while waiting
InterruptedException - if the current thread is interrupted
IllegalStateException - if hazelcast instance is shutdown while waiting

await

boolean await(long timeout,
              TimeUnit unit)
              throws InstanceDestroyedException,
                     MemberLeftException,
                     InterruptedException
Causes the current thread to wait until the latch has counted down to zero, an exception is thrown, or the specified waiting time elapses.

If the current count is zero then this method returns immediately with the value true.

If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of five things happen:

If the count reaches zero then the method returns with the value true.

If the ICountDownLatch instance is destroyed while waiting then InstanceDestroyedException will be thrown.

If the countdown owner becomes disconnected while waiting then MemberLeftException will be thrown.

If the current thread:

then InterruptedException is thrown and the current thread's interrupted status is cleared.

If the specified waiting time elapses then the value false is returned. If the time is less than or equal to zero, the method will not wait at all.

Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
true if the count reached zero and false if the waiting time elapsed before the count reached zero
Throws:
InstanceDestroyedException - if the instance is destroyed while waiting
MemberLeftException - if the countdown owner becomes disconnected while waiting
InterruptedException - if the current thread is interrupted
IllegalStateException - if hazelcast instance is shutdown while waiting

countDown

void countDown()
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.

If the current count is greater than zero then it is decremented. If the new count is zero:

If the current count equals zero then nothing happens.


hasCount

boolean hasCount()
Returns whether the current count is greater than zero.

Returns:
true if count is greater than zero

setCount

boolean setCount(int count)
Sets the count to the given value if the current count is zero. The calling cluster member becomes the owner of the countdown and is responsible for staying connected to the cluster until the count reaches zero.

If the owner becomes disconnected before the count reaches zero:

If count is not zero then this method does nothing and returns false.

Parameters:
count - the number of times countDown() must be invoked before threads can pass through await()
Returns:
true if the new count was set or false if the current count is not zero
Throws:
IllegalArgumentException - if count is negative

getLocalCountDownLatchStats

LocalCountDownLatchStats getLocalCountDownLatchStats()


Copyright © 2008-2012 Hazel Ltd. All Rights Reserved.