Class ConcurrentDequePublisher<T>
java.lang.Object
dev.getelements.elements.sdk.util.AbstractPublisher<T>
dev.getelements.elements.sdk.util.ConcurrentDequePublisher<T>
- Type Parameters:
T
-
- All Implemented Interfaces:
Publisher<T>
,Iterable<Subscription>
public class ConcurrentDequePublisher<T>
extends AbstractPublisher<T>
implements Iterable<Subscription>
A thread-safe
Publisher
which uses a standard ConcurrentLinkedDeque
to perform operations.
When iterating the list of subscribers (such as when dispatching events) no locks are required as iteration
of the list can happen without any locks. The iterator is weakly consistent as per the implementation of
of ConcurrentLinkedDeque
and unsubscription happens in O(n) (worst case).-
Field Summary
Fields inherited from class dev.getelements.elements.sdk.util.AbstractPublisher
logger
-
Constructor Summary
ConstructorsConstructorDescriptionConcurrentDequePublisher
(Class<?> cls) ConcurrentDequePublisher
(org.slf4j.Logger logger) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears allSubscription
s and implicitly removes them from the internal pool.iterator()
void
Publishes the supplied event synchronously and calls theConsumer
when allSubscription
s have been notified.subscribe
(BiConsumer<Subscription, ? super T> consumer) Subscribes to a particular event.Methods inherited from class dev.getelements.elements.sdk.util.AbstractPublisher
handleException, logException, publish, publish
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ConcurrentDequePublisher
public ConcurrentDequePublisher() -
ConcurrentDequePublisher
-
ConcurrentDequePublisher
public ConcurrentDequePublisher(org.slf4j.Logger logger)
-
-
Method Details
-
subscribe
Description copied from interface:Publisher
Subscribes to a particular event. The suppliedBiConsumer
will receive zero or more events in the future until the associated call toSubscription.unsubscribe()
.- Specified by:
subscribe
in interfacePublisher<T>
- Parameters:
consumer
- theBiConsumer
which will accept event- Returns:
- the
Subscription
-
clear
public void clear()Description copied from interface:Publisher
Clears allSubscription
s and implicitly removes them from the internal pool. Implementing this interface method is optional, and therefore this may throw an instance ofUnsupportedOperationException
. -
publish
Description copied from interface:Publisher
Publishes the supplied event synchronously and calls theConsumer
when allSubscription
s have been notified. Additionally, this notifies for every exception thrown in the process. -
iterator
-