Class AbstractQueryResponseMessageStream<T>

java.lang.Object
org.axonframework.axonserver.connector.query.AbstractQueryResponseMessageStream<T>
Type Parameters:
T - The type of the objects in the underlying ResultStream to be transformed into QueryResponseMessages.
All Implemented Interfaces:
MessageStream<QueryResponseMessage>
Direct Known Subclasses:
QueryResponseMessageStream, QueryUpdateMessageStream

@Internal public abstract class AbstractQueryResponseMessageStream<T> extends Object implements MessageStream<QueryResponseMessage>
An abstract implementation of the MessageStream interface that wraps a ResultStream. This class provides functionality for transforming the data in the ResultStream into QueryResponseMessages, handling any encountered errors, and managing stream lifecycle events.
  • Constructor Details

    • AbstractQueryResponseMessageStream

      public AbstractQueryResponseMessageStream(@Nonnull io.axoniq.axonserver.connector.ResultStream<T> stream)
      Constructs an instance of the AbstractQueryResponseMessageStream class with the provided result stream.
      Parameters:
      stream - The ResultStream instance from which query response data will be fetched. Must not be null.
  • Method Details

    • next

      Description copied from interface: MessageStream
      Returns an Optional carrying the next entry from the stream, if such entry was available. If no entry was available for reading, this method returns an empty Optional.

      This method will never block for elements becoming available.

      Specified by:
      next in interface MessageStream<T>
      Returns:
      An optional carrying the next entry, if available.
    • peek

      Description copied from interface: MessageStream
      Returns an Optional carrying the next entry from the stream (without moving the stream pointer), if such entry was available. If no entry was available for reading, this method returns an empty Optional.

      This method will never block for elements becoming available.

      Specified by:
      peek in interface MessageStream<T>
      Returns:
      An optional carrying the next entry, if available.
    • setCallback

      public void setCallback(@Nonnull 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<T>
      Parameters:
      callback - The callback to invoke when entries are available for reading, or the stream completes.
    • error

      @Nonnull 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<T>
      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<T>
      Returns:
      true if the stream completed, otherwise false.
    • hasNextAvailable

      public boolean hasNextAvailable()
      Description copied from interface: MessageStream
      Indicates whether an entry is available for immediate reading. When entries are reported available, there is no guarantee that MessageStream.next() will indeed return an entry. However, besides any concurrent activity on this stream, it is guaranteed that no entries are available for reading when this method returns false.
      Specified by:
      hasNextAvailable in interface MessageStream<T>
      Returns:
      true when there are entries available for reading, false otherwise.
    • close

      public void close()
      Description copied from interface: MessageStream
      Closes this stream, freeing any possible resources occupied by the underlying stream. After invocation, some entries may still be available for reading.

      Implementations must always release resources when a stream is completed, either with an error or normally. Therefore, it is only required to close() a stream if the consumer decides to not read until the end.

      Specified by:
      close in interface MessageStream<T>
    • buildResponseMessage

      @Nonnull protected abstract QueryResponseMessage buildResponseMessage(@Nonnull T t)
    • createAxonException

      @Nonnull protected abstract AxonException createAxonException(@Nonnull T t)
    • isError

      protected abstract boolean isError(@Nonnull T t)