K - the type of the conflation keyV - the type of values in the queue@FunctionalInterface public interface PollerListener<K,V>
poller of a ConflationQueue for instance useful to
record performance metrics related to poll operations. The listener or a supplier thereof is usually passed to
the constructor of a conflation queue. Note that listeners must be thread safe if used in a multi-consumer
environment; best practice is to use separate listener instances for each consumer thread e.g. by using
threadLocal(Supplier) or threadLocalSupplier(Supplier).| Modifier and Type | Field and Description |
|---|---|
static PollerListener<java.lang.Object,java.lang.Object> |
NOOP
Constant for a no-op listener.
|
| Modifier and Type | Method and Description |
|---|---|
void |
polled(ConflationQueue<? extends K,? extends V> queue,
K key,
V value)
Called whenever a value is polled via any of the
poll methods. |
default void |
polledButFoundEmpty(ConflationQueue<? extends K,? extends V> queue)
Called whenever a poll attempt was made but the queue was found empty.
|
static <K,V> PollerListener<K,V> |
threadLocal(java.util.function.Supplier<? extends PollerListener<K,V>> listenerSupplier)
Creates a poller listener that delegates to thread-local listener instances created on demand by the given
supplier.
|
static <L extends PollerListener<?,?>> |
threadLocalSupplier(java.util.function.Supplier<L> listenerSupplier)
Creates a thread local supplier that creates a new instance once for every caller thread.
|
static final PollerListener<java.lang.Object,java.lang.Object> NOOP
void polled(ConflationQueue<? extends K,? extends V> queue, K key, V value)
poll methods. By default
this method is also invoked when the queue was found empty (with null key and value) unless
polledButFoundEmpty(ConflationQueue) is overridden and implemented differently.queue - the conflation queue, sometimes useful to record queue size metrics, never nullkey - the conflation key, may be null for poll invocations of the empty queuevalue - the value that was polled, or null for unsuccessful poll invocations (i.e. when the queue was found
empty)default void polledButFoundEmpty(ConflationQueue<? extends K,? extends V> queue)
polled(ConflationQueue, Object, Object) passing nulls for key and value.queue - the conflation queue, sometimes useful to record queue size metrics, never nullstatic <K,V> PollerListener<K,V> threadLocal(java.util.function.Supplier<? extends PollerListener<K,V>> listenerSupplier)
AtomicConflationQueue which use a single
poller instance for all consumer threads.K - the type of the conflation keyV - the type of values in the queuelistenerSupplier - the supplier acting as factory for per-thread listener instancesstatic <L extends PollerListener<?,?>> java.util.function.Supplier<L> threadLocalSupplier(java.util.function.Supplier<L> listenerSupplier)
EvictConflationQueue and MergeConflationQueue which use a per
thread poller instances; the returned supplier will create a new thread-local listener instance for every
poller instance that is created.L - the poller listener (sub-)typelistenerSupplier - the supplier acting as factory for per-thread listener instances