Class Client
- All Implemented Interfaces:
AutoCloseable
All network methods block the calling thread until the gRPC request completes. Create one
client for a registered set of Flow definitions and reuse it across calls; the underlying gRPC
channel supports concurrent callers. The supplied BlobCache is borrowed and is not closed
by the client. Service failures use typed DexServiceException subclasses. Long-poll
operations can throw LongPollTimeoutException. waitForFlow(String) returns a
FlowResult for every terminal status.
Registry registry = new Registry(Collections.<Flow<?>>singletonList(orderFlow));
try (Client client = new Client(registry, blobCache)) {
String runId = client.startFlow(orderFlow, "order-123", input);
OrderFlow rpc = client.newRpcStub(OrderFlow.class, "order-123", runId);
OrderStatus status = client.invokeRPC(rpc::getStatus);
OrderOutput output = client.waitForFlow("order-123").getSingleOutput(OrderOutput.class);
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shuts down the client's gRPC channel.describeFlow(String flowId) Returns aFlowInfosummary of the current Flow run.<O> OinvokeRPC(RpcDefinitions.RpcFunc0<O> rpcStubMethod) Invokes a function-style RPC without application input.<O> OinvokeRPC(RpcDefinitions.RpcFunc0<O> rpcStubMethod, RPCInvokeOptions invokeOptions) Invokes a function-style RPC without application input and adds map-instance selections.<I,O> O invokeRPC(RpcDefinitions.RpcFunc1<I, O> rpcStubMethod, I input) Invokes a function-style RPC with one input and returns its typed output.<I,O> O invokeRPC(RpcDefinitions.RpcFunc1<I, O> rpcStubMethod, I input, RPCInvokeOptions invokeOptions) Invokes a function-style RPC with one input and runtime-selected map instances.voidinvokeRPC(RpcDefinitions.RpcProc0 rpcStubMethod) Invokes a procedure-style RPC without application input.voidinvokeRPC(RpcDefinitions.RpcProc0 rpcStubMethod, RPCInvokeOptions invokeOptions) Invokes a procedure-style RPC without input and adds map-instance selections.<I> voidinvokeRPC(RpcDefinitions.RpcProc1<I> rpcStubMethod, I input) Invokes a procedure-style RPC with one input.<I> voidinvokeRPC(RpcDefinitions.RpcProc1<I> rpcStubMethod, I input, RPCInvokeOptions invokeOptions) Invokes a procedure-style RPC with one input and runtime-selected map instances.<T> StreamMessagesPage<T> listStreamMessages(String flowId, Stream<T> stream, int pageSize, String beforePageToken) Returns one newest-first page of retained Stream messages without waiting for writes.<T> TnewRpcStub(Class<T> rpcClass, String flowId) Creates a strongly typed RPC stub targeting the current run of a Flow.<T> TnewRpcStub(Class<T> rpcClass, String flowId, String runId) Creates a strongly typed RPC stub targeting a specific Flow run.<T> StreamMessage<T> readStream(String flowId, Stream<T> stream, String resumeToken) Blocks for the next retained Stream message using the server default wait.<T> StreamMessage<T> readStream(String flowId, Stream<T> stream, String resumeToken, Duration timeout) Blocks for the next retained Stream message with an explicit long-poll duration.searchFlows(String query, int pageSize) Searches Flow executions and returns the first page.searchFlows(String query, int pageSize, String nextPageToken) Searches Flow executions from a continuation token.searchFlows(String query, int pageSize, String nextPageToken, SearchFlowsOptions options) Searches with inclusion options.voidskipTimer(String flowId, StepExecutionId stepExecutionId, TimerId timerId) Makes one durable timer condition fire immediately.<I> StringStarts a registered Flow using default start options.<I> StringstartFlow(Flow<I> flow, String flowId, I input, StartFlowOptions startOptions) Starts a registered Flow with explicit start options.voidCancels a running Flow without an explicit reason.voidstopFlow(String flowId, StopFlowOptions stopOptions) Stops a running Flow with explicit terminal behavior.timeTravel(String flowId, TimeTravelOptions options) Creates a new run from a selected point in an existing Flow's history.voidtriggerContinueAsNew(String flowId) Requests that the current Flow run continue as new.voidupdateFlowConfig(String flowId, FlowConfig config) Updates the supplied mutable Flow configuration fields for the current run.<T> TwaitForAttributeMatch(String flowId, Attribute<T> attribute, AttributeMatch<T> match, WaitForAttributeOptions options) Blocks until a singleton Attribute satisfies a scalar match or its request timeout expires.<T> TwaitForAttributeMatch(String flowId, AttributeMap<T> attribute, String instance, AttributeMatch<T> match, WaitForAttributeOptions options) Blocks until an AttributeMap instance satisfies a scalar match.waitForFlow(String flowId) Blocks until a Flow reaches any terminal status.waitForFlow(String flowId, Duration timeout) Blocks for a bounded duration until a Flow reaches any terminal status.voidwaitForStepCompletion(String flowId, StepExecutionId stepExecutionId, WaitForStepCompletionOptions options) Blocks until a specific Step execution completes or its caller-visible request expires.<T> voidwriteStream(String flowId, Stream<T> stream, String source, T value) Appends one typed best-effort Stream message with producer metadata.
-
Constructor Details
-
Client
Creates a client using local development defaults.- Parameters:
registry- the nonnull registry of Flow definitions used for typed mappingblobCache- the nonnull cache used to hydrate blob-backed values- Throws:
IllegalArgumentException- if either argument isnull
-
Client
Creates a client with explicit connection, routing, and serialization options.- Parameters:
registry- the nonnull registry of Flow definitions used for typed mappingblobCache- the nonnull cache used to hydrate blob-backed valuesoptions- the nonnull client options- Throws:
IllegalArgumentException- if any argument isnull
-
-
Method Details
-
startFlow
Starts a registered Flow using default start options.- Type Parameters:
I- the Flow start input type- Parameters:
flow- the exact Flow instance registered with this clientflowId- the nonblank application-assigned Flow IDinput- the typed start-Step input, ornullfor a Flow without a start Step- Returns:
- the server-assigned run ID
- Throws:
IllegalArgumentException- if the Flow is unregistered, the ID is invalid, or the input does not match the registered start StepFlowAlreadyStartedException- if the Flow ID conflicts with an existing executionDexServiceException- if Dex otherwise rejects or cannot complete the request
-
startFlow
Starts a registered Flow with explicit start options.- Type Parameters:
I- the Flow start input type- Parameters:
flow- the exact Flow instance registered with this clientflowId- the nonblank application-assigned Flow IDinput- the typed start-Step input, ornullfor a Flow without a start StepstartOptions- timeout, scheduling, initial state, routing, and idempotency settings- Returns:
- the server-assigned run ID
- Throws:
IllegalArgumentException- if the Flow, ID, input, or duration settings are invalid, if an initial value targets aAttribute.hardDeleteOnNull()Attribute and maps to a number or a Boolean, or if an initial Attribute's hard-delete setting differs from the definition registered for the FlowIllegalStateException- if an initial value targets a hard-delete Attribute and the Server does not support protocol version 3 or later, or the Server protocol cannot be negotiatedFlowAlreadyStartedException- if the Flow ID conflicts with an existing executionDexServiceException- if Dex otherwise rejects or cannot complete the request
-
newRpcStub
Creates a strongly typed RPC stub targeting the current run of a Flow.- Type Parameters:
T- the concrete Flow class- Parameters:
rpcClass- the non-final registered Flow class containingRPCmethodsflowId- the target Flow ID- Returns:
- a constructor-free stub whose RPC methods perform client requests
- Throws:
IllegalArgumentException- if the class is unregistered, final, or cannot be subclassed
-
newRpcStub
Creates a strongly typed RPC stub targeting a specific Flow run.Dex subclasses the class with ByteBuddy and allocates the stub without invoking a constructor. RPC methods and the containing class must therefore be non-final. Kotlin classes and methods are final by default and must be declared
open.- Type Parameters:
T- the concrete Flow class- Parameters:
rpcClass- the non-final registered Flow class containingRPCmethodsflowId- the target Flow IDrunId- the target run ID, or an empty string for the current run- Returns:
- a constructor-free typed RPC stub
- Throws:
IllegalArgumentException- if the class is unregistered, final, or cannot be subclassed
-
invokeRPC
Invokes a function-style RPC with one input and returns its typed output.A non-transactional RPC without Attribute locks starts from a backend query. A retained terminal execution can serve the query when the handler returns no durable effects. Locks, transactional execution, returned effects, or server policy can require an active execution.
- Type Parameters:
I- the RPC input typeO- the RPC output type- Parameters:
rpcStubMethod- a direct method reference from a stub created by this clientinput- the typed RPC input- Returns:
- the decoded RPC output
- Throws:
FlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
invokeRPC
public <I,O> O invokeRPC(RpcDefinitions.RpcFunc1<I, O> rpcStubMethod, I input, RPCInvokeOptions invokeOptions) Invokes a function-style RPC with one input and runtime-selected map instances.- Type Parameters:
I- the RPC input typeO- the RPC output type- Parameters:
rpcStubMethod- a direct method reference from a stub created by this clientinput- the typed RPC inputinvokeOptions- additive Attribute-map locks and exact map-instance loads- Returns:
- the decoded RPC output
- Throws:
FlowDefinitionException- if an option references a definition outside the RPC FlowIllegalArgumentException- ifinvokeOptionsisnullFlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
invokeRPC
Invokes a function-style RPC without application input.A retained terminal execution can serve a query-only RPC. Locks, transactional execution, returned effects, or server policy can require an active execution.
- Type Parameters:
O- the RPC output type- Parameters:
rpcStubMethod- a direct method reference from a stub created by this client- Returns:
- the decoded RPC output
- Throws:
FlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
invokeRPC
Invokes a function-style RPC without application input and adds map-instance selections.- Type Parameters:
O- the RPC output type- Parameters:
rpcStubMethod- a direct method reference from a stub created by this clientinvokeOptions- additive Attribute-map locks and exact map-instance loads- Returns:
- the decoded RPC output
- Throws:
FlowDefinitionException- if an option references a definition outside the RPC FlowIllegalArgumentException- ifinvokeOptionsisnullFlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
invokeRPC
Invokes a procedure-style RPC with one input.A retained terminal execution can serve a query-only RPC. Locks, transactional execution, returned effects, or server policy can require an active execution.
- Type Parameters:
I- the RPC input type- Parameters:
rpcStubMethod- a direct method reference from a stub created by this clientinput- the typed RPC input- Throws:
FlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
invokeRPC
public <I> void invokeRPC(RpcDefinitions.RpcProc1<I> rpcStubMethod, I input, RPCInvokeOptions invokeOptions) Invokes a procedure-style RPC with one input and runtime-selected map instances.- Type Parameters:
I- the RPC input type- Parameters:
rpcStubMethod- a direct method reference from a stub created by this clientinput- the typed RPC inputinvokeOptions- additive Attribute-map locks and exact map-instance loads- Throws:
FlowDefinitionException- if an option references a definition outside the RPC FlowIllegalArgumentException- ifinvokeOptionsisnullFlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
invokeRPC
Invokes a procedure-style RPC without application input.A retained terminal execution can serve a query-only RPC. Locks, transactional execution, returned effects, or server policy can require an active execution.
- Parameters:
rpcStubMethod- a direct method reference from a stub created by this client- Throws:
FlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
invokeRPC
Invokes a procedure-style RPC without input and adds map-instance selections.- Parameters:
rpcStubMethod- a direct method reference from a stub created by this clientinvokeOptions- additive Attribute-map locks and exact map-instance loads- Throws:
FlowDefinitionException- if an option references a definition outside the RPC FlowIllegalArgumentException- ifinvokeOptionsisnullFlowNotActiveOrNotFoundException- if the Flow is missing or the selected path cannot use its closed executionRpcLockConflictException- if the RPC cannot acquire its Attribute locksWorkerInvocationException- if worker code fails while executing the RPCDexServiceException- if Dex otherwise rejects or cannot complete the RPC
-
writeStream
Appends one typed best-effort Stream message with producer metadata.Each call appends a new message. The source is informational and may be reused, including by concurrent producers. A source may contain
#.- Type Parameters:
T- the Stream message type- Parameters:
flowId- the logical Flow instance ID; the Flow need not exist or be activestream- the exact Stream registered in one Flow schemasource- the nonblank producer description returned with the messagevalue- the typed message to append- Throws:
FlowDefinitionException- if the Stream is not registeredIllegalArgumentException- if the Flow ID or source is invalidDexServiceException- if Dex cannot append the message
-
readStream
Blocks for the next retained Stream message using the server default wait.- Type Parameters:
T- the Stream message type- Parameters:
flowId- the logical Flow instance IDstream- the exact Stream registered in one Flow schemaresumeToken- the prior token, or empty for the retained head- Returns:
- the decoded message and resumable metadata
-
readStream
public <T> StreamMessage<T> readStream(String flowId, Stream<T> stream, String resumeToken, Duration timeout) Blocks for the next retained Stream message with an explicit long-poll duration.- Type Parameters:
T- the Stream message type- Parameters:
flowId- the logical Flow instance IDstream- the exact Stream registered in one Flow schemaresumeToken- the prior token, or empty for the retained headtimeout- the nonnegative whole-second server wait, ornullfor its default- Returns:
- the decoded message and resumable metadata
- Throws:
LongPollTimeoutException- if no message arrives before the wait expiresFlowDefinitionException- if the Stream is not registeredDexServiceException- if Dex cannot read the Stream
-
listStreamMessages
public <T> StreamMessagesPage<T> listStreamMessages(String flowId, Stream<T> stream, int pageSize, String beforePageToken) Returns one newest-first page of retained Stream messages without waiting for writes.An empty token starts at the retained tail. Pass the returned next-page token unchanged to read older messages. Stream trimming may remove messages between pages.
- Type Parameters:
T- the Stream message type- Parameters:
flowId- the logical Flow instance ID used as the Stream instance keystream- the exact Stream registered in one Flow schemapageSize- the positive maximum count within the server-configured limitbeforePageToken- the preceding page token, or empty for the first page- Returns:
- decoded messages in newest-first order and the next-page token
- Throws:
IllegalArgumentException- ifpageSizeis not positiveFlowDefinitionException- if the Stream is not registeredDexServiceException- if Dex cannot list the Stream
-
stopFlow
Cancels a running Flow without an explicit reason.- Parameters:
flowId- the target Flow ID- Throws:
FlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot stop the Flow
-
stopFlow
Stops a running Flow with explicit terminal behavior.- Parameters:
flowId- the target Flow IDstopOptions- the stop mode and optional reason- Throws:
FlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot stop the Flow
-
waitForFlow
Blocks until a Flow reaches any terminal status.- Parameters:
flowId- the target Flow ID- Returns:
- the terminal Flow result
- Throws:
FlowNotFoundException- if no matching Flow execution existsDexServiceException- if Dex otherwise cannot complete the wait request
-
waitForFlow
Blocks for a bounded duration until a Flow reaches any terminal status.- Parameters:
flowId- the target Flow IDtimeout- the nonnegative whole-second long-poll duration, ornullfor no bound- Returns:
- the terminal Flow result
- Throws:
LongPollTimeoutException- iftimeoutexpires while the Flow remains runningIllegalArgumentException- iftimeoutis not a supported whole-second durationFlowNotFoundException- if no matching Flow execution existsDexServiceException- if Dex otherwise cannot complete the wait request
-
describeFlow
Returns aFlowInfosummary of the current Flow run.The summary contains the Flow ID, run ID, Flow type, current status, and start time. It reflects the execution when Dex handles this request; a running Flow may change afterward.
- Parameters:
flowId- the target Flow ID- Returns:
- the current Flow run summary
- Throws:
FlowNotFoundException- if no matching Flow execution existsDexServiceException- if Dex otherwise cannot describe the Flow
-
searchFlows
Searches Flow executions and returns the first page.- Parameters:
query- the server search expression, ornullfor the default searchpageSize- the nonnegative requested page size; zero uses the server default- Returns:
- the first immutable search-results page
- Throws:
IllegalArgumentException- ifpageSizeis negativeDexServiceException- if Dex cannot execute the search
-
searchFlows
Searches Flow executions from a continuation token.- Parameters:
query- the same server search expression used for the previous pagepageSize- the nonnegative requested page size; zero uses the server defaultnextPageToken- the prior page's token, ornullfor the first page- Returns:
- an immutable search-results page
- Throws:
IllegalArgumentException- ifpageSizeis negativeDexServiceException- if Dex cannot execute the search
-
searchFlows
public SearchFlowsPage searchFlows(String query, int pageSize, String nextPageToken, SearchFlowsOptions options) Searches with inclusion options.- Parameters:
query- filterpageSize- maximumnextPageToken- tokenoptions- inclusion- Returns:
- page
-
timeTravel
Creates a new run from a selected point in an existing Flow's history.- Parameters:
flowId- the target Flow IDoptions- the time travel point and replay behavior- Returns:
- the server-assigned run ID of the new execution
- Throws:
FlowNotFoundException- if no matching Flow execution existsDexServiceException- if Dex otherwise rejects or cannot perform time travel
-
skipTimer
Makes one durable timer condition fire immediately.- Parameters:
flowId- the target Flow IDstepExecutionId- the Step execution containing the timertimerId- the timer selected by condition ID or index- Throws:
FlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot find or skip the timer
-
waitForStepCompletion
public void waitForStepCompletion(String flowId, StepExecutionId stepExecutionId, WaitForStepCompletionOptions options) Blocks until a specific Step execution completes or its caller-visible request expires. The server derives a stable Request ID from the Step execution when none is supplied. Request timeout covers transparent transport reattachments. Internal handler timeout controls Temporal Update generation rollover and does not end this request.- Parameters:
flowId- the target Flow IDstepExecutionId- the Step execution to observeoptions- the Request ID override and request/handler timeout controls- Throws:
IllegalArgumentException- if either timeout is unsupportedRequestTimeoutException- if a positive request timeout expires firstFlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot complete the wait request
-
waitForAttributeMatch
public <T> T waitForAttributeMatch(String flowId, Attribute<T> attribute, AttributeMatch<T> match, WaitForAttributeOptions options) Blocks until a singleton Attribute satisfies a scalar match or its request timeout expires. The server derives a stable Request ID from the condition when none is supplied. Request timeout covers transparent transport reattachments. Internal handler timeout controls Temporal Update generation rollover and does not end this request.- Type Parameters:
T- the Attribute value type- Parameters:
flowId- the target Flow IDattribute- the registered Attribute definitionmatch- the scalar predicate to awaitoptions- the Request ID override and request/handler timeout controls- Returns:
- the current Attribute value that satisfied the match
- Throws:
IllegalArgumentException- if the budget, match operand, or operator is invalid, or if the definition usesAttribute.hardDeleteOnNull()orAttributeMap.hardDeleteOnNull()RequestTimeoutException- if a positive request timeout expires firstFlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot complete the wait
-
waitForAttributeMatch
public <T> T waitForAttributeMatch(String flowId, AttributeMap<T> attribute, String instance, AttributeMatch<T> match, WaitForAttributeOptions options) Blocks until an AttributeMap instance satisfies a scalar match.- Type Parameters:
T- the Attribute value type- Parameters:
flowId- the target Flow IDattribute- the registered Attribute-map definitioninstance- the map instancematch- the scalar predicate to awaitoptions- the Request ID override and request/handler timeout controls- Returns:
- the current AttributeMap value that satisfied the match
- Throws:
IllegalArgumentException- if the budget, match operand, or operator is invalid, or if the definition usesAttribute.hardDeleteOnNull()orAttributeMap.hardDeleteOnNull()RequestTimeoutException- if a positive request timeout expires firstFlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot complete the wait
-
updateFlowConfig
Updates the supplied mutable Flow configuration fields for the current run.Unset fields retain their existing values. Worker routing remains unchanged.
- Parameters:
flowId- the target Flow IDconfig- the new Flow configuration- Throws:
FlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot update the Flow
-
triggerContinueAsNew
Requests that the current Flow run continue as new.- Parameters:
flowId- the target Flow ID- Throws:
FlowNotActiveOrNotFoundException- if the target Flow has no active executionDexServiceException- if Dex otherwise cannot apply the request
-
close
public void close()Shuts down the client's gRPC channel.The method waits up to five seconds for channel termination and preserves interruption status. The application owns any supplied
Credentialand the borrowedBlobCache.- Specified by:
closein interfaceAutoCloseable
-