Class Channel<T>

Type Parameters:
T - the Java message type carried by the Channel

public final class Channel<T> extends PersistenceDefinition
Defines one durable, typed message Channel for a Flow.

Register the Channel in the Flow's PersistenceSchema. Clients, Steps, and RPCs may publish messages, while Step wait methods create conditions describing how many messages must be available. Condition results are consumed from the current invocation context.

private final Channel<String> approvals = Channel.define("approvals", String.class);

public Wait waitFor(Context context, Order input) {
    return Wait.until(approvals.forOne("approval"));
}

public StepDecision execute(Context context, Order input) {
    String approver = approvals.getConditionResults(context).get(0);
    return StepDecision.gracefulComplete(approver);
}
  • Method Details

    • define

      public static <T> Channel<T> define(String name, Class<T> valueType)
      Defines a typed Channel.
      Type Parameters:
      T - the Java message type
      Parameters:
      name - the stable Channel name; must not be blank or contain /
      valueType - the concrete Java class used to serialize messages
      Returns:
      the typed Channel definition
      Throws:
      IllegalArgumentException - if name is null, blank, or contains /
      NullPointerException - if valueType is null
    • publish

      public void publish(Context context, T value)
      Publishes one message from the current invocation.
      Parameters:
      context - the Step or RPC invocation context
      value - the typed message to publish
    • delete

      public void delete(Context context, String messageId)
      Stages deletion of one pending message from a Step, timeout handler, or RPC.

      Step and timeout-handler deletions are best-effort when the message is already absent.

      Parameters:
      context - the handler invocation context
      messageId - the nonblank server-assigned message ID
    • size

      public int size(Context context)
      Returns the number of messages currently visible to this invocation.
      Parameters:
      context - the Step or RPC invocation context
      Returns:
      the visible message count
    • pendingMessages

      public List<ChannelMessage<T>> pendingMessages(Context context)
      Returns this Channel's loaded pending-message snapshot in FIFO order.

      Select this Channel in the handler's options. The snapshot does not change after staged publications or deletions in the same handler.

      Parameters:
      context - the handler invocation context
      Returns:
      immutable pending message IDs and decoded values
      Throws:
      ChannelMessagesNotLoadedException - if the invocation did not load its messages
    • findPendingMessage

      public ChannelMessage<T> findPendingMessage(Context context, String messageId)
      Finds one pending message in the loaded handler snapshot.
      Parameters:
      context - the handler invocation context
      messageId - the server-assigned message ID
      Returns:
      the matching message, or null when it is absent from the snapshot
      Throws:
      ChannelMessagesNotLoadedException - if the invocation did not load its messages
    • getConditionResults

      public List<T> getConditionResults(Context context)
      Returns messages consumed by this Channel's satisfied condition.
      Parameters:
      context - the Step invocation context
      Returns:
      the typed condition results in server-provided order
    • forOne

      public Condition forOne()
      Creates a condition requiring exactly one message.
      Returns:
      the Channel condition
    • forOne

      public Condition forOne(String conditionId)
      Creates a named condition requiring exactly one message.
      Parameters:
      conditionId - the condition ID used to identify its result
      Returns:
      the Channel condition
    • forN

      public Condition forN(int count)
      Creates a condition requiring exactly count messages.
      Parameters:
      count - the required message count
      Returns:
      the Channel condition
    • forN

      public Condition forN(int count, String conditionId)
      Creates a named condition requiring exactly count messages.
      Parameters:
      count - the required message count
      conditionId - the condition ID used to identify its results
      Returns:
      the Channel condition
    • atLeast

      public Condition atLeast(int count)
      Creates a condition requiring at least count messages.
      Parameters:
      count - the minimum message count
      Returns:
      the Channel condition
    • atLeast

      public Condition atLeast(int count, String conditionId)
      Creates a named condition requiring at least count messages.
      Parameters:
      count - the minimum message count
      conditionId - the condition ID used to identify its results
      Returns:
      the Channel condition
    • atMost

      public Condition atMost(int count)
      Creates a non-blocking condition consuming up to count queued messages. When its surrounding Wait completes, it consumes messages queued then. An empty queue yields none.
      Parameters:
      count - the maximum message count
      Returns:
      the Channel condition
    • atMost

      public Condition atMost(int count, String conditionId)
      Creates a named, non-blocking condition consuming up to count queued messages. When its surrounding Wait completes, it consumes messages queued then. An empty queue yields none.
      Parameters:
      count - the maximum message count
      conditionId - the condition ID used to identify its results
      Returns:
      the Channel condition
    • range

      public Condition range(Integer atLeast, Integer atMost)
      Creates a condition with optional minimum and maximum message counts. Dex waits only for the minimum, then consumes currently queued messages up to the maximum. A null minimum makes the condition complete immediately.
      Parameters:
      atLeast - the minimum count, or null for no minimum
      atMost - the maximum count, or null for no maximum
      Returns:
      the Channel condition
      Throws:
      IllegalArgumentException - if both bounds are null
    • range

      public Condition range(Integer atLeast, Integer atMost, String conditionId)
      Creates a named condition with optional minimum and maximum message counts. Dex waits only for the minimum, then consumes currently queued messages up to the maximum. A null minimum makes the condition complete immediately.
      Parameters:
      atLeast - the minimum count, or null for no minimum
      atMost - the maximum count, or null for no maximum
      conditionId - the condition ID used to identify its results
      Returns:
      the Channel condition
      Throws:
      IllegalArgumentException - if both bounds are null