Package org.multiverse.stms.gamma

## Class Listeners

- java.lang.Object
- - org.multiverse.stms.gamma.Listeners

-     public final class Listeners
      extends Object

  A Listeners object contains all the Latches of blockingAllowed transactions that listen to a write on a transactional object. Essentially it is a single linked list.

  This is an 'immutable' class. As long as it is registered to a transactional object, it should not be mutated. But as soon as it is removed as listener, only a single thread has access to this Listeners object. This means that it can be pooled.

  Setting the Listeners and removing the it should provide the happens before relation so that all changes made to the Listener before it is getAndSet, are visible when it is removed.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `RetryLatch` | `listener` |
    `long` | `listenerEra` |
    `Listeners` | `next` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Listeners()` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `openAll​(GammaObjectPool pool)` | Opens all latches.
    `static void` | `openAll​(Listeners[] listenersArray, GammaObjectPool pool)` | Opens all the listeners.
    `void` | `prepareForPooling()` | Prepares this Listeners object for pooling.

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

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

- - ### Field Detail

    - #### next

          public Listeners next

    - #### listener

          public RetryLatch listener

    - #### listenerEra

          public long listenerEra

  - ### Constructor Detail

    - #### Listeners

          public Listeners()

  - ### Method Detail

    - #### prepareForPooling

          public void prepareForPooling()

      Prepares this Listeners object for pooling. This is done by:
      1. setting the next to null
      2. setting the listener to null
      3. setting the listenerEra to Long.MIN_VALUE

      This call is not threadsafe and should only be done by a transaction that has exclusive access to the listeners. The most logical place would be in the object pool when the Listeners is placed there.

    - #### openAll

          public void openAll​(GammaObjectPool pool)

      Opens all latches.

      All Listeners are put in the pool. The Latches are not put in the pool since no guarantee can be given that the Latch is still registered on a different transactional object.

      This call should only be done by the transaction that removed the listeners from the transactional object. So it is not threadsafe,
      Parameters:
        `pool` - the GammaObjectPool to store the discarded Listeners in.

    - #### openAll

          public static void openAll​(Listeners[] listenersArray,
                                     GammaObjectPool pool)

      Opens all the listeners. As soon as in the array a null element is found, it signals the end of the list of listeners. This makes is possible to place an array that is larger than the actual number of writes.

      The call safely can be made with a null listenersArray. In that case the call is ignored.
      Parameters:
        `listenersArray` - the array of Listeners to notify.
        `pool` - the GammaObjectPool to pool the Listeners and the array containing the listeners.