public class EventBuffer extends Object implements TrackingEventStream
This class is intended for internal use. Be cautious.
| Constructor and Description |
|---|
EventBuffer(EventUpcaster upcasterChain,
Serializer serializer)
Initializes an Event Buffer, passing messages through given
upcasterChain and deserializing events using
given serializer. |
EventBuffer(EventUpcaster upcasterChain,
Serializer serializer,
long pollingTimeMillis)
Initializes an Event Buffer, passing messages through given
upcasterChain and deserializing events using
given serializer. |
| Modifier and Type | Method and Description |
|---|---|
void |
blacklist(TrackedEventMessage<?> trackedEventMessage)
Report the stream that a specific message was ignored by the consumer.
|
void |
close() |
void |
fail(RuntimeException e)
Fail
this EventBuffer with the given RuntimeException. |
boolean |
hasNextAvailable(int timeout,
TimeUnit timeUnit)
Checks whether or not the next message in the stream is available.
|
TrackedEventMessage<?> |
nextAvailable()
Returns the next available message in the stream.
|
Optional<TrackedEventMessage<?>> |
peek()
Checks whether or not the next message in the stream is immediately available.
|
boolean |
push(EventWithToken event)
Push a new
event on to this EventBuffer instance. |
void |
registerBlacklistListener(Consumer<SerializedType> blacklistListener)
Registers the callback to invoke when a the event processor determines that a type should be blacklisted.
|
void |
registerCloseListener(Consumer<EventBuffer> closeCallback)
Registers the callback to invoke when the reader wishes to close the stream.
|
void |
registerConsumeListener(Consumer<Integer> consumeListener)
Registers the callback to invoke when a raw input message was consumed from the buffer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasStream, hasNextAvailablepublic EventBuffer(EventUpcaster upcasterChain, Serializer serializer)
upcasterChain and deserializing events using
given serializer.upcasterChain - the upcasterChain to translate serialized representations before deserializingserializer - the serializer capable of deserializing incoming messagespublic EventBuffer(EventUpcaster upcasterChain, Serializer serializer, long pollingTimeMillis)
upcasterChain and deserializing events using
given serializer.upcasterChain - the upcasterChain to translate serialized representations before deserializingserializer - the serializer capable of deserializing incoming messagespollingTimeMillis - a long defining the polling periods used to split the up the timeout used in
hasNextAvailable(int, TimeUnit), ensuring nobody accidentally blocks for an
extended period of time. Defaults to 500 millisecondspublic void blacklist(TrackedEventMessage<?> trackedEventMessage)
This implementation blacklists based on the payload type of the given message.
blacklist in interface BlockingStream<TrackedEventMessage<?>>trackedEventMessage - the message containing the payload to blacklistpublic void registerCloseListener(Consumer<EventBuffer> closeCallback)
closeCallback - The callback to invoke when the reader wishes to close the streampublic void registerConsumeListener(Consumer<Integer> consumeListener)
consumeListener - the callback to invoke when a raw input message was consumed from the bufferpublic void registerBlacklistListener(Consumer<SerializedType> blacklistListener)
blacklistListener - the callback to invoke when a payload type is to be blacklisted.public Optional<TrackedEventMessage<?>> peek()
BlockingStreampeek in interface BlockingStream<TrackedEventMessage<?>>public boolean hasNextAvailable(int timeout,
TimeUnit timeUnit)
throws InterruptedException
BlockingStreamtrue or until the given timeout expires, returning
false.
To check if the stream has messages available now, pass a zero timeout.
hasNextAvailable in interface BlockingStream<TrackedEventMessage<?>>timeout - the maximum number of time units to wait for messages to become availabletimeUnit - the time unit for the timeoutInterruptedException - when the thread is interrupted before the indicated time is uppublic TrackedEventMessage<?> nextAvailable()
BlockingStreamBlockingStream.hasNextAvailable()
with or without a timeout to check if the stream has available messages before calling this method.nextAvailable in interface BlockingStream<TrackedEventMessage<?>>public void close()
close in interface AutoCloseableclose in interface BlockingStream<TrackedEventMessage<?>>public boolean push(EventWithToken event)
event on to this EventBuffer instance. Will return false if the given event
could not be added because the buffer is already closed or if the operation was interrupted. If pushing the
event was successful, true will be returned.event - the EventWithToken to be pushed on to this EventBuffertrue if adding the event to the buffer was successful and false if it wasn'tpublic void fail(RuntimeException e)
this EventBuffer with the given RuntimeException.e - a RuntimeException with which this EventBuffer failedCopyright © 2010–2020. All rights reserved.