Class AbstractMessageStream<M extends Message>

java.lang.Object
org.axonframework.messaging.core.AbstractMessageStream<M>
Type Parameters:
M - The type of Message contained in the entries of this stream.
All Implemented Interfaces:
MessageStream<M>
Direct Known Subclasses:
QueueMessageStream

@Internal public abstract class AbstractMessageStream<M extends Message> extends Object implements MessageStream<M>
Abstract implementation of MessageStream that provides basic state management for completion, errors, and callbacks.
Since:
5.1.0
Author:
Jan Galinski
  • Constructor Details

    • AbstractMessageStream

      public AbstractMessageStream()
  • Method Details

    • setCallback

      public void setCallback(Runnable callback)
      Description copied from interface: MessageStream
      Registers the callback to invoke when entries are available for reading or when the stream completes (either normally or with an error). An invocation of the callback does not in any way guarantee that entries are indeed available, or that the stream has indeed been completed. Implementations may choose to suppress repeated invocations of the callback if no entries have been read in the meantime.

      Any previously registered callback is replaced with the given callback.

      The callback is called on an arbitrary thread, and it should keep work performed on this thread to a minimum as this may interfere with other callbacks handled by the same thread. Any exception thrown by the callback will result in the stream completing with this exception as the error.

      Specified by:
      setCallback in interface MessageStream<M extends Message>
      Parameters:
      callback - The callback to invoke when entries are available for reading, or the stream completes.
    • invokeCallbackSafely

      protected void invokeCallbackSafely()
      Invokes the registered callback safely, catching any exceptions and completing the stream with that exception.
    • complete

      protected void complete()
      Completes the stream normally.
    • completeExceptionally

      protected void completeExceptionally(Throwable throwable)
      Completes the stream with the given throwable.
      Parameters:
      throwable - The error that caused the stream to complete.
    • error

      public Optional<Throwable> error()
      Description copied from interface: MessageStream
      Indicates whether any error has been reported in this stream. Implementations may choose to not return any error here until all entries that were available for reading before any error occurred have been consumed.
      Specified by:
      error in interface MessageStream<M extends Message>
      Returns:
      An optional containing the possible error this stream completed with.
    • isCompleted

      public boolean isCompleted()
      Description copied from interface: MessageStream
      Indicates whether this stream has been completed. A completed stream will never return entries from MessageStream.next(), and MessageStream.hasNextAvailable() will always return false. If the stream completed with an error, MessageStream.error() will report so.
      Specified by:
      isCompleted in interface MessageStream<M extends Message>
      Returns:
      true if the stream completed, otherwise false.