Package com.uber.cadence.worker
Class WorkerFactory
- java.lang.Object
-
- com.uber.cadence.worker.WorkerFactory
-
public final class WorkerFactory extends java.lang.Object
Maintains worker creation and lifecycle.
-
-
Constructor Summary
Constructors Constructor Description WorkerFactory(WorkflowClient workflowClient, WorkerFactoryOptions factoryOptions)
Creates a factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.WorkflowClient
getWorkflowClient()
java.util.concurrent.CompletableFuture<java.lang.Boolean>
isHealthy()
Checks if we have a valid connection to the Cadence cluster, and potentially resets the peer listboolean
isShutdown()
Wasshutdown()
orshutdownNow()
called.boolean
isStarted()
Wasstart()
called.boolean
isTerminated()
Returns true if all tasks have completed following shut down.static WorkerFactory
newInstance(WorkflowClient workflowClient)
static WorkerFactory
newInstance(WorkflowClient workflowClient, WorkerFactoryOptions options)
Worker
newWorker(java.lang.String taskList)
Creates worker that connects to an instance of the Cadence Service.Worker
newWorker(java.lang.String taskList, WorkerOptions options)
Creates worker that connects to an instance of the Cadence Service.void
resumePolling()
void
shutdown()
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are executed.void
shutdownNow()
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are attempted to be stopped.void
start()
Starts all the workers created by this factory.void
suspendPolling()
-
-
-
Constructor Detail
-
WorkerFactory
public WorkerFactory(WorkflowClient workflowClient, WorkerFactoryOptions factoryOptions)
Creates a factory. Workers will be connect to the cadence-server using the workflowService client passed in.- Parameters:
workflowClient
- client to the Cadence Service endpoint.factoryOptions
- Options used to configure factory settings
-
-
Method Detail
-
newInstance
public static WorkerFactory newInstance(WorkflowClient workflowClient)
-
newInstance
public static WorkerFactory newInstance(WorkflowClient workflowClient, WorkerFactoryOptions options)
-
newWorker
public Worker newWorker(java.lang.String taskList)
Creates worker that connects to an instance of the Cadence Service. It uses the domain configured at the Factory level. New workers cannot be created after the start() has been called- Parameters:
taskList
- task list name worker uses to poll. It uses this name for both decision and activity task list polls.- Returns:
- Worker
-
newWorker
public Worker newWorker(java.lang.String taskList, WorkerOptions options)
Creates worker that connects to an instance of the Cadence Service. It uses the domain configured at the Factory level. New workers cannot be created after the start() has been called- Parameters:
taskList
- task list name worker uses to poll. It uses this name for both decision and activity task list polls.options
- Options (likeDataConverter
override) for configuring worker.- Returns:
- Worker
-
start
public void start()
Starts all the workers created by this factory.
-
isStarted
public boolean isStarted()
Wasstart()
called.
-
isShutdown
public boolean isShutdown()
Wasshutdown()
orshutdownNow()
called.
-
isTerminated
public boolean isTerminated()
Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.
-
getWorkflowClient
public WorkflowClient getWorkflowClient()
- Returns:
- instance of the Cadence client that this worker uses.
-
shutdown
public void shutdown()
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are executed. After the shutdown calls toActivity.heartbeat(Object)
start throwingActivityWorkerShutdownException
. Invocation has no additional effect if already shut down. This method does not wait for previously received tasks to complete execution. UseawaitTermination(long, TimeUnit)
to do that.
-
shutdownNow
public void shutdownNow()
Initiates an orderly shutdown in which polls are stopped and already received decision and activity tasks are attempted to be stopped. This implementation cancels tasks via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate. Also after the shutdownNow calls toActivity.heartbeat(Object)
start throwingActivityWorkerShutdownException
. Invocation has no additional effect if already shut down. This method does not wait for previously received tasks to complete execution. UseawaitTermination(long, TimeUnit)
to do that.
-
isHealthy
public java.util.concurrent.CompletableFuture<java.lang.Boolean> isHealthy()
Checks if we have a valid connection to the Cadence cluster, and potentially resets the peer list
-
awaitTermination
public void awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
-
suspendPolling
public void suspendPolling()
-
resumePolling
public void resumePolling()
-
-