public class DelegatingConsumer<T> extends java.lang.Object implements BatchConsumer<T>, java.lang.Iterable<Consumer<T>>
Consumer that maintains a list of delegates to which events received by this Consumer will be passed along.
NOTE: Access to the list of delegates is synchronized to make it thread-safe, so using this implementation of
Consumer will incur an overall performance hit on throughput. Also, references to the Consumers are weak. It's not possible to remove a Consumer without a reference to it, so the DelegatingConsumer assumes references to Consumers added here have other components with strong
references to them somewhere else.| Constructor and Description |
|---|
DelegatingConsumer() |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(T t)
Execute the logic of the action, accepting the given parameter.
|
DelegatingConsumer<T> |
add(java.util.Collection<Consumer<T>> consumers)
Add the given
Consumers to the list of delegates. |
DelegatingConsumer<T> |
add(Consumer<T> consumer)
Add the given
Consumer to the list of delegates. |
DelegatingConsumer<T> |
clear()
Clear all delegate
Consumers from the list. |
void |
end()
Called when a batch ends.
|
java.util.Iterator<Consumer<T>> |
iterator() |
DelegatingConsumer<T> |
prune()
Remove the references to
Consumers that have been removed or have gone out of scope and prune the
size of the list. |
DelegatingConsumer<T> |
remove(java.util.Collection<Consumer<T>> consumers)
Remove the given
Consumers from the list of delegates. |
DelegatingConsumer<T> |
remove(Consumer<T> consumer)
Remove the given
Consumer from the list of delegates. |
void |
start()
Called when a batch begins.
|
public DelegatingConsumer<T> add(Consumer<T> consumer)
Consumer to the list of delegates.consumer - the Consumer to addpublic DelegatingConsumer<T> add(java.util.Collection<Consumer<T>> consumers)
Consumers to the list of delegates.consumers - the Consumers to addpublic DelegatingConsumer<T> remove(Consumer<T> consumer)
Consumer from the list of delegates.consumer - public DelegatingConsumer<T> remove(java.util.Collection<Consumer<T>> consumers)
Consumers from the list of delegates.consumers - the Consumers to removepublic DelegatingConsumer<T> prune()
Consumers that have been removed or have gone out of scope and prune the
size of the list. If many Consumers are removed individually, it will increase overall throughput
to call this method periodically. To maintain as high a throughput as possible, though, its not necessary to call
this every time a Consumer is removed.public DelegatingConsumer<T> clear()
Consumers from the list.public void accept(T t)
Consumerpublic void start()
BatchConsumerstart in interface BatchConsumer<T>public void end()
BatchConsumerend in interface BatchConsumer<T>