Package io.deephaven.util.datastructures
Class SubscriptionSet<LISTENER_TYPE>
java.lang.Object
io.deephaven.util.datastructures.SubscriptionSet<LISTENER_TYPE>
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Subscription entry, allowing state associated with a listener. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
add
(LISTENER_TYPE listener, SubscriptionSet<LISTENER_TYPE>.@NotNull Entry entry) Add a listener to the set, if it's not already present.final void
clear()
Remove all listeners.final boolean
collect()
Clean up any GC'd subscriptions.final <NOTIFICATION_TYPE>
booleandeliverNotification
(@NotNull BiConsumer<LISTENER_TYPE, NOTIFICATION_TYPE> procedure, NOTIFICATION_TYPE notification, boolean activeOnly) Dispatch a unary notification to all subscribers.final boolean
deliverNotification
(@NotNull Consumer<LISTENER_TYPE> procedure, boolean activeOnly) Dispatch a nullary notification to all subscribers.final boolean
isEmpty()
Check if this set is empty, without cleaning up existing subscriptions.final SubscriptionSet<LISTENER_TYPE>.Entry
makeEntryFor
(LISTENER_TYPE listener) Make an entry for a listener, in order to pass it toadd(Object, SubscriptionSet.Entry)
.final boolean
remove
(LISTENER_TYPE listener) Remove a listener from the set, if it's present.
-
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
Make an entry for a listener, in order to pass it toadd(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. SeemakeEntryFor(Object)
.- Parameters:
listener
- The listener to be addedentry
- An entry for the listener to be added- Returns:
- Whether this operation caused the set to become non-empty
-
remove
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 invokeactiveOnly
- 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 invokenotification
- The notification to deliveractiveOnly
- Whether to restrict this notification to active subscriptions only- Returns:
- Whether this operation caused the set to become empty
-