java.lang.Object
org.axonframework.axonserver.connector.event.axon.EventBuffer
All Implemented Interfaces:
AutoCloseable, BlockingStream<TrackedEventMessage<?>>, TrackingEventStream

public class EventBuffer extends Object implements TrackingEventStream
Client-side buffer of messages received from the server. Once consumed from this buffer, the client is notified of a permit being consumed, potentially triggering a permit refresh, if flow control is enabled.

This class is intended for internal use. Be cautious.

Since:
4.0
Author:
Marc Gathier, Allard Buijze
  • Constructor Details

    • EventBuffer

      public EventBuffer(io.axoniq.axonserver.connector.event.EventStream delegate, EventUpcaster upcasterChain, Serializer serializer, boolean disableIgnoredEventFiltering)
      Initializes an Event Buffer, passing messages through given upcasterChain and deserializing events using given serializer.
      Parameters:
      delegate - the EventStream to delegate operations to
      upcasterChain - the upcasterChain to translate serialized representations before deserializing
      serializer - the serializer capable of deserializing incoming messages
      disableIgnoredEventFiltering - specifying whether events should or should not be included in the buffer
  • Method Details

    • skipMessagesWithPayloadTypeOf

      public void skipMessagesWithPayloadTypeOf(TrackedEventMessage<?> ignoredMessage)
      Report the stream that a specific message was ignored by the consumer. Stream implementation can use this information for instance to filter messages with the same type of payload.

      This implementation removes events from the stream based on the payload type of the given message.

      Specified by:
      skipMessagesWithPayloadTypeOf in interface BlockingStream<TrackedEventMessage<?>>
      Parameters:
      ignoredMessage - the message containing the payload to exclude from the stream
    • peek

      public Optional<TrackedEventMessage<?>> peek()
      Description copied from interface: BlockingStream
      Checks whether or not the next message in the stream is immediately available. If so, an Optional with the next message is returned (without moving the stream pointer), otherwise an empty Optional is returned.
      Specified by:
      peek in interface BlockingStream<TrackedEventMessage<?>>
      Returns:
      the next event if immediately available
    • hasNextAvailable

      public boolean hasNextAvailable(int timeout, TimeUnit timeUnit) throws InterruptedException
      Description copied from interface: BlockingStream
      Checks whether or not the next message in the stream is available. If a message is available when this method is invoked this method returns immediately. If not, this method will block until a message becomes available, returning true or until the given timeout expires, returning false.

      To check if the stream has messages available now, pass a zero timeout.

      Specified by:
      hasNextAvailable in interface BlockingStream<TrackedEventMessage<?>>
      Parameters:
      timeout - the maximum number of time units to wait for messages to become available
      timeUnit - the time unit for the timeout
      Returns:
      true if a message is available or becomes available before the given timeout, false otherwise
      Throws:
      InterruptedException - when the thread is interrupted before the indicated time is up
    • nextAvailable

      public TrackedEventMessage<?> nextAvailable() throws InterruptedException
      Description copied from interface: BlockingStream
      Returns the next available message in the stream. Note that this method blocks for as long as there are no available messages in the stream. In case this blocking behavior is not desired use BlockingStream.hasNextAvailable() with or without a timeout to check if the stream has available messages before calling this method.
      Specified by:
      nextAvailable in interface BlockingStream<TrackedEventMessage<?>>
      Returns:
      the next available message
      Throws:
      InterruptedException - when the thread is interrupted before the next message is returned
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface BlockingStream<TrackedEventMessage<?>>
    • setOnAvailableCallback

      public boolean setOnAvailableCallback(Runnable callback)
      Description copied from interface: BlockingStream
      Set a callback to be invoked once new messages are available on this stream. Returns true if this functionality is supported and false otherwise. When true is returned, the callee can expect the callback to be invoked immediately.

      Note that returning false does not define the given callback is never invoked. If the callee needs to be certain the callback is never invoked in case of false, a no-op Runnable should be provided.

      Specified by:
      setOnAvailableCallback in interface BlockingStream<TrackedEventMessage<?>>
      Parameters:
      callback - a Runnable
      Returns:
      true if on available callback is supported and can thus be waited on, false otherwise