C
- the type for the context for the messageM
- the type of the message being added to the queuepublic class ContextualMessageQueue<C,M> extends Object
Barrier is re-usable and can be reset to support Keep-Alive
Constructor and Description |
---|
ContextualMessageQueue(java.util.function.BiConsumer<C,M> consumer)
Registers a consumer with this barrier.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addContextualMessage(C ctx,
M msg)
Will either queue up a message or provide it to the consumer depending on if we are in
streaming mode or not.
|
void |
forEach(java.util.function.BiConsumer<C,M> consumer)
Allows a consumer to consume the stream of queued up contextualMessages.
|
void |
forEachMessage(java.util.function.Consumer<M> consumer)
Allows a consumer to consume the stream of queued up messages without their context.
|
boolean |
isStreaming()
Check if the queue is in streaming mode.
|
void |
reset()
Clears all contextualMessages and resets to non-streaming mode.
|
int |
size()
Returns the number of queued contextualMessages.
|
void |
startStreaming()
Initiates streaming mode and streams all queued up contextualMessages to the registered
consumer.
|
public ContextualMessageQueue(java.util.function.BiConsumer<C,M> consumer)
consumer
- a BiConsumer that will be fed each context and message pair once streaming
starts.public boolean addContextualMessage(C ctx, M msg)
ctx
- the context for the message being addedmsg
- the message being added to the queuepublic void reset()
public void forEach(java.util.function.BiConsumer<C,M> consumer)
consumer
- a BiConsumer that will be fed each context and message pair.public void forEachMessage(java.util.function.Consumer<M> consumer)
consumer
- a Consumer that will be fed each message.public void startStreaming()
public int size()
public boolean isStreaming()
Copyright © 2016. All Rights Reserved.