Package org.rostore.v2.container.async
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)).
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean b) Cancels the processing of the stream.voidclose()voidempty()voidCalled by the internal processing logic in case any error occurs during processingget()This one will only work if the object is created as blockingbooleanbooleanisDone()voidnotifyRecord(Record record) final voidprocessFunction(AsyncFunction<S> runnable) This function is called from the async process to process the entity.static <S extends AutoCloseable>
AsyncStream<S> wrap(S s) static <S extends AutoCloseable>
AsyncStream<S> wrap(S s, AsyncListener asyncListener) static <S extends AutoCloseable>
AsyncStream<S> wrapBlocking(S s) static <S extends AutoCloseable>
AsyncStream<S> wrapBlocking(S s, AsyncListener asyncListener) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.concurrent.Future
exceptionNow, resultNow, state
-
Method Details
-
wrap
-
wrap
-
wrapBlocking
-
wrapBlocking
public static <S extends AutoCloseable> AsyncStream<S> wrapBlocking(S s, AsyncListener asyncListener) -
getException
-
notifyRecord
-
processFunction
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
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:
cancelin interfaceFuture<S extends AutoCloseable>- Parameters:
b-trueif 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:
isCancelledin interfaceFuture<S extends AutoCloseable>
-
isDone
public boolean isDone()- Specified by:
isDonein interfaceFuture<S extends AutoCloseable>
-
get
- Specified by:
getin interfaceFuture<S extends AutoCloseable>
-
get
This one will only work if the object is created as blocking- Specified by:
getin interfaceFuture<S extends AutoCloseable>- Returns:
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
empty
public void empty()
-