Class SimplePlugin
- java.lang.Object
-
- io.temporal.common.SimplePlugin
-
- All Implemented Interfaces:
ScheduleClientPlugin,WorkflowClientPlugin,io.temporal.serviceclient.WorkflowServiceStubsPlugin,WorkerPlugin
@Experimental public abstract class SimplePlugin extends java.lang.Object implements io.temporal.serviceclient.WorkflowServiceStubsPlugin, WorkflowClientPlugin, ScheduleClientPlugin, WorkerPlugin
A plugin that implementsWorkflowServiceStubsPlugin,WorkflowClientPlugin,ScheduleClientPlugin, andWorkerPlugin. This class can be used in two ways:- Builder pattern: Use
newBuilder(String)to declaratively configure a plugin with callbacks - Subclassing: Extend this class and override specific methods for custom behavior
Builder Pattern Example
SimplePlugin myPlugin = SimplePlugin.newBuilder("my-plugin") .addWorkerInterceptors(new TracingInterceptor()) .addClientInterceptors(new LoggingInterceptor()) .customizeDataConverter(existing -> new CodecDataConverter(existing, myCodec)) .build();Subclassing Example
{@code public class TracingPlugin extends SimplePlugin { private final Tracer tracer; public TracingPlugin(Tracer tracer) { super("io.temporal.tracing"); this.tracer = tracer; }- See Also:
WorkflowServiceStubsPlugin,WorkflowClientPlugin,ScheduleClientPlugin,WorkerPlugin
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSimplePlugin.BuilderBuilder for creatingSimplePlugininstances with declarative configuration.-
Nested classes/interfaces inherited from interface io.temporal.worker.WorkerPlugin
WorkerPlugin.ReplayCallback
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSimplePlugin(SimplePlugin.Builder builder)Creates a new plugin from a builder.protectedSimplePlugin(java.lang.String name)Creates a new plugin with the specified name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureScheduleClient(ScheduleClientOptions.Builder builder)Allows the plugin to modify schedule client options before the client is created.voidconfigureServiceStubs(io.temporal.serviceclient.WorkflowServiceStubsOptions.Builder builder)voidconfigureWorker(java.lang.String taskQueue, WorkerOptions.Builder builder)Allows the plugin to modify worker options before a worker is created.voidconfigureWorkerFactory(WorkerFactoryOptions.Builder builder)Allows the plugin to modify worker factory options before the factory is created.voidconfigureWorkflowClient(WorkflowClientOptions.Builder builder)Allows the plugin to modify workflow client options before the client is created.io.temporal.serviceclient.WorkflowServiceStubsconnectServiceClient(io.temporal.serviceclient.WorkflowServiceStubsOptions options, java.util.function.Supplier<io.temporal.serviceclient.WorkflowServiceStubs> next)java.lang.StringgetName()Returns a unique name for this plugin.voidinitializeWorker(java.lang.String taskQueue, Worker worker)Called after a worker is created, allowing plugins to register workflows, activities, Nexus services, and other components on the worker.static SimplePlugin.BuildernewBuilder(java.lang.String name)Creates a new builder with the specified plugin name.voidreplayWorkflowExecution(Worker worker, WorkflowExecutionHistory history, WorkerPlugin.ReplayCallback next)Allows the plugin to wrap workflow execution replay.voidshutdownWorker(java.lang.String taskQueue, Worker worker, java.util.function.BiConsumer<java.lang.String,Worker> next)Allows the plugin to wrap individual worker shutdown.voidshutdownWorkerFactory(WorkerFactory factory, java.util.function.Consumer<WorkerFactory> next)Allows the plugin to wrap worker factory shutdown.voidstartWorker(java.lang.String taskQueue, Worker worker, java.util.function.BiConsumer<java.lang.String,Worker> next)Allows the plugin to wrap individual worker startup.voidstartWorkerFactory(WorkerFactory factory, java.util.function.Consumer<WorkerFactory> next)Allows the plugin to wrap worker factory startup.java.lang.StringtoString()
-
-
-
Constructor Detail
-
SimplePlugin
protected SimplePlugin(@Nonnull java.lang.String name)Creates a new plugin with the specified name. Use this constructor when subclassing to override specific methods.- Parameters:
name- a unique name for this plugin, used for logging and duplicate detection. Recommended format: "organization.plugin-name" (e.g., "io.temporal.tracing")- Throws:
java.lang.NullPointerException- if name is null
-
SimplePlugin
protected SimplePlugin(@Nonnull SimplePlugin.Builder builder)Creates a new plugin from a builder. Use this constructor when subclassing to combine builder configuration with method overrides.- Parameters:
builder- the builder with configuration- Throws:
java.lang.NullPointerException- if builder is null
-
-
Method Detail
-
newBuilder
public static SimplePlugin.Builder newBuilder(@Nonnull java.lang.String name)
Creates a new builder with the specified plugin name.- Parameters:
name- a unique name for the plugin, used for logging and duplicate detection. Recommended format: "organization.plugin-name" (e.g., "my-org.tracing")- Returns:
- a new builder instance
-
getName
@Nonnull public java.lang.String getName()
Description copied from interface:WorkflowClientPluginReturns a unique name for this plugin. Used for logging and duplicate detection. Recommended format: "organization.plugin-name" (e.g., "io.temporal.tracing")- Specified by:
getNamein interfaceScheduleClientPlugin- Specified by:
getNamein interfaceWorkerPlugin- Specified by:
getNamein interfaceWorkflowClientPlugin- Specified by:
getNamein interfaceio.temporal.serviceclient.WorkflowServiceStubsPlugin- Returns:
- fully qualified plugin name
-
configureServiceStubs
public void configureServiceStubs(@Nonnull io.temporal.serviceclient.WorkflowServiceStubsOptions.Builder builder)- Specified by:
configureServiceStubsin interfaceio.temporal.serviceclient.WorkflowServiceStubsPlugin
-
configureWorkflowClient
public void configureWorkflowClient(@Nonnull WorkflowClientOptions.Builder builder)Description copied from interface:WorkflowClientPluginAllows the plugin to modify workflow client options before the client is created. Called during configuration phase in forward (registration) order.- Specified by:
configureWorkflowClientin interfaceWorkflowClientPlugin- Parameters:
builder- the options builder to modify
-
configureScheduleClient
public void configureScheduleClient(@Nonnull ScheduleClientOptions.Builder builder)Description copied from interface:ScheduleClientPluginAllows the plugin to modify schedule client options before the client is created. Called during configuration phase in forward (registration) order.- Specified by:
configureScheduleClientin interfaceScheduleClientPlugin- Parameters:
builder- the options builder to modify
-
configureWorkerFactory
public void configureWorkerFactory(@Nonnull WorkerFactoryOptions.Builder builder)Description copied from interface:WorkerPluginAllows the plugin to modify worker factory options before the factory is created. Called during configuration phase in forward (registration) order.- Specified by:
configureWorkerFactoryin interfaceWorkerPlugin- Parameters:
builder- the options builder to modify
-
configureWorker
public void configureWorker(@Nonnull java.lang.String taskQueue, @Nonnull WorkerOptions.Builder builder)Description copied from interface:WorkerPluginAllows the plugin to modify worker options before a worker is created. Called during configuration phase in forward (registration) order.- Specified by:
configureWorkerin interfaceWorkerPlugin- Parameters:
taskQueue- the task queue name for the worker being createdbuilder- the options builder to modify
-
initializeWorker
public void initializeWorker(@Nonnull java.lang.String taskQueue, @Nonnull Worker worker)Description copied from interface:WorkerPluginCalled after a worker is created, allowing plugins to register workflows, activities, Nexus services, and other components on the worker.This method is called in forward (registration) order immediately after the worker is created in
WorkerFactory.newWorker(java.lang.String). This is the appropriate place for registrations because it is called before the worker starts polling.Example:
{@code- Specified by:
initializeWorkerin interfaceWorkerPlugin- Parameters:
taskQueue- the task queue name for the workerworker- the newly created worker
-
startWorker
public void startWorker(@Nonnull java.lang.String taskQueue, @Nonnull Worker worker, @Nonnull java.util.function.BiConsumer<java.lang.String,Worker> next)Description copied from interface:WorkerPluginAllows the plugin to wrap individual worker startup. Called during execution phase in reverse order (first plugin wraps all others) whenWorkerFactory.start()is invoked.This method is called for each worker when the factory starts. Use this for per-worker resource initialization, logging, or metrics. Note that workflow/activity registration should be done in
WorkerPlugin.initializeWorker(java.lang.String, io.temporal.worker.Worker)instead, as this method is called after registrations are finalized.Example:
{@code- Specified by:
startWorkerin interfaceWorkerPlugin- Parameters:
taskQueue- the task queue name for the workerworker- the worker being startednext- callback that starts the next in chain (eventually starts the actual worker)
-
shutdownWorker
public void shutdownWorker(@Nonnull java.lang.String taskQueue, @Nonnull Worker worker, @Nonnull java.util.function.BiConsumer<java.lang.String,Worker> next)Description copied from interface:WorkerPluginAllows the plugin to wrap individual worker shutdown. Called during shutdown phase in reverse order (first plugin wraps all others) whenWorkerFactory.shutdown()orWorkerFactory.shutdownNow()is invoked.This method is called for each worker when the factory shuts down. Use this for per-worker resource cleanup that was initialized in
WorkerPlugin.startWorker(java.lang.String, io.temporal.worker.Worker, java.util.function.BiConsumer<java.lang.String, io.temporal.worker.Worker>)orWorkerPlugin.initializeWorker(java.lang.String, io.temporal.worker.Worker).Warning: Exceptions thrown from this method will propagate up and may halt the shutdown process. Plugin authors should handle exceptions appropriately and ensure
nextis called exactly once. If cleanup code may throw, consider wrapping it in a try-catch to ensure graceful degradation.Example:
{@code- Specified by:
shutdownWorkerin interfaceWorkerPlugin- Parameters:
taskQueue- the task queue name for the workerworker- the worker being shut downnext- callback that shuts down the next in chain (eventually shuts down the actual worker)
-
connectServiceClient
public io.temporal.serviceclient.WorkflowServiceStubs connectServiceClient(io.temporal.serviceclient.WorkflowServiceStubsOptions options, java.util.function.Supplier<io.temporal.serviceclient.WorkflowServiceStubs> next)- Specified by:
connectServiceClientin interfaceio.temporal.serviceclient.WorkflowServiceStubsPlugin
-
startWorkerFactory
public void startWorkerFactory(WorkerFactory factory, java.util.function.Consumer<WorkerFactory> next)
Description copied from interface:WorkerPluginAllows the plugin to wrap worker factory startup. Called during execution phase in reverse order (first plugin wraps all others).This method is called when
WorkerFactory.start()is invoked. The plugin can perform setup before starting and cleanup logic.Example:
{@code- Specified by:
startWorkerFactoryin interfaceWorkerPlugin- Parameters:
factory- the worker factory being startednext- callback that starts the next in chain (eventually starts actual workers)
-
shutdownWorkerFactory
public void shutdownWorkerFactory(WorkerFactory factory, java.util.function.Consumer<WorkerFactory> next)
Description copied from interface:WorkerPluginAllows the plugin to wrap worker factory shutdown. Called during shutdown phase in reverse order (first plugin wraps all others).This method is called when
WorkerFactory.shutdown()orWorkerFactory.shutdownNow()is invoked. The plugin can perform actions before and after the actual shutdown occurs.Warning: Exceptions thrown from this method will propagate up and may halt the shutdown process. Plugin authors should handle exceptions appropriately and ensure
nextis called exactly once. If cleanup code may throw, consider wrapping it in a try-catch to ensure graceful degradation.Example:
{@code- Specified by:
shutdownWorkerFactoryin interfaceWorkerPlugin- Parameters:
factory- the worker factory being shut downnext- callback that shuts down the next in chain (eventually shuts down actual workers)
-
replayWorkflowExecution
public void replayWorkflowExecution(@Nonnull Worker worker, @Nonnull WorkflowExecutionHistory history, @Nonnull WorkerPlugin.ReplayCallback next) throws java.lang.ExceptionDescription copied from interface:WorkerPluginAllows the plugin to wrap workflow execution replay. Called in reverse order (first plugin wraps all others) when replaying a workflow history.This method allows plugins to perform setup/teardown around replay, add logging, metrics, or other observability for replay operations.
Example:
{@code- Specified by:
replayWorkflowExecutionin interfaceWorkerPlugin- Parameters:
worker- the worker performing the replayhistory- the workflow execution history being replayednext- callback that performs the next in chain (eventually performs the actual replay)- Throws:
java.lang.Exception- if replay fails
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-