Class AsyncStream<S extends AutoCloseable>

java.lang.Object
org.rostore.v2.container.async.AsyncStream<S>
Type Parameters:
S - the stream that this object is wrapped around.
All Implemented Interfaces:
AutoCloseable, Future<S>

public class AsyncStream<S extends AutoCloseable> extends Object implements AutoCloseable, Future<S>
This class is a wrapper around the stream (input or output).

It is handy to observe and steer the long-running operation of network stream processing.

It has a status model, reflected in AsyncStatus, as well as a set of listeners that will be notified on different events around the stream processing: status transition and Record updates during processing of the stream.

The client can wait of the blocking variant of this stream (e.g. wrapBlocking(AutoCloseable)).

The stream processing can also be canceled (see cancel(boolean)).

  • Method Details

    • wrap

      public static <S extends AutoCloseable> AsyncStream<S> wrap(S s)
    • wrap

      public static <S extends AutoCloseable> AsyncStream<S> wrap(S s, AsyncListener asyncListener)
    • wrapBlocking

      public static <S extends AutoCloseable> AsyncStream<S> wrapBlocking(S s)
    • wrapBlocking

      public static <S extends AutoCloseable> AsyncStream<S> wrapBlocking(S s, AsyncListener asyncListener)
    • getException

      public Exception getException()
    • notifyRecord

      public void notifyRecord(Record record)
    • processFunction

      public final void processFunction(AsyncFunction<S> runnable)
      This function is called from the async process to process the entity. This function will safely mark the async process as done and can only be executed once.
      Parameters:
      runnable - the callback the async process implements
      Throws:
      StreamProcessingException - wraps any exception can happen in the processing
    • fail

      public void fail(Exception e)
      Called by the internal processing logic in case any error occurs during processing
      Parameters:
      e - the exception experienced
    • cancel

      public boolean cancel(boolean b)
      Cancels the processing of the stream.
      Specified by:
      cancel in interface Future<S extends AutoCloseable>
      Parameters:
      b - true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
      Returns:
      always true
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface Future<S extends AutoCloseable>
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface Future<S extends AutoCloseable>
    • get

      public S get(long l, TimeUnit timeUnit)
      Specified by:
      get in interface Future<S extends AutoCloseable>
    • get

      public S get()
      This one will only work if the object is created as blocking
      Specified by:
      get in interface Future<S extends AutoCloseable>
      Returns:
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • empty

      public void empty()