Client Usage
Creating Workflow Stubs
The Infinitic client manages workflows through stubs built from the workflow interface.
Here is an example of workflow interface from our Hello World app:
public interface HelloWorkflow {
String greet(String name);
}
interface HelloWorkflow {
fun greet(name: String): String
}
Using this interface, an Infinitic client can create stubs that behaves syntactically as instances of such workflow. Stubs are used to trigger actions such as:
- starting a new workflow
- cancelling running workflows
- sending a signal to running workflows
- starting a new method on running workflows
Stub of New Workflow
The client has a newWorkflow
method to create the stub of a new workflow:
HelloWorkflow w =
client.newWorkflow(HelloWorkflow.class);
val w : HelloWorkflow =
client.newWorkflow(HelloWorkflow::class.java)
We can also add tags to this stub. Those tags will be attached to workflow instances started with this stub.
HelloWorkflow w =
client.newWorkflow(HelloWorkflow.class, Set.of("foo", "bar"));
val w : HelloWorkflow =
client.newWorkflow(HelloWorkflow::class.java, tags = setOf("foo", "bar"))
The stub of new workflow can be used to start a new workflow instance. It can be used multiple times to start multiple instances.
Stub of An Running Workflow
A workflow is said running, as long as it is neither completed neither canceled.
We can create the stub of a running workflow from its id
:
HelloWorkflow w =
client.getWorkflowById(HelloWorkflow.class, id);
val w : HelloWorkflow =
client.getWorkflowById(HelloWorkflow::class.java, id)
Alternatively, we can create a stub targeting all running workflow having a given tag:
HelloWorkflow w =
client.getWorkflowByTag(HelloWorkflow.class, "foo");
val w: HelloWorkflow =
client.getWorkflowByTag(HelloWorkflow::class.java, tag = "foo")
The stub of running workflows can be used to apply actions to the targeted workflows:
- cancelling
- sending signals
- starting new methods
Creating a stub has no side effect. It just creates an object that contains the provided info.