Package org.multiverse.api.blocking
Class DefaultRetryLatch
- java.lang.Object
-
- org.multiverse.api.blocking.DefaultRetryLatch
-
- All Implemented Interfaces:
RetryLatch
public final class DefaultRetryLatch extends java.lang.Object implements RetryLatch
A CheapRetryLatch
implementation based on the intrinsic lock.
-
-
Constructor Summary
Constructors Constructor Description DefaultRetryLatch()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
await(long expectedEra, java.lang.String transactionFamilyName)
Awaits for this Latch to open.long
awaitNanos(long expectedEra, long nanosTimeout, java.lang.String transactionFamilyName)
Awaits for this latch to open with a timeout.long
awaitNanosUninterruptible(long expectedEra, long nanosTimeout)
Awaits for this latch to open with a timeout.void
awaitUninterruptible(long expectedEra)
Awaits for this latch to open.long
getEra()
Gets the current era.boolean
isOpen()
Checks if the Latch is open.void
open(long expectedEra)
Opens this latch only if the expectedEra is the same.void
reset()
Prepares the Latch for pooling.java.lang.String
toString()
-
-
-
Method Detail
-
open
public void open(long expectedEra)
Description copied from interface:RetryLatch
Opens this latch only if the expectedEra is the same. If the expectedEra is not the same, the call is ignored. If the Latch already is open, this call is also ignored.- Specified by:
open
in interfaceRetryLatch
- Parameters:
expectedEra
- the expected era.
-
await
public void await(long expectedEra, java.lang.String transactionFamilyName)
Description copied from interface:RetryLatch
Awaits for this Latch to open. There are 3 possible ways for this methods to complete;- the era doesn't match the expected era
- the latch is opened while waiting
- the latch is interrupted while waiting. When this happens the RetryInterruptedException is thrown and the Thread.interrupt status is restored.
- Specified by:
await
in interfaceRetryLatch
- Parameters:
expectedEra
- the expected era.transactionFamilyName
- the name of the transaction (only needed for creating a usable message in the RetryInterruptedException).
-
awaitUninterruptible
public void awaitUninterruptible(long expectedEra)
Description copied from interface:RetryLatch
Awaits for this latch to open. This call is not responsive to interrupts.- Specified by:
awaitUninterruptible
in interfaceRetryLatch
- Parameters:
expectedEra
- the expected era. If the era is different, the await always succeeds.
-
awaitNanosUninterruptible
public long awaitNanosUninterruptible(long expectedEra, long nanosTimeout)
Description copied from interface:RetryLatch
Awaits for this latch to open with a timeout. This call is not responsive to interrupts. When the calling thread is interrupted, the Thread.interrupt status will not be eaten by this method and safely be restored.- Specified by:
awaitNanosUninterruptible
in interfaceRetryLatch
- Parameters:
expectedEra
- the expected era.nanosTimeout
- the timeout in nanoseconds- Returns:
- the remaining timeout. A negative value indicates that the Latch is not opened in time.
-
awaitNanos
public long awaitNanos(long expectedEra, long nanosTimeout, java.lang.String transactionFamilyName)
Description copied from interface:RetryLatch
Awaits for this latch to open with a timeout. This call is responsive to interrupts. When the calling thread is interrupted, the Thread.interrupt status will not be eaten by this method and safely be restored.- Specified by:
awaitNanos
in interfaceRetryLatch
- Parameters:
expectedEra
- the expected erananosTimeout
- the timeout in nanoseconds. Can safely be called with a zero or negative timeouttransactionFamilyName
- the name of the transaction (only needed for creating a usable message in the RetryInterruptedException).- Returns:
- the remaining timeout. A 0 or negative value indicates that the latch is not opened in time.
-
getEra
public long getEra()
Description copied from interface:RetryLatch
Gets the current era.- Specified by:
getEra
in interfaceRetryLatch
- Returns:
- the current era.
-
reset
public void reset()
Description copied from interface:RetryLatch
Prepares the Latch for pooling. All waiting threads will be notified and the era is increased.- Specified by:
reset
in interfaceRetryLatch
-
isOpen
public boolean isOpen()
Description copied from interface:RetryLatch
Checks if the Latch is open.- Specified by:
isOpen
in interfaceRetryLatch
- Returns:
- true if the Latch is open, false otherwise.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-