Class Channel<T>
java.lang.Object
io.superdurable.dex.PersistenceDefinition
io.superdurable.dex.Channel<T>
- Type Parameters:
T- the Java message type carried by the Channel
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 Summary
Modifier and TypeMethodDescriptionatLeast(int count) Creates a condition requiring at leastcountmessages.Creates a named condition requiring at leastcountmessages.atMost(int count) Creates a non-blocking condition consuming up tocountqueued messages.Creates a named, non-blocking condition consuming up tocountqueued messages.static <T> Channel<T> Defines a typed Channel.voidStages deletion of one pending message from a Step, timeout handler, or RPC.findPendingMessage(Context context, String messageId) Finds one pending message in the loaded handler snapshot.forN(int count) Creates a condition requiring exactlycountmessages.Creates a named condition requiring exactlycountmessages.forOne()Creates a condition requiring exactly one message.Creates a named condition requiring exactly one message.getConditionResults(Context context) Returns messages consumed by this Channel's satisfied condition.pendingMessages(Context context) Returns this Channel's loaded pending-message snapshot in FIFO order.voidPublishes one message from the current invocation.Creates a condition with optional minimum and maximum message counts.Creates a named condition with optional minimum and maximum message counts.intReturns the number of messages currently visible to this invocation.
-
Method Details
-
define
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- ifnameisnull, blank, or contains/NullPointerException- ifvalueTypeisnull
-
publish
-
delete
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 contextmessageId- the nonblank server-assigned message ID
-
size
Returns the number of messages currently visible to this invocation.- Parameters:
context- the Step or RPC invocation context- Returns:
- the visible message count
-
pendingMessages
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
Finds one pending message in the loaded handler snapshot.- Parameters:
context- the handler invocation contextmessageId- the server-assigned message ID- Returns:
- the matching message, or
nullwhen it is absent from the snapshot - Throws:
ChannelMessagesNotLoadedException- if the invocation did not load its messages
-
getConditionResults
-
forOne
Creates a condition requiring exactly one message.- Returns:
- the Channel condition
-
forOne
-
forN
Creates a condition requiring exactlycountmessages.- Parameters:
count- the required message count- Returns:
- the Channel condition
-
forN
-
atLeast
Creates a condition requiring at leastcountmessages.- Parameters:
count- the minimum message count- Returns:
- the Channel condition
-
atLeast
-
atMost
Creates a non-blocking condition consuming up tocountqueued 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
Creates a named, non-blocking condition consuming up tocountqueued messages. When its surrounding Wait completes, it consumes messages queued then. An empty queue yields none.- Parameters:
count- the maximum message countconditionId- the condition ID used to identify its results- Returns:
- the Channel condition
-
range
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. Anullminimum makes the condition complete immediately.- Parameters:
atLeast- the minimum count, ornullfor no minimumatMost- the maximum count, ornullfor no maximum- Returns:
- the Channel condition
- Throws:
IllegalArgumentException- if both bounds arenull
-
range
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. Anullminimum makes the condition complete immediately.- Parameters:
atLeast- the minimum count, ornullfor no minimumatMost- the maximum count, ornullfor no maximumconditionId- the condition ID used to identify its results- Returns:
- the Channel condition
- Throws:
IllegalArgumentException- if both bounds arenull
-