public final class Worker extends java.lang.Object implements Suspendable
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.
|
<R> void |
addWorkflowImplementationFactory(WorkflowImplementationOptions options,
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 |
getTaskQueue() |
static java.lang.String |
getWorkflowType(java.lang.Class<?> workflowInterfaceClass)
Name of the workflow type the interface defines.
|
boolean |
isSuspended() |
void |
registerActivitiesImplementations(java.lang.Object... activityImplementations)
Register activity implementation objects with a worker.
|
void |
registerWorkflowImplementationTypes(java.lang.Class<?>... workflowImplementationClasses)
Registers workflow implementation classes with a worker.
|
void |
registerWorkflowImplementationTypes(WorkflowImplementationOptions options,
java.lang.Class<?>... workflowImplementationClasses)
Registers 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
. By default the short name of the interface is used as 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.
Use DynamicWorkflow
implementation to implement many workflow
types dynamically. It can be useful for implementing DSL based workflows. Only a single type
that implements DynamicWorkflow can be registered per worker.
public void registerWorkflowImplementationTypes(WorkflowImplementationOptions options, java.lang.Class<?>... workflowImplementationClasses)
WorkflowMethod
. By default the short name of the interface is used as 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.
Use DynamicWorkflow
implementation to implement many workflow
types dynamically. It can be useful for implementing DSL based workflows. Only a single type
that implements DynamicWorkflow can be registered per worker.
public <R> void addWorkflowImplementationFactory(WorkflowImplementationOptions options, java.lang.Class<R> workflowInterface, Functions.Func<R> factory)
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 <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)
An activity implementation object must implement at least one interface annotated with
ActivityInterface
. Each method of the annotated interface becomes
an activity type.
Implementations that share a worker must implement different interfaces as an activity type is identified by the activity interface, not by the implementation.
Use an implementation of DynamicActivity
to register an object
that can implement activity types dynamically. A single registration of DynamicActivity
implementation per worker is allowed.
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 getTaskQueue()
public void suspendPolling()
Suspendable
suspendPolling
in interface Suspendable
public void resumePolling()
Suspendable
resumePolling
in interface Suspendable
public boolean isSuspended()
isSuspended
in interface Suspendable
public static java.lang.String getWorkflowType(java.lang.Class<?> workflowInterfaceClass)
WorkflowMethod.name()
parameter.workflowInterfaceClass
- interface annotated with @WorkflowInterface