org.apache.ignite.internal.processors.datastructures

## Class GridCacheCountDownLatchImpl

- java.lang.Object
- - org.apache.ignite.internal.processors.datastructures.GridCacheCountDownLatchImpl

All Implemented Interfaces:
  Closeable, Externalizable, Serializable, AutoCloseable, IgniteCountDownLatch, GridCacheCountDownLatchEx, GridCacheRemovable

    public final class GridCacheCountDownLatchImpl
    extends Object
    implements GridCacheCountDownLatchEx, Externalizable

Cache count down latch implementation.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`GridCacheCountDownLatchImpl()` Empty constructor required by `Externalizable`.
`GridCacheCountDownLatchImpl(String name, int initCnt, boolean autoDel, GridCacheInternalKey key, IgniteInternalCache<GridCacheInternalKey,GridCacheCountDownLatchValue> latchView, GridCacheContext ctx)` Constructor.

### Method Summary

Methods
`boolean` `autoDelete()` Gets `autoDelete` flag.
`void` `await()` Causes the current thread to wait until the latch has counted down to zero, unless current thread is interrupted.
`boolean` `await(long timeout)` Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, or the specified waiting time elapses.
`boolean` `await(long timeout, TimeUnit unit)` Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, or the specified waiting time elapses.
`void` `close()` Removes this count down latch.
`int` `count()` Gets current count value of the latch.
`int` `countDown()` Decrements the count of the latch, releasing all waiting threads on all nodes if the count reaches zero.
`int` `countDown(int val)` Decreases the count of the latch using passed in value, releasing all waiting threads on all nodes if the count reaches zero.
`void` `countDownAll()` Counts down this latch to zero, releasing all waiting threads on all nodes.
`int` `initialCount()` Gets initial count value of the latch.
`GridCacheInternalKey` `key()` Get current count down latch key.
`String` `name()` Gets name of the latch.
`void` `needCheckNotRemoved()`
`boolean` `onRemoved()` Set status of data structure as removed.
`void` `onUpdate(int cnt)` Callback to notify latch on changes.
`void` `readExternal(ObjectInput in)`
`boolean` `removed()` Gets `removed` status of the latch.
`String` `toString()`
`void` `writeExternal(ObjectOutput out)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### GridCacheCountDownLatchImpl

    public GridCacheCountDownLatchImpl()

Empty constructor required by `Externalizable`.

#### GridCacheCountDownLatchImpl

    public GridCacheCountDownLatchImpl(String name,
                               int initCnt,
                               boolean autoDel,
                               GridCacheInternalKey key,
                               IgniteInternalCache<GridCacheInternalKey,GridCacheCountDownLatchValue> latchView,
                               GridCacheContext ctx)

Constructor.

Parameters:
  `name` - Latch name.
  `initCnt` - Initial count.
  `autoDel` - Auto delete flag.
  `key` - Latch key.
  `latchView` - Latch projection.
  `ctx` - Cache context.

### Method Detail

#### name

    public String name()

Gets name of the latch.

Specified by:
  `name` in interface `IgniteCountDownLatch`
Returns:
  Name of the latch.

#### count

    public int count()

Gets current count value of the latch.

Specified by:
  `count` in interface `IgniteCountDownLatch`
Returns:
  Current count.

#### initialCount

    public int initialCount()

Gets initial count value of the latch.

Specified by:
  `initialCount` in interface `IgniteCountDownLatch`
Returns:
  Initial count.

#### autoDelete

    public boolean autoDelete()

Gets `autoDelete` flag. If this flag is `true` latch is removed from cache when it has been counted down to 0.

Specified by:
  `autoDelete` in interface `IgniteCountDownLatch`
Returns:
  Value of `autoDelete` flag.

#### await

    public void await()

Causes the current thread to wait until the latch has counted down to zero, unless current thread is interrupted.

If the current count of the latch 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 two things happen:

- The count reaches zero due to invocations of the `IgniteCountDownLatch.countDown()` method on any node; or
- Some other thread interrupts the current thread.

If the current thread:

- has its interrupted status set on entry to this method; or
- is interrupted while waiting,

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

Specified by:
  `await` in interface `IgniteCountDownLatch`

#### await

    public boolean await(long timeout,
                TimeUnit unit)

Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, 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 three things happen:

- The count reaches zero due to invocations of the `IgniteCountDownLatch.countDown()` method on any node; or
- Some other thread interrupts the current thread; or
- The specified waiting time elapses.

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

If the current thread:

- has its interrupted status set on entry to this method; or
- is interrupted while waiting,

then `IgniteInterruptedCheckedException` 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.

Specified by:
  `await` in interface `IgniteCountDownLatch`
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.

#### await

    public boolean await(long timeout)

Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, 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 three things happen:

- The count reaches zero due to invocations of the `IgniteCountDownLatch.countDown()` method on any node; or
- Some other thread interrupts the current thread; or
- The specified waiting time elapses.

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

If the current thread:

- has its interrupted status set on entry to this method; or
- is interrupted while waiting,

then `IgniteInterruptedCheckedException` 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.

Specified by:
  `await` in interface `IgniteCountDownLatch`
Parameters:
  `timeout` - The maximum time to wait in milliseconds.
Returns:
  `True` if the count reached zero and `false` if the waiting time elapsed before the count reached zero.

#### countDown

    public int countDown()

Decrements the count of the latch, releasing all waiting threads on all nodes if the count reaches zero.

If the current count is greater than zero then it is decremented. If the new count is zero then all waiting threads are re-enabled for thread scheduling purposes.

If the current count equals zero then nothing happens.

Specified by:
  `countDown` in interface `IgniteCountDownLatch`
Returns:
  Count after decrement.

#### countDown

    public int countDown(int val)

Decreases the count of the latch using passed in value, releasing all waiting threads on all nodes if the count reaches zero.

If the current count is greater than zero then it is decreased. If the new count is zero then all waiting threads are re-enabled for thread scheduling purposes.

If the current count equals zero then nothing happens.

Specified by:
  `countDown` in interface `IgniteCountDownLatch`
Parameters:
  `val` - Value to decrease counter on.
Returns:
  Count after decreasing.

#### countDownAll

    public void countDownAll()

Counts down this latch to zero, releasing all waiting threads on all nodes.

If the current count equals zero then nothing happens.

Specified by:
  `countDownAll` in interface `IgniteCountDownLatch`

#### onRemoved

    public boolean onRemoved()

Set status of data structure as removed.

Specified by:
  `onRemoved` in interface `GridCacheRemovable`
Returns:
  Current status.

#### needCheckNotRemoved

    public void needCheckNotRemoved()

Specified by:
  `needCheckNotRemoved` in interface `GridCacheRemovable`

#### key

    public GridCacheInternalKey key()

Get current count down latch key.

Specified by:
  `key` in interface `GridCacheCountDownLatchEx`
Returns:
  Latch key.

#### removed

    public boolean removed()

Gets `removed` status of the latch.

Specified by:
  `removed` in interface `IgniteCountDownLatch`
Returns:
  `True` if latch was removed from cache, `false` otherwise.

#### onUpdate

    public void onUpdate(int cnt)

Callback to notify latch on changes.

Specified by:
  `onUpdate` in interface `GridCacheCountDownLatchEx`
Parameters:
  `cnt` - New count.

#### close

    public void close()

Removes this count down latch.

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `IgniteCountDownLatch`

#### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`
  `ClassNotFoundException`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.9.0
Release Date | : March 2 2017