Class ChannelSend<T>

  • All Implemented Interfaces:
    de.esoco.lib.property.Fluent<CoroutineStep<T,​T>>, org.obrel.core.FluentRelatable<CoroutineStep<T,​T>>, org.obrel.core.Relatable

    public class ChannelSend<T>
    extends ChannelStep<T,​T>
    A coroutine step that sends a value into a channel. If the channel capacity has been reached at the time of this step's invocation the coroutine execution will be suspended until channel capacity becomes available. The channel to send to will be queried (and if not existing created) by calling CoroutineScope.getChannel(ChannelId).

    A send step returns the input value it sends so that it ca be processed further in subsequent steps if needed.

    • Constructor Summary

      Constructors 
      Constructor Description
      ChannelSend​(java.util.function.Function<Continuation<?>,​ChannelId<T>> fGetChannelId)
      Creates a new instance that sends to a channel the ID of which is provided in a state relation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected T execute​(T input, Continuation<?> continuation)
      This method must be implemented by subclasses to provide the actual functionality of this step.
      void runAsync​(java.util.concurrent.CompletableFuture<T> previousExecution, CoroutineStep<T,​?> nextStep, Continuation<?> continuation)
      Runs this execution step asynchronously as a continuation of a previous code execution in a CompletableFuture and proceeds to the next step afterwards.
      static <T> ChannelSend<T> send​(ChannelId<T> rId)
      Suspends until a value can be sent to a certain channel.
      static <T> ChannelSend<T> send​(java.util.function.Function<Continuation<?>,​ChannelId<T>> fGetChannelId)
      Suspends until a value can be sent to the channel with the ID provided by the given function.
      • Methods inherited from class org.obrel.core.RelatedObject

        deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface de.esoco.lib.property.Fluent

        _with
      • Methods inherited from interface org.obrel.core.FluentRelatable

        with, with, with
      • Methods inherited from interface org.obrel.core.Relatable

        deleteRelation, deleteRelation, deleteRelations, get, getAll, getOption, getRelation, getRelationCount, getRelations, getRelations, hasFlag, hasRelation, hasRelations, init, set, set, set, set, set, setOption, streamRelations, transform
    • Constructor Detail

      • ChannelSend

        public ChannelSend​(java.util.function.Function<Continuation<?>,​ChannelId<T>> fGetChannelId)
        Creates a new instance that sends to a channel the ID of which is provided in a state relation.
        Parameters:
        fGetChannelId - The function that will return the channel ID
    • Method Detail

      • send

        public static <T> ChannelSend<T> send​(ChannelId<T> rId)
        Suspends until a value can be sent to a certain channel.
        Parameters:
        rId - The ID of the channel to send to
        Returns:
        A new step instance
      • send

        public static <T> ChannelSend<T> send​(java.util.function.Function<Continuation<?>,​ChannelId<T>> fGetChannelId)
        Suspends until a value can be sent to the channel with the ID provided by the given function.
        Parameters:
        fGetChannelId - The function that will return the channel ID
        Returns:
        A new step instance
      • runAsync

        public void runAsync​(java.util.concurrent.CompletableFuture<T> previousExecution,
                             CoroutineStep<T,​?> nextStep,
                             Continuation<?> continuation)
        Runs this execution step asynchronously as a continuation of a previous code execution in a CompletableFuture and proceeds to the next step afterwards.

        Subclasses that need to suspend the invocation of the next step until some condition is met (e.g. sending or receiving data has finished) need to override this method and create a Suspension by invoking Continuation.suspend(CoroutineStep, CoroutineStep) on the next step. If the condition that caused the suspension resolves the coroutine execution can be resumed by calling Suspension.resume(Object).

        Subclasses that override this method also need to handle errors by terminating any further execution (i.e. not resuming a suspension if such exists) and forwarding the causing exception to Continuation.fail(Throwable).

        Overrides:
        runAsync in class CoroutineStep<T,​T>
        Parameters:
        previousExecution - The future of the previous code execution
        nextStep - The next step to execute or NULL for none
        continuation - The continuation of the execution
      • execute

        protected T execute​(T input,
                            Continuation<?> continuation)
        This method must be implemented by subclasses to provide the actual functionality of this step.
        Specified by:
        execute in class CoroutineStep<T,​T>
        Parameters:
        input - The input value
        continuation - The continuation of the execution
        Returns:
        The result of the execution