Class DefaultRetryLatch

java.lang.Object
org.multiverse.api.blocking.DefaultRetryLatch
All Implemented Interfaces:
RetryLatch

public final class DefaultRetryLatch extends Object implements RetryLatch
A Cheap RetryLatch implementation based on the intrinsic lock.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
     
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    await(long expectedEra, String transactionFamilyName)
    Awaits for this Latch to open.
    long
    awaitNanos(long expectedEra, long nanosTimeout, 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
    Gets the current era.
    boolean
    Checks if the Latch is open.
    void
    open(long expectedEra)
    Opens this latch only if the expectedEra is the same.
    void
    Prepares the Latch for pooling.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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: 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 interface RetryLatch
      Parameters:
      expectedEra - the expected era.
    • await

      public void await(long expectedEra, String transactionFamilyName)
      Description copied from interface: RetryLatch
      Awaits for this Latch to open. There are 3 possible ways for this methods to complete;
      1. the era doesn't match the expected era
      2. the latch is opened while waiting
      3. the latch is interrupted while waiting. When this happens the RetryInterruptedException is thrown and the Thread.interrupt status is restored.
      Specified by:
      await in interface RetryLatch
      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 interface RetryLatch
      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 interface RetryLatch
      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, 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 interface RetryLatch
      Parameters:
      expectedEra - the expected era
      nanosTimeout - the timeout in nanoseconds. Can safely be called with a zero or negative timeout
      transactionFamilyName - 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 interface RetryLatch
      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 interface RetryLatch
    • isOpen

      public boolean isOpen()
      Description copied from interface: RetryLatch
      Checks if the Latch is open.
      Specified by:
      isOpen in interface RetryLatch
      Returns:
      true if the Latch is open, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object