Package org.multiverse.api.blocking
Class DefaultRetryLatch
java.lang.Object
org.multiverse.api.blocking.DefaultRetryLatch
- All Implemented Interfaces:
RetryLatch
A Cheap
RetryLatch implementation based on the intrinsic lock.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAwaits for this Latch to open.longawaitNanos(long expectedEra, long nanosTimeout, String transactionFamilyName) Awaits for this latch to open with a timeout.longawaitNanosUninterruptible(long expectedEra, long nanosTimeout) Awaits for this latch to open with a timeout.voidawaitUninterruptible(long expectedEra) Awaits for this latch to open.longgetEra()Gets the current era.booleanisOpen()Checks if the Latch is open.voidopen(long expectedEra) Opens this latch only if the expectedEra is the same.voidreset()Prepares the Latch for pooling.toString()
-
Field Details
-
era
private volatile long era -
isOpen
private volatile boolean isOpen
-
-
Constructor Details
-
DefaultRetryLatch
public DefaultRetryLatch()
-
-
Method Details
-
open
public void open(long expectedEra) Description copied from interface:RetryLatchOpens 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:
openin interfaceRetryLatch- Parameters:
expectedEra- the expected era.
-
await
Description copied from interface:RetryLatchAwaits 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:
awaitin 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:RetryLatchAwaits for this latch to open. This call is not responsive to interrupts.- Specified by:
awaitUninterruptiblein 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:RetryLatchAwaits 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:
awaitNanosUninterruptiblein 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
Description copied from interface:RetryLatchAwaits 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:
awaitNanosin 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:RetryLatchGets the current era.- Specified by:
getErain interfaceRetryLatch- Returns:
- the current era.
-
reset
public void reset()Description copied from interface:RetryLatchPrepares the Latch for pooling. All waiting threads will be notified and the era is increased.- Specified by:
resetin interfaceRetryLatch
-
isOpen
public boolean isOpen()Description copied from interface:RetryLatchChecks if the Latch is open.- Specified by:
isOpenin interfaceRetryLatch- Returns:
- true if the Latch is open, false otherwise.
-
toString
-