All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nflow.engine.guice.NflowController Maven / Gradle / Ivy

There is a newer version: 10.0.0
Show newest version
package io.nflow.engine.guice;

import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;

import io.nflow.engine.internal.executor.WorkflowLifecycle;
import io.nflow.engine.internal.workflow.MaintenanceWorkflowStarter;
import io.nflow.engine.service.WorkflowDefinitionService;
import io.nflow.engine.workflow.definition.AbstractWorkflowDefinition;

@Singleton
public class NflowController {
    private final WorkflowLifecycle lifecycle;
    private final WorkflowDefinitionService workflowDefinitionService;
    private final MaintenanceWorkflowStarter maintenanceWorkflowStarter;
    private final Set> workflows;

    @Inject
    public NflowController(WorkflowLifecycle lifecycle,
                           WorkflowDefinitionService workflowDefinitionService,
                           MaintenanceWorkflowStarter maintenanceWorkflowStarter,
                           Set> workflowDefinitions
    ) {
        this.lifecycle = lifecycle;
        this.workflowDefinitionService = workflowDefinitionService;
        this.maintenanceWorkflowStarter = maintenanceWorkflowStarter;
        this.workflows = workflowDefinitions;
    }

    public void start() {
        try {
            workflows.forEach(workflowDefinitionService::addWorkflowDefinition);
            maintenanceWorkflowStarter.start();
        } catch (Exception e) {
            throw new RuntimeException("Failed to register workflows", e);
        }
        lifecycle.start();
    }

    public void stop() {
        lifecycle.stop();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy