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 . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
fail(RuntimeException e) |
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) |
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, wait
asStream, hasNextAvailable
public 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 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 Optional<TrackedEventMessage<?>> peek()
BlockingStream
peek
in interface BlockingStream<TrackedEventMessage<?>>
public boolean hasNextAvailable(int timeout, TimeUnit timeUnit) throws InterruptedException
BlockingStream
true
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()
BlockingStream
BlockingStream.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 AutoCloseable
close
in interface BlockingStream<TrackedEventMessage<?>>
public boolean push(EventWithToken event)
public void fail(RuntimeException e)
Copyright © 2010–2018. All rights reserved.