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 TypeMethodDescriptionvoidclear()Clears allSubscriptions and implicitly removes them from the internal pool.iterator()voidPublishes the supplied event synchronously and calls theConsumerwhen allSubscriptions 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, publishMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:PublisherSubscribes to a particular event. The suppliedBiConsumerwill receive zero or more events in the future until the associated call toSubscription.unsubscribe().- Specified by:
subscribein interfacePublisher<T>- Parameters:
consumer- theBiConsumerwhich will accept event- Returns:
- the
Subscription
-
clear
public void clear()Description copied from interface:PublisherClears allSubscriptions 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:PublisherPublishes the supplied event synchronously and calls theConsumerwhen allSubscriptions have been notified. Additionally, this notifies for every exception thrown in the process. -
iterator
-