Interface Context
A context belongs to one worker invocation and must not be retained or used from another
thread after the method returns. Attribute and Channel helpers are also available directly on
their typed definitions; the context methods are useful for framework-style code. Values passed
with a Class must use concrete, non-parameterized types. Wrap a parameterized value in a
concrete holder class, or use an array such as String[] instead of List<String>.
public StepDecision execute(Context context, Order input) {
int attempt = context.getAttempt();
status.set(context, "processed-on-attempt-" + attempt);
context.recordEvent("order-processed", input, Order.class);
return StepDecision.gracefulComplete();
}
-
Method Summary
Modifier and TypeMethodDescription<T> List<T> channelResults(Channel<T> channel) Returns condition results for a Channel.<T> List<T> channelResults(ChannelMap<T> channel, String instance) Returns condition results for one Channel-map instance.intchannelSize(Channel<?> channel) Returns the visible message count for a Channel.intchannelSize(ChannelMap<?> channel, String instance) Returns the visible message count for one Channel-map instance.voiddeleteAttribute(Attribute<?> attribute) Deletes an Attribute.voiddeleteAttribute(AttributeMap<?> attribute, String instance) Deletes one Attribute-map instance.voiddeleteChannelMessage(Channel<?> channel, String messageId) Stages deletion of one pending singleton Channel message from an RPC.voiddeleteChannelMessage(ChannelMap<?> channel, String instance, String messageId) Stages deletion of one pending Channel-map message from an RPC.intReturns the one-based attempt number of the current method invocation.<T> TgetAttribute(Attribute<T> attribute) Reads an Attribute.<T> TgetAttribute(AttributeMap<T> attribute, String instance) Reads one Attribute-map instance.Returns when the first attempt of the current method began.Returns the Flow ID for the current invocation.Returns when the current Flow execution started.Returns the Step execution that scheduled the current Step.<T> TgetLastHeartbeatValue(Class<T> valueType) Decodes heartbeat details restored from an earlier attempt.Returns the previous Step method failure that caused this recovery invocation.getRunId()Returns the current Flow run ID.Returns the server-assigned identifier of the current Step execution.<T> TgetStepExecutionLocal(String key, Class<T> valueType) Reads a value scoped to the current Step execution.booleanReports whether Dex restored heartbeat details from an earlier attempt.booleanReports whether any timer condition in the current wait has fired.booleanhasTimerFired(int index) Reports whether the timer at a specific condition index fired.booleanReports whether Dex requested cancellation of the current Step execution.<T> List<ChannelMessage<T>> pendingChannelMessages(Channel<T> channel) Returns a singleton Channel's loaded pending-message snapshot in FIFO order.<T> List<ChannelMessage<T>> pendingChannelMessages(ChannelMap<T> channel, String instance) Returns one ChannelMap instance's loaded pending-message snapshot in FIFO order.<T> voidPublishes one message to a Channel.<T> voidpublish(ChannelMap<T> channel, String instance, T value) Publishes one message to a Channel-map instance.<T> voidrecordEvent(String name, T value, Class<T> valueType) Appends a named user event to the Flow execution history.voidrecordHeartbeat(Object value) Sends a best-effort heartbeat for the current Step method or Flow timeout attempt.<T> voidsetAttribute(Attribute<T> attribute, T value) Writes an Attribute.<T> voidsetAttribute(AttributeMap<T> attribute, String instance, T value) Writes one Attribute-map instance.<T> voidsetStepExecutionLocal(String key, T value, Class<T> valueType) Stores a value scoped to the current Step execution.booleanReports whether execute is running after a failed wait-for method.<T> voidwriteStream(Stream<T> stream, T value) Appends one immediate best-effort Stream message.
-
Method Details
-
getFlowId
-
getRunId
-
getFlowStartedAt
Instant getFlowStartedAt()Returns when the current Flow execution started.- Returns:
- the Flow start timestamp
-
getStepExecutionId
String getStepExecutionId()Returns the server-assigned identifier of the current Step execution.- Returns:
- the Step execution ID
-
getFromStepExecutionId
String getFromStepExecutionId()Returns the Step execution that scheduled the current Step.- Returns:
- the originating Step execution ID, or an empty value when none exists
-
getRecoveryError
RecoveryErrorInfo getRecoveryError()Returns the previous Step method failure that caused this recovery invocation.For wait-for recovery, execute receives the failed wait-for method's final error. For an execute recovery Step, both wait-for and execute receive the failed execute method's final error. A recovery Step whose own wait-for fails receives that newer failure in execute.
- Returns:
- the recovery error, or
nullfor a normal Step or RPC invocation
-
getFirstAttemptAt
Instant getFirstAttemptAt()Returns when the first attempt of the current method began.- Returns:
- the first-attempt timestamp
-
getAttempt
int getAttempt()Returns the one-based attempt number of the current method invocation.- Returns:
- the current attempt number
-
isCancellationRequested
boolean isCancellationRequested()Reports whether Dex requested cancellation of the current Step execution.When cancellation reaches the Java Worker, Dex cancels the handler task and interrupts its thread. Blocking handlers should return when they receive
InterruptedException. CPU-bound or batch-oriented handlers may check this method at natural work boundaries; they do not need to poll continuously. Neither thread interruption nor this method makes external side effects atomic. Use timeouts, idempotency, or compensation when required.- Returns:
trueafter cancellation is requested or the handler thread is interrupted
-
hasTimerFired
boolean hasTimerFired()Reports whether any timer condition in the current wait has fired.- Returns:
truewhen at least one timer fired
-
hasTimerFired
boolean hasTimerFired(int index) Reports whether the timer at a specific condition index fired.- Parameters:
index- the zero-based timer condition index- Returns:
truewhen that timer fired
-
waitForMethodFailed
boolean waitForMethodFailed()Reports whether execute is running after a failed wait-for method.This can be
trueonly when the Step usesWaitForFailurePolicy.PROCEED.- Returns:
truewhen wait-for retries were exhausted before execute
-
recordHeartbeat
Sends a best-effort heartbeat for the current Step method or Flow timeout attempt.Dex persists a nonnull value with the activity heartbeat and supplies it to a later attempt through
getLastHeartbeatValue(Class). Passingnullsends a heartbeat without details, clearing any value previously reported during the current attempt. A Stream write also acts as a heartbeat and preserves the most recently reported details. Heartbeats are ignored while an asynchronous Step runs as a local activity. This method sends directly on the invocation's response stream and must be called only from the handler thread.public StepDecision execute(Context context, Batch input) { for (int index = 0; index < input.items().size(); index++) { process(input.items().get(index)); context.recordHeartbeat(index + 1); } return StepDecision.gracefulComplete(); }- Parameters:
value- the checkpoint to persist, ornullto send no heartbeat details- Throws:
IllegalStateException- if called from an RPCio.grpc.StatusRuntimeException- if the invocation is canceled or transport failsValueMappingException- if a nonnull value cannot be encoded
-
hasLastHeartbeatValue
boolean hasLastHeartbeatValue()Reports whether Dex restored heartbeat details from an earlier attempt.- Returns:
truewhengetLastHeartbeatValue(Class)can decode a restored value
-
getLastHeartbeatValue
Decodes heartbeat details restored from an earlier attempt.Call
hasLastHeartbeatValue()to distinguish an absent checkpoint. Values passed with aClassmust use concrete, non-parameterized types.- Type Parameters:
T- the checkpoint type- Parameters:
valueType- the concrete Java class used to decode the checkpoint- Returns:
- the decoded checkpoint, or
nullwhen no checkpoint was restored - Throws:
ValueMappingException- if the value cannot be decoded
-
setStepExecutionLocal
Stores a value scoped to the current Step execution.Step-execution locals allow
Step.waitFor(Context, I)to pass durable data toStep.execute(Context, I)for the same execution.- Type Parameters:
T- the local value type- Parameters:
key- the local value keyvalue- the value to serializevalueType- the concrete Java value class
-
getStepExecutionLocal
Reads a value scoped to the current Step execution.- Type Parameters:
T- the local value type- Parameters:
key- the local value keyvalueType- the concrete Java class used to decode the value- Returns:
- the decoded value, or
nullwhen the key is absent
-
recordEvent
-
getAttribute
Reads an Attribute.- Type Parameters:
T- the Attribute value type- Parameters:
attribute- the registered typed Attribute- Returns:
- the current value, or
nullwhen absent
-
getAttribute
Reads one Attribute-map instance.- Type Parameters:
T- the Attribute value type- Parameters:
attribute- the registered typed Attribute mapinstance- the map instance- Returns:
- the current value, or
nullwhen absent
-
setAttribute
Writes an Attribute.- Type Parameters:
T- the Attribute value type- Parameters:
attribute- the registered typed Attributevalue- the value to persist
-
setAttribute
Writes one Attribute-map instance.- Type Parameters:
T- the Attribute value type- Parameters:
attribute- the registered typed Attribute mapinstance- the map instancevalue- the value to persist
-
deleteAttribute
Deletes an Attribute.- Parameters:
attribute- the registered Attribute
-
deleteAttribute
Deletes one Attribute-map instance.- Parameters:
attribute- the registered Attribute mapinstance- the map instance
-
publish
Publishes one message to a Channel.- Type Parameters:
T- the Channel message type- Parameters:
channel- the registered typed Channelvalue- the message value
-
publish
Publishes one message to a Channel-map instance.- Type Parameters:
T- the Channel message type- Parameters:
channel- the registered typed Channel mapinstance- the map instancevalue- the message value
-
deleteChannelMessage
-
deleteChannelMessage
Stages deletion of one pending Channel-map message from an RPC.- Parameters:
channel- the registered Channel mapinstance- the nonblank Channel-map instancemessageId- the nonblank server-assigned message ID
-
channelSize
Returns the visible message count for a Channel.- Parameters:
channel- the registered Channel- Returns:
- the visible message count
-
channelSize
Returns the visible message count for one Channel-map instance.- Parameters:
channel- the registered Channel mapinstance- the map instance- Returns:
- the visible message count
-
pendingChannelMessages
Returns a singleton Channel's loaded pending-message snapshot in FIFO order.- Type Parameters:
T- the Channel message type- Parameters:
channel- the registered typed Channel selected by invocation options- Returns:
- immutable pending message IDs and decoded values
- Throws:
ChannelMessagesNotLoadedException- if the invocation did not load its messages
-
pendingChannelMessages
Returns one ChannelMap instance's loaded pending-message snapshot in FIFO order.- Type Parameters:
T- the Channel message type- Parameters:
channel- the registered typed ChannelMap selected by invocation optionsinstance- the logical map instance- Returns:
- immutable pending message IDs and decoded values
- Throws:
ChannelMessagesNotLoadedException- if the invocation did not load its messages
-
channelResults
-
channelResults
Returns condition results for one Channel-map instance.- Type Parameters:
T- the Channel message type- Parameters:
channel- the registered typed Channel mapinstance- the map instance used by the condition- Returns:
- the typed messages consumed by the satisfied condition
-
writeStream
Appends one immediate best-effort Stream message.The write emits a frame on the current Step method response stream and does not wait for storage acknowledgement. Multiple writes to the same Stream are allowed. Dex may discard a message when its Stream Store is unavailable or rejects the write.
- Type Parameters:
T- the Stream message type- Parameters:
stream- the Stream registered by the current Flowvalue- the typed message to append- Throws:
IllegalStateException- if called from an RPCio.grpc.StatusRuntimeException- if the invocation is canceled or transport failsValueMappingException- if the value cannot be encoded
-