Examples of RuntimeEnvironmentBuilder


Examples of org.kie.api.runtime.manager.RuntimeEnvironmentBuilder

public class KieRuntimeManagerFactoryBean {

    public static Object createRuntime(String type, String asset, String assetType){

        RuntimeEnvironmentBuilder builder;
        RuntimeEnvironment environment;
        RuntimeManager manager;

        if ("empty".equalsIgnoreCase(type)) {
            builder = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder();
        } else if ("default".equalsIgnoreCase(type)) {
            builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder();
        } else if ("defaultInMemory".equalsIgnoreCase(type)) {
            builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder();
        } else {
            throw new IllegalArgumentException("Could not find a RuntimeManager for the type : " + type);
        }

        // Add asset(s)
        if (assetType.equals(ResourceType.BPMN2.getName())){
        builder.addAsset(ResourceFactory.newClassPathResource(asset), ResourceType.BPMN2);
        } else {
            throw new IllegalArgumentException("Asset is not of type BPMN2");
        }

        // Get RuntimeEnvironment
        environment = builder.get();

        // Create Singleton RuntimeManager
        // TODO Allow to create Singleton, PerProcess or PerRequest
        manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
View Full Code Here

Examples of org.kie.api.runtime.manager.RuntimeEnvironmentBuilder

    private GlobalSchedulerService schedulerService;
    private boolean pessimisticLocking = false;

    @Override
    public Object getObject() throws Exception {
        RuntimeEnvironmentBuilder builder = null;

        RuntimeEnvironmentBuilderFactory factory = RuntimeEnvironmentBuilder.Factory.get();

        if (type.equalsIgnoreCase(TYPE_EMPTY)) {
            builder = factory.newEmptyBuilder();
        } else if (type.equalsIgnoreCase(TYPE_DEFAULT_IN_MEMORY)) {
            builder = factory.newDefaultInMemoryBuilder();
        } else if (type.equalsIgnoreCase(TYPE_DEFAULT)) {
            builder = factory.newDefaultBuilder();
        } else if (type.equalsIgnoreCase(TYPE_DEFAULT_KJAR)) {
            if (releaseId != null) {
                builder = factory.newDefaultBuilder(releaseId, kbaseName, ksessionName);
            } else {
                builder = factory.newDefaultBuilder(groupId, artifactId, version, kbaseName, ksessionName);
            }
        } else if (type.equalsIgnoreCase(TYPE_DEFAULT_KJAR_CL)) {
            builder = factory.newClasspathKmoduleDefaultBuilder(kbaseName, ksessionName);
        } else {
            throw new IllegalArgumentException("Unknown type of environment");
        }

        // apply all known properties
        builder
        .entityManagerFactory(entityManagerFactory)
        .knowledgeBase(knowledgeBase)
        .classLoader(classLoader)
        .schedulerService(schedulerService)
        .userGroupCallback(userGroupCallback)
        .registerableItemsFactory(registerableItemsFactory);

        // common environment entries
        builder.addEnvironmentEntry("org.kie.api.task.TaskService", taskService);
        builder.addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, transactionManager);
        builder.addEnvironmentEntry(EnvironmentName.TASK_USER_GROUP_CALLBACK, userGroupCallback);
        builder.addEnvironmentEntry(EnvironmentName.TASK_USER_INFO, userInfo);
        if (entityManager != null) {
            builder.addEnvironmentEntry(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, entityManager)
            .addEnvironmentEntry(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, entityManager)
            .addEnvironmentEntry("IS_JTA_TRANSACTION", false)
            .addEnvironmentEntry("IS_SHARED_ENTITY_MANAGER", true);
        }
        if( pessimisticLocking ) {
            builder.addEnvironmentEntry(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
        }

        // apply configuration if any
        if (configuration != null) {
            for (Map.Entry<String, String> entry : configuration.entrySet()) {
                builder.addConfiguration(entry.getKey(), entry.getValue());
            }
        }

        // apply environment entries if any
        if (environmentEntries != null) {
            for (Map.Entry<String, Object> entry : environmentEntries.entrySet()) {
                builder.addEnvironmentEntry(entry.getKey(), entry.getValue());
            }
        }

        // apply assets if kbase was not given
        if (knowledgeBase == null && assets != null) {
            for (Map.Entry<Resource, ResourceType> entry : assets.entrySet()) {
                builder.addAsset(entry.getKey(), entry.getValue());
            }
        }

        return builder.get();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.