Interface RetryLatch

  • All Known Implementing Classes:
    DefaultRetryLatch

    public interface RetryLatch
    A blockingAllowed structure that can be used to create blocking transactions. When a transaction blocks, a 'listener' is added to each read transactional object. This listener is the Latch. Each transactional object can have a set of listeners.

    The Latch can safely be created once by a Txn and reused by the same Txn because it works based on an listenerEra. So of opens happen with an older listener-era, the open is ignored. So even though the Latch could be attached to an older ref that didn't get updated, but is updated eventually even though the latch is notified by another ref, there is no problem.

    By resetting it, the listenerEra-counter is incremented, so that call to open or await are ignored.

    • Method Summary

      All Methods Instance Methods Abstract 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.
    • Method Detail

      • isOpen

        boolean isOpen()
        Checks if the Latch is open.
        Returns:
        true if the Latch is open, false otherwise.
      • open

        void open​(long expectedEra)
        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.
        Parameters:
        expectedEra - the expected era.
      • getEra

        long getEra()
        Gets the current era.
        Returns:
        the current era.
      • awaitUninterruptible

        void awaitUninterruptible​(long expectedEra)
        Awaits for this latch to open. This call is not responsive to interrupts.
        Parameters:
        expectedEra - the expected era. If the era is different, the await always succeeds.
      • await

        void await​(long expectedEra,
                   java.lang.String transactionFamilyName)
        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.
        Parameters:
        expectedEra - the expected era.
        transactionFamilyName - the name of the transaction (only needed for creating a usable message in the RetryInterruptedException).
        Throws:
        RetryInterruptedException
      • awaitNanosUninterruptible

        long awaitNanosUninterruptible​(long expectedEra,
                                       long nanosTimeout)
        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.

        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

        long awaitNanos​(long expectedEra,
                        long nanosTimeout,
                        java.lang.String transactionFamilyName)
        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.

        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.
        Throws:
        RetryInterruptedException
      • reset

        void reset()
        Prepares the Latch for pooling. All waiting threads will be notified and the era is increased.