public final class Worker
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Worker.Factory
Maintains worker creation and lifecycle.
|
static class |
Worker.FactoryOptions |
Modifier and Type | Method and Description |
---|---|
<R> void |
addWorkflowImplementationFactory(java.lang.Class<R> workflowInterface,
Functions.Func<R> factory)
Configures a factory to use when an instance of a workflow implementation is created.
|
java.lang.String |
getTaskList() |
boolean |
isClosed() |
boolean |
isStarted() |
<R> R |
queryWorkflowExecution(WorkflowExecution execution,
java.lang.String queryType,
java.lang.Class<R> returnType,
java.lang.Object... args)
This is an utility method to query a workflow execution using this particular instance of a
worker.
|
<R> R |
queryWorkflowExecution(WorkflowExecution execution,
java.lang.String queryType,
java.lang.Class<R> resultClass,
java.lang.reflect.Type resultType,
java.lang.Object... args)
This is an utility method to query a workflow execution using this particular instance of a
worker.
|
void |
registerActivitiesImplementations(java.lang.Object... activityImplementations)
Register activity implementation objects with a worker.
|
void |
registerWorkflowImplementationTypes(java.lang.Class<?>... workflowImplementationClasses)
Register workflow implementation classes with a worker.
|
java.lang.String |
toString() |
public void registerWorkflowImplementationTypes(java.lang.Class<?>... workflowImplementationClasses)
WorkflowMethod
. That method becomes a workflow type that this worker supports.
Implementations that share a worker must implement different interfaces as a workflow type is identified by the workflow interface, not by the implementation.
The reason for registration accepting workflow class, but not the workflow instance is that workflows are stateful and a new instance is created for each workflow execution.
public <R> void addWorkflowImplementationFactory(java.lang.Class<R> workflowInterface, Functions.Func<R> factory)
worker.addWorkflowImplementationFactory(ChildWorkflow.class, () -> {
ChildWorkflow child = mock(ChildWorkflow.class);
when(child.workflow(anyString(), anyString())).thenReturn("result1");
return child;
});
Unless mocking a workflow execution use registerWorkflowImplementationTypes(Class[])
.
R
- type of the workflow object to create.workflowInterface
- Workflow interface that this factory implementsfactory
- factory that when called creates a new instance of the workflow implementation
object.public void registerActivitiesImplementations(java.lang.Object... activityImplementations)
Implementations that share a worker must implement different interfaces as an activity type is identified by the activity interface, not by the implementation.
public boolean isStarted()
public boolean isClosed()
public java.lang.String toString()
toString
in class java.lang.Object
public <R> R queryWorkflowExecution(WorkflowExecution execution, java.lang.String queryType, java.lang.Class<R> returnType, java.lang.Object... args) throws java.lang.Exception
WorkflowClient
to query workflows is preferable, as it doesn't require workflow
implementation code to be available. There is no need to call start()
to be able to
call this method.R
- type of the query resultexecution
- workflow execution to replay and then query locallyqueryType
- query type to executereturnType
- return type of the query resultargs
- query argumentsjava.lang.Exception
- if replay failed for any reasonpublic <R> R queryWorkflowExecution(WorkflowExecution execution, java.lang.String queryType, java.lang.Class<R> resultClass, java.lang.reflect.Type resultType, java.lang.Object... args) throws java.lang.Exception
WorkflowClient
to query workflows is preferable, as it doesn't require workflow
implementation code to be available. There is no need to call start()
to be able to
call this method.R
- type of the query resultexecution
- workflow execution to replay and then query locallyqueryType
- query type to executeresultClass
- return class of the query resultresultType
- return type of the query result. Useful when resultClass is a generic type.args
- query argumentsjava.lang.Exception
- if replay failed for any reasonpublic java.lang.String getTaskList()