Class SimplePlugin.Builder

java.lang.Object
io.temporal.common.SimplePlugin.Builder
Enclosing class:
SimplePlugin

public static final class SimplePlugin.Builder extends Object
Builder for creating SimplePlugin instances with declarative configuration.
  • Method Details

    • initializeWorker

      public SimplePlugin.Builder initializeWorker(@Nonnull BiConsumer<String,Worker> initializer)
      Adds an initializer that is called after a worker is created. This can be used to register workflows, activities, and Nexus services on the worker.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .initializeWorker((taskQueue, worker) -> {
               worker.registerWorkflowImplementationTypes(MyWorkflow.class);
               worker.registerActivitiesImplementations(new MyActivityImpl());
           })
           .build();
       
      Parameters:
      initializer - a consumer that receives the task queue name and worker
      Returns:
      this builder for chaining
    • onWorkerStart

      public SimplePlugin.Builder onWorkerStart(@Nonnull BiConsumer<String,Worker> callback)
      Adds a callback that is invoked when a worker starts. This can be used to start per-worker resources or record metrics.

      Note: For registering workflows and activities, use initializeWorker(java.util.function.BiConsumer<java.lang.String, io.temporal.worker.Worker>) instead, as registrations must happen before the worker starts polling.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .onWorkerStart((taskQueue, worker) -> {
               logger.info("Worker started for task queue: {}", taskQueue);
               perWorkerResources.put(taskQueue, new ResourcePool());
           })
           .build();
       
      Parameters:
      callback - a consumer that receives the task queue name and worker when the worker starts
      Returns:
      this builder for chaining
    • onWorkerShutdown

      public SimplePlugin.Builder onWorkerShutdown(@Nonnull BiConsumer<String,Worker> callback)
      Adds a callback that is invoked when a worker shuts down. This can be used to clean up per-worker resources initialized in initializeWorker(java.util.function.BiConsumer<java.lang.String, io.temporal.worker.Worker>) or onWorkerStart(java.util.function.BiConsumer<java.lang.String, io.temporal.worker.Worker>).

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .onWorkerShutdown((taskQueue, worker) -> {
               logger.info("Worker shutting down for task queue: {}", taskQueue);
               ResourcePool pool = perWorkerResources.remove(taskQueue);
               if (pool != null) {
                   pool.close();
               }
           })
           .build();
       
      Parameters:
      callback - a consumer that receives the task queue name and worker when the worker shuts down
      Returns:
      this builder for chaining
    • onWorkerFactoryStart

      public SimplePlugin.Builder onWorkerFactoryStart(@Nonnull Consumer<WorkerFactory> callback)
      Adds a callback that is invoked when the worker factory starts. This can be used to initialize factory-level resources or record metrics.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .onWorkerFactoryStart(factory -> {
               logger.info("Worker factory started");
               globalResources.initialize();
           })
           .build();
       
      Parameters:
      callback - a consumer that receives the worker factory when it starts
      Returns:
      this builder for chaining
    • onWorkerFactoryShutdown

      public SimplePlugin.Builder onWorkerFactoryShutdown(@Nonnull Consumer<WorkerFactory> callback)
      Adds a callback that is invoked when the worker factory shuts down. This can be used to clean up factory-level resources.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .onWorkerFactoryShutdown(factory -> {
               logger.info("Worker factory shutting down");
               globalResources.cleanup();
           })
           .build();
       
      Parameters:
      callback - a consumer that receives the worker factory when it shuts down
      Returns:
      this builder for chaining
    • onReplayWorkflowExecution

      public SimplePlugin.Builder onReplayWorkflowExecution(@Nonnull BiConsumer<Worker,WorkflowExecutionHistory> callback)
      Adds a callback that is invoked after a workflow execution is replayed. This can be used for logging, metrics, or other observability around replay operations.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .onReplayWorkflowExecution((worker, history) -> {
               logger.info("Replayed workflow: {}", history.getWorkflowExecution().getWorkflowId());
           })
           .build();
       
      Parameters:
      callback - a consumer that receives the worker and history after replay completes
      Returns:
      this builder for chaining
    • addWorkerInterceptors

      public SimplePlugin.Builder addWorkerInterceptors(WorkerInterceptor... interceptors)
      Adds worker interceptors. Interceptors are appended to any existing interceptors in the configuration.
      Parameters:
      interceptors - the interceptors to add
      Returns:
      this builder for chaining
    • addClientInterceptors

      public SimplePlugin.Builder addClientInterceptors(WorkflowClientInterceptor... interceptors)
      Adds client interceptors. Interceptors are appended to any existing interceptors in the configuration.
      Parameters:
      interceptors - the interceptors to add
      Returns:
      this builder for chaining
    • addContextPropagators

      public SimplePlugin.Builder addContextPropagators(ContextPropagator... propagators)
      Adds context propagators. Propagators are appended to any existing propagators in the configuration.
      Parameters:
      propagators - the propagators to add
      Returns:
      this builder for chaining
    • customizeDataConverter

      public SimplePlugin.Builder customizeDataConverter(@Nonnull UnaryOperator<DataConverter> customizer)
      Sets a customizer for the data converter. The customizer receives the existing data converter and returns a new or modified data converter.

      This is useful for wrapping the existing data converter with additional functionality, such as adding a codec for encryption or compression.

      Example - wrapping with a codec:

      
       SimplePlugin.newBuilder("my-plugin")
           .customizeDataConverter(existing ->
               new CodecDataConverter(existing, Collections.singletonList(new MyCodec())))
           .build();
       

      Example - replacing entirely:

      
       SimplePlugin.newBuilder("my-plugin")
           .customizeDataConverter(existing -> myCustomDataConverter)
           .build();
       
      Parameters:
      customizer - a function that receives the existing data converter and returns the data converter to use
      Returns:
      this builder for chaining
    • registerWorkflowImplementationTypes

      public SimplePlugin.Builder registerWorkflowImplementationTypes(Class<?>... workflowImplementationTypes)
      Registers workflow implementation types. These workflows will be registered on all workers created by the factory.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .registerWorkflowImplementationTypes(MyWorkflowImpl.class, OtherWorkflowImpl.class)
           .build();
       
      Parameters:
      workflowImplementationTypes - workflow implementation classes to register
      Returns:
      this builder for chaining
    • registerActivitiesImplementations

      public SimplePlugin.Builder registerActivitiesImplementations(Object... activitiesImplementations)
      Registers activity implementations. These activities will be registered on all workers created by the factory.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .registerActivitiesImplementations(new MyActivityImpl(), new OtherActivityImpl())
           .build();
       
      Parameters:
      activitiesImplementations - activity implementation instances to register
      Returns:
      this builder for chaining
    • registerNexusServiceImplementation

      public SimplePlugin.Builder registerNexusServiceImplementation(@Nonnull Object nexusServiceImplementation)
      Registers a Nexus service implementation. The service will be registered on all workers created by the factory.

      Example:

      
       SimplePlugin.newBuilder("my-plugin")
           .registerNexusServiceImplementation(new MyNexusServiceImpl())
           .build();
       
      Parameters:
      nexusServiceImplementation - the Nexus service implementation to register
      Returns:
      this builder for chaining
    • build

      public SimplePlugin build()
      Builds the plugin with the configured settings.
      Returns:
      a new plugin instance