Package io.activej.csp.process
Class AbstractCommunicatingProcess
java.lang.Object
io.activej.csp.process.AbstractCommunicatingProcess
- All Implemented Interfaces:
io.activej.async.process.AsyncCloseable,io.activej.async.process.AsyncProcess
- Direct Known Subclasses:
AbstractChannelTransformer,ChannelFrameDecoder,ChannelFrameEncoder,ChannelSplitter
public abstract class AbstractCommunicatingProcess
extends Object
implements io.activej.async.process.AsyncProcess
An abstract AsyncProcess which describes interactions
between ChannelSupplier and ChannelConsumer. A universal
class which can be set up for various behaviours. May contain
an input (
ChannelSupplier) and output (ChannelConsumer).
After process completes, a Promise of null is returned.
New process can't be started before the previous one ends.
Process can be cancelled or closed manually.
-
Field Summary
Fields inherited from interface io.activej.async.process.AsyncCloseable
STATIC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterProcess(@Nullable Exception e) protected voidfinal voidclose()Closes this process withAsyncCloseExceptionfinal voidCloses this process if it is not completed yet.protected final voidprotected final voidcompleteProcessEx(@Nullable Exception e) protected abstract voidAn operation which is executed in case of manual closing.protected abstract voidDescribes the main operations of the communicating process.protected final <T> io.activej.promise.Promise<T>doSanitize(T value, @Nullable Exception e) Closes this process and returns a promise ofeexception if providedeis notnull.final @NotNull io.activej.promise.Promise<Void>final booleanfinal booleanprotected final BinaryChannelSuppliersanitize(BinaryChannelSupplier supplier) protected final <T> ChannelConsumer<T>sanitize(ChannelConsumer<T> consumer) protected final <T> ChannelSupplier<T>sanitize(ChannelSupplier<T> supplier) protected final <T> io.activej.promise.Promise<T>sanitize(io.activej.promise.Promise<T> promise) final @NotNull io.activej.promise.Promise<Void>Starts this communicating process if it is not started yet.
-
Constructor Details
-
AbstractCommunicatingProcess
public AbstractCommunicatingProcess()
-
-
Method Details
-
beforeProcess
protected void beforeProcess() -
afterProcess
-
isProcessStarted
public final boolean isProcessStarted() -
isProcessComplete
public final boolean isProcessComplete() -
completeProcess
protected final void completeProcess() -
completeProcessEx
-
getProcessCompletion
- Specified by:
getProcessCompletionin interfaceio.activej.async.process.AsyncProcess
-
startProcess
Starts this communicating process if it is not started yet. Consistently executesbeforeProcess()anddoProcess().- Specified by:
startProcessin interfaceio.activej.async.process.AsyncProcess- Returns:
promisewith null result as the marker of completion of the process
-
doProcess
protected abstract void doProcess()Describes the main operations of the communicating process. May include interaction between input (ChannelSupplier) and output (ChannelConsumer). -
closeEx
Closes this process if it is not completed yet. ExecutesdoClose(Exception)andafterProcess(Exception).- Specified by:
closeExin interfaceio.activej.async.process.AsyncCloseable- Parameters:
e- exception that is used to close process with
-
doClose
An operation which is executed in case of manual closing.- Parameters:
e- an exception thrown on closing
-
close
public final void close()Closes this process withAsyncCloseException- Specified by:
closein interfaceio.activej.async.process.AsyncCloseable
-
sanitize
-
sanitize
-
sanitize
-
sanitize
protected final <T> io.activej.promise.Promise<T> sanitize(io.activej.promise.Promise<T> promise) -
doSanitize
protected final <T> io.activej.promise.Promise<T> doSanitize(T value, @Nullable @Nullable Exception e) Closes this process and returns a promise ofeexception if providedeis notnull. Otherwise, returns a promise ofvalue. If the process was already completed, returns a promise ofProcessCompleteExceptionand recycles the providedvalue.- Returns:
- a promise of
valueifeisnullandpromiseofeexception otherwise. If the process was already completed, returnsProcessCompleteException.
-