Class ChannelMap<T>
java.lang.Object
io.superdurable.dex.PersistenceDefinition
io.superdurable.dex.ChannelMap<T>
- Type Parameters:
T- the Java message type carried by every Channel instance
Defines a durable map of named, typed Channel instances.
Use a Channel map when the instance key is selected at runtime, such as one Channel per order
or tenant. Register the definition once in the Flow's PersistenceSchema, then pass the
same instance key when publishing, waiting, and reading condition results. Instance keys must
be nonblank and must not contain /.
private final ChannelMap<String> commands =
ChannelMap.define("commands", String.class);
return Wait.until(commands.forOne(orderId, "next-command"));
-
Method Summary
Modifier and TypeMethodDescriptionCreates a condition requiring at leastcountmessages from an instance.Creates a named condition requiring at leastcountmessages from an instance.Creates a non-blocking condition consuming up tocountqueued messages from an instance.Creates a named, non-blocking condition consuming up tocountqueued messages from an instance.static <T> ChannelMap<T> Defines a typed Channel map.voidStages deletion of one pending message from a Channel-map instance.findPendingMessage(Context context, String instance, String messageId) Finds one instance message in the loaded handler snapshot.Creates a condition requiring exactlycountmessages from an instance.Creates a named condition requiring exactlycountmessages from an instance.Creates a condition requiring exactly one message from an instance.Creates a named condition requiring exactly one message from an instance.getAllInstanceKeys(Context context) Returns non-empty instance keys in ascending order for the current RPC.getConditionResults(Context context, String instance) Returns messages consumed by a satisfied condition for one map instance.intgetMapSize(Context context) Returns the number of non-empty instances visible to the current RPC.pendingMessages(Context context, String instance) Returns one instance's loaded pending-message snapshot in FIFO order.voidPublishes one message to a map instance from the current invocation.Creates a condition with optional message-count bounds for one instance.Creates a named condition with optional message-count bounds for one instance.intReturns the number of messages visible in one map instance.
-
Method Details
-
define
Defines a typed Channel map.- Type Parameters:
T- the Java message type- Parameters:
name- the stable Channel-map name; must not be blank or contain/valueType- the concrete Java class used to serialize messages- Returns:
- the typed Channel-map definition
- Throws:
IllegalArgumentException- ifnameisnull, blank, or contains/NullPointerException- ifvalueTypeisnull
-
publish
-
delete
Stages deletion of one pending message from a Channel-map instance.Step and timeout-handler deletions are best-effort when the message is already absent.
- Parameters:
context- the handler invocation contextinstance- the nonblank Channel-map instancemessageId- the nonblank server-assigned message ID
-
size
-
pendingMessages
Returns one instance's loaded pending-message snapshot in FIFO order.Select the instance in the handler's options. The snapshot does not change after staged publications or deletions in the same handler.
- Parameters:
context- the handler invocation contextinstance- the logical ChannelMap instance- Returns:
- immutable pending message IDs and decoded values
- Throws:
ChannelMessagesNotLoadedException- if the invocation did not load its messages
-
findPendingMessage
Finds one instance message in the loaded handler snapshot.- Parameters:
context- the handler invocation contextinstance- the logical ChannelMap instancemessageId- the server-assigned message ID- Returns:
- the matching message, or
nullwhen absent from the snapshot - Throws:
ChannelMessagesNotLoadedException- if the invocation did not load its messages
-
getMapSize
Returns the number of non-empty instances visible to the current RPC.- Parameters:
context- the RPC invocation context- Returns:
- the current number of non-empty instances
-
getAllInstanceKeys
-
getConditionResults
Returns messages consumed by a satisfied condition for one map instance.- Parameters:
context- the Step invocation contextinstance- the Channel-map instance used by the condition- Returns:
- the typed condition results in server-provided order
-
forOne
-
forOne
-
forN
-
forN
Creates a named condition requiring exactlycountmessages from an instance.- Parameters:
instance- the Channel-map instancecount- the required message countconditionId- the condition ID used to identify its results- Returns:
- the Channel condition
-
atLeast
-
atLeast
Creates a named condition requiring at leastcountmessages from an instance.- Parameters:
instance- the Channel-map instancecount- the minimum message countconditionId- the condition ID used to identify its results- Returns:
- the Channel condition
-
atMost
Creates a non-blocking condition consuming up tocountqueued messages from an instance. When its surrounding Wait completes, it consumes messages queued then. An empty queue yields none.- Parameters:
instance- the Channel-map instancecount- the maximum message count- Returns:
- the Channel condition
-
atMost
Creates a named, non-blocking condition consuming up tocountqueued messages from an instance. When its surrounding Wait completes, it consumes messages queued then. An empty queue yields none.- Parameters:
instance- the Channel-map instancecount- the maximum message countconditionId- the condition ID used to identify its results- Returns:
- the Channel condition
-
range
Creates a condition with optional message-count bounds for one instance. Dex waits only for the minimum, then consumes currently queued messages up to the maximum. Anullminimum makes the condition complete immediately.- Parameters:
instance- the Channel-map instanceatLeast- 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 message-count bounds for one instance. Dex waits only for the minimum, then consumes currently queued messages up to the maximum. Anullminimum makes the condition complete immediately.- Parameters:
instance- the Channel-map instanceatLeast- 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
-