Class SimplePlugin.Builder

  • Enclosing class:
    SimplePlugin

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

      • initializeWorker

        public SimplePlugin.Builder initializeWorker​(@Nonnull
                                                     java.util.function.BiConsumer<java.lang.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
                                                  java.util.function.BiConsumer<java.lang.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
      • onWorkerFactoryStart

        public SimplePlugin.Builder onWorkerFactoryStart​(@Nonnull
                                                         java.util.function.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
                                                            java.util.function.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
                                                              java.util.function.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
                                                           java.util.function.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​(java.lang.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​(java.lang.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
                                                                       java.lang.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