Package io.activej.csp.process
Class AbstractCommunicatingProcess
java.lang.Object
io.activej.reactor.AbstractReactive
io.activej.reactor.ImplicitlyReactive
io.activej.csp.process.AbstractCommunicatingProcess
- All Implemented Interfaces:
io.activej.async.process.AsyncCloseable,io.activej.async.process.ReactiveProcess,io.activej.reactor.Reactive
- Direct Known Subclasses:
AbstractChannelTransformer,ChannelFrameDecoder,ChannelFrameEncoder,ChannelSplitter
public abstract class AbstractCommunicatingProcess
extends io.activej.reactor.ImplicitlyReactive
implements io.activej.async.process.ReactiveProcess
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected final class -
Field Summary
Fields inherited from class io.activej.reactor.AbstractReactive
reactorFields 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 io.activej.promise.Promise<Void>final booleanfinal booleanprotected final AbstractCommunicatingProcess.SanitizedBinaryChannelSuppliersanitize(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 io.activej.promise.Promise<Void>Starts this communicating process if it is not started yet.Methods inherited from class io.activej.reactor.AbstractReactive
getReactorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.activej.reactor.Reactive
getReactor
-
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.ReactiveProcess
-
startProcess
Starts this communicating process if it is not started yet. Consistently executesbeforeProcess()anddoProcess().- Specified by:
startProcessin interfaceio.activej.async.process.ReactiveProcess- 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
protected final AbstractCommunicatingProcess.SanitizedBinaryChannelSupplier sanitize(BinaryChannelSupplier supplier) -
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.
-