Package io.temporal.worker
Class WorkerFactory
- java.lang.Object
-
- io.temporal.worker.WorkerFactory
-
public final class WorkerFactory extends java.lang.Object
Maintains worker creation and lifecycle.
-
-
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.Worker
getWorker(java.lang.String taskQueue)
WorkflowClient
getWorkflowClient()
boolean
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 taskQueue)
Creates worker that connects to an instance of the Temporal Service.Worker
newWorker(java.lang.String taskQueue, WorkerOptions options)
Creates worker that connects to an instance of the Temporal Service.void
resumePolling()
void
shutdown()
Initiates an orderly shutdown in which polls are stopped and already received workflow and activity tasks are executed.void
shutdownNow()
Initiates an orderly shutdown in which polls are stopped and already received workflow and activity tasks are attempted to be stopped.void
start()
Starts all the workers created by this factory.void
suspendPolling()
java.lang.String
toString()
Worker
tryGetWorker(java.lang.String taskQueue)
-
-
-
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 taskQueue)
Creates worker that connects to an instance of the Temporal Service. It uses the namespace configured at the Factory level. New workers cannot be created after the start() has been called- Parameters:
taskQueue
- task queue name worker uses to poll. It uses this name for both workflow and activity task queue polls.- Returns:
- Worker
-
newWorker
public Worker newWorker(java.lang.String taskQueue, WorkerOptions options)
Creates worker that connects to an instance of the Temporal Service. It uses the namespace configured at the Factory level. New workers cannot be created after the start() has been called- Parameters:
taskQueue
- task queue name worker uses to poll. It uses this name for both workflow and activity task queue polls.options
- Options (likeDataConverter
override) for configuring worker.- Returns:
- Worker
-
getWorker
public Worker getWorker(java.lang.String taskQueue)
- Parameters:
taskQueue
- task queue name to lookup an existing worker for- Returns:
- a worker created previously through
newWorker(String)
for the given task queue. - Throws:
java.lang.IllegalStateException
- if the worker has not been registered for the given task queue.
-
tryGetWorker
@Nullable public Worker tryGetWorker(@Nonnull java.lang.String taskQueue)
- Parameters:
taskQueue
- task queue name to lookup an existing worker for- Returns:
- a worker created previously through
newWorker(String)
for the given task queue or null.
-
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 Temporal client that this worker factory uses.
-
shutdown
public void shutdown()
Initiates an orderly shutdown in which polls are stopped and already received workflow and activity tasks are executed.
After the shutdown, calls toActivityExecutionContext.heartbeat(Object)
start throwingActivityWorkerShutdownException
.
This method does not wait for the shutdown to complete. UseawaitTermination(long, TimeUnit)
to do that.
Invocation has no additional effect if already shut down.
-
shutdownNow
public void shutdownNow()
Initiates an orderly shutdown in which polls are stopped and already received workflow 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.
After the shutdownNow calls toActivityExecutionContext.heartbeat(Object)
start throwingActivityWorkerShutdownException
.
This method does not wait for the shutdown to complete. UseawaitTermination(long, TimeUnit)
to do that.
Invocation has no additional effect if already shut down.
-
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.
-
suspendPolling
public void suspendPolling()
-
resumePolling
public void resumePolling()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-