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.

  • Constructor Details

    • AbstractCommunicatingProcess

      public AbstractCommunicatingProcess()
  • Method Details

    • beforeProcess

      protected void beforeProcess()
    • afterProcess

      protected void afterProcess(@Nullable @Nullable Exception e)
    • isProcessStarted

      public final boolean isProcessStarted()
    • isProcessComplete

      public final boolean isProcessComplete()
    • completeProcess

      protected final void completeProcess()
    • completeProcessEx

      protected final void completeProcessEx(@Nullable @Nullable Exception e)
    • getProcessCompletion

      @NotNull public final @NotNull io.activej.promise.Promise<Void> getProcessCompletion()
      Specified by:
      getProcessCompletion in interface io.activej.async.process.AsyncProcess
    • startProcess

      @NotNull public final @NotNull io.activej.promise.Promise<Void> startProcess()
      Starts this communicating process if it is not started yet. Consistently executes beforeProcess() and doProcess().
      Specified by:
      startProcess in interface io.activej.async.process.AsyncProcess
      Returns:
      promise with 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

      public final void closeEx(@NotNull @NotNull Exception e)
      Closes this process if it is not completed yet. Executes doClose(Exception) and afterProcess(Exception).
      Specified by:
      closeEx in interface io.activej.async.process.AsyncCloseable
      Parameters:
      e - exception that is used to close process with
    • doClose

      protected abstract void doClose(Exception e)
      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 with AsyncCloseException
      Specified by:
      close in interface io.activej.async.process.AsyncCloseable
    • sanitize

      protected final <T> ChannelSupplier<T> sanitize(ChannelSupplier<T> supplier)
    • sanitize

      protected final <T> ChannelConsumer<T> sanitize(ChannelConsumer<T> consumer)
    • sanitize

      protected final BinaryChannelSupplier 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 of e exception if provided e is not null. Otherwise, returns a promise of value. If the process was already completed, returns a promise of ProcessCompleteException and recycles the provided value.
      Returns:
      a promise of value if e is null and promise of e exception otherwise. If the process was already completed, returns ProcessCompleteException.