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

io.github.factoryfx.copperbridge.TransientScottyEngineFactory Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.github.factoryfx.copperbridge;

import java.util.Collections;
import java.util.List;

import io.github.factoryfx.factory.attribute.dependency.FactoryAttribute;
import io.github.factoryfx.factory.attribute.primitive.IntegerAttribute;
import io.github.factoryfx.factory.FactoryBase;
import org.copperengine.core.EngineIdProvider;
import org.copperengine.core.common.DefaultProcessorPoolManager;
import org.copperengine.core.common.DefaultTicketPoolManager;
import org.copperengine.core.common.JdkRandomUUIDFactory;
import org.copperengine.core.common.ProcessorPoolManager;
import org.copperengine.core.monitoring.NullRuntimeStatisticsCollector;
import org.copperengine.core.tranzient.DefaultEarlyResponseContainer;
import org.copperengine.core.tranzient.DefaultTimeoutManager;
import org.copperengine.core.tranzient.TransientPriorityProcessorPool;
import org.copperengine.core.tranzient.TransientProcessorPool;
import org.copperengine.core.tranzient.TransientScottyEngine;
import org.copperengine.ext.wfrepo.classpath.ClasspathWorkflowRepository;


public abstract class TransientScottyEngineFactory> extends FactoryBase {

    public final FactoryAttribute> engineIdProviderFactory = new FactoryAttribute<>();
    public final IntegerAttribute threads = new IntegerAttribute().labelText("Number of processing threads");

    public abstract List getWorkflowClassPaths();

    public TransientScottyEngineFactory() {
        configLifeCycle().setCreator(this::createImpl);
        configLifeCycle().setStarter(TransientScottyEngine::startup);
        configLifeCycle().setDestroyer(TransientScottyEngine::shutdown);
    }

    public TransientScottyEngine createImpl() {
        TransientScottyEngine engine = new TransientScottyEngine();
        TransientProcessorPool processorPool = new TransientPriorityProcessorPool(TransientProcessorPool.DEFAULT_POOL_ID, threads.get());
        ProcessorPoolManager processorPoolManager = new DefaultProcessorPoolManager<>();
        processorPoolManager.setProcessorPools(Collections.singletonList(processorPool));

        engine.setEarlyResponseContainer(new DefaultEarlyResponseContainer());
        engine.setEngineIdProvider(engineIdProviderFactory.instance());
        engine.setIdFactory(new JdkRandomUUIDFactory());
        engine.setPoolManager(processorPoolManager);
        engine.setStatisticsCollector(new NullRuntimeStatisticsCollector());
        engine.setTicketPoolManager(new DefaultTicketPoolManager());
        engine.setTimeoutManager(new DefaultTimeoutManager());
        engine.setWfRepository(new ClasspathWorkflowRepository(getWorkflowClassPaths()));
        return engine;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy