public final class Worker extends java.lang.Object implements Suspendable
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 |
isSuspended() |
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.
|
void |
registerWorkflowImplementationTypes(WorkflowImplementationOptions options,
java.lang.Class<?>... workflowImplementationClasses)
Register workflow implementation classes with a worker.
|
void |
replayWorkflowExecution(java.lang.String jsonSerializedHistory)
This is an utility method to replay a workflow execution using this particular instance of a
worker.
|
void |
replayWorkflowExecution(WorkflowExecutionHistory history)
This is an utility method to replay a workflow execution using this particular instance of a
worker.
|
void |
resumePolling()
Allow new poll requests.
|
void |
suspendPolling()
Do not make new poll requests.
|
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 void registerWorkflowImplementationTypes(WorkflowImplementationOptions options, 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 java.lang.String toString()
toString
in class java.lang.Object
public void replayWorkflowExecution(WorkflowExecutionHistory history) throws java.lang.Exception
start()
to be able to call this method.history
- workflow execution history to replayjava.lang.Exception
- if replay failed for any reasonpublic void replayWorkflowExecution(java.lang.String jsonSerializedHistory) throws java.lang.Exception
start()
to be able to call this method.jsonSerializedHistory
- workflow execution history in JSON format to replayjava.lang.Exception
- if replay failed for any reasonpublic java.lang.String getTaskList()
public void suspendPolling()
Suspendable
suspendPolling
in interface Suspendable
public void resumePolling()
Suspendable
resumePolling
in interface Suspendable
public boolean isSuspended()
isSuspended
in interface Suspendable