Class SubscriptionSet<LISTENER_TYPE>

java.lang.Object
io.deephaven.util.datastructures.SubscriptionSet<LISTENER_TYPE>

public class SubscriptionSet<LISTENER_TYPE> extends Object

Array-backed set that stores generic listener objects, only enforcing hard reachability on listeners that are SubstitutionWeakReferences.

All public operations (except clear and isEmpty) are O(n). All comparisons are based on object reference equality.

Requires external synchronization for thread safe usage, except where otherwise noted.

  • Constructor Details

    • SubscriptionSet

      public SubscriptionSet()
  • Method Details

    • clear

      public final void clear()
      Remove all listeners.
    • isEmpty

      public final boolean isEmpty()
      Check if this set is empty, without cleaning up existing subscriptions.
      Returns:
      Whether this set is empty
    • collect

      public final boolean collect()
      Clean up any GC'd subscriptions.
      Returns:
      Whether this operation caused the set to become empty
    • makeEntryFor

      public final SubscriptionSet<LISTENER_TYPE>.Entry makeEntryFor(LISTENER_TYPE listener)
      Make an entry for a listener, in order to pass it to add(Object, SubscriptionSet.Entry). May be called without holding any locks.
      Parameters:
      listener - The listener
      Returns:
      A new entry for the listener
    • add

      public final boolean add(@NotNull LISTENER_TYPE listener, @NotNull SubscriptionSet<LISTENER_TYPE>.@NotNull Entry entry)
      Add a listener to the set, if it's not already present. Clean up any GC'd subscriptions. See makeEntryFor(Object).
      Parameters:
      listener - The listener to be added
      entry - An entry for the listener to be added
      Returns:
      Whether this operation caused the set to become non-empty
    • remove

      public final boolean remove(LISTENER_TYPE listener)
      Remove a listener from the set, if it's present. Clean up any GC'd subscriptions.
      Parameters:
      listener - The listener to remove
      Returns:
      Whether this operation caused the set to become empty
    • deliverNotification

      public final boolean deliverNotification(@NotNull @NotNull Consumer<LISTENER_TYPE> procedure, boolean activeOnly)
      Dispatch a nullary notification to all subscribers. Clean up any GC'd subscriptions.
      Parameters:
      procedure - The notification procedure to invoke
      activeOnly - Whether to restrict this notification to active subscriptions only
      Returns:
      Whether this operation caused the set to become empty
    • deliverNotification

      public final <NOTIFICATION_TYPE> boolean deliverNotification(@NotNull @NotNull BiConsumer<LISTENER_TYPE,NOTIFICATION_TYPE> procedure, @Nullable NOTIFICATION_TYPE notification, boolean activeOnly)
      Dispatch a unary notification to all subscribers. Clean up any GC'd subscriptions.
      Parameters:
      procedure - The notification procedure to invoke
      notification - The notification to deliver
      activeOnly - Whether to restrict this notification to active subscriptions only
      Returns:
      Whether this operation caused the set to become empty
    • deliverNotification

      public final <NOTIFICATION_TYPE> boolean deliverNotification(@NotNull @NotNull org.apache.commons.lang3.function.TriConsumer<LISTENER_TYPE,NOTIFICATION_TYPE,NOTIFICATION_TYPE> procedure, @Nullable NOTIFICATION_TYPE firstNotification, @Nullable NOTIFICATION_TYPE secondNotification, boolean activeOnly)
      Dispatch a notification to all subscribers. Clean up any GC'd subscriptions.
      Parameters:
      procedure - The notification procedure to invoke
      firstNotification - The first item to deliver
      secondNotification - The second item to deliver (must be of the same type as firstNotification)
      activeOnly - Whether to restrict this notification to active subscriptions only
      Returns:
      Whether this operation caused the set to become empty