Search in sources :

Example 1 with RuntimeEngineImpl

use of org.jbpm.runtime.manager.impl.RuntimeEngineImpl in project jbpm by kiegroup.

the class InjectableRegisterableItemsFactory method getGlobals.

@Override
public Map<String, Object> getGlobals(RuntimeEngine runtime) {
    Map<String, Object> globals = new HashMap<String, Object>();
    RuntimeManager manager = ((RuntimeEngineImpl) runtime).getManager();
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ksession", runtime.getKieSession());
    parameters.put("taskService", runtime.getTaskService());
    parameters.put("runtimeManager", manager);
    parameters.put("kieContainer", getRuntimeManager().getKieContainer());
    try {
        parameters.put("executorService", executorService.get());
    } catch (Exception e) {
        logger.debug("Executor service not available due to {}", e.getMessage());
    }
    try {
        for (GlobalProducer producer : globalProducer) {
            globals.putAll(producer.getGlobals(manager.getIdentifier(), parameters));
        }
    } catch (Exception e) {
        // do nothing as work item handler is considered optional
        logger.warn("Exception while evalutating globals prodcuers {}", e.getMessage());
    }
    // add globals from descriptor
    globals.putAll(getGlobalsFromDescriptor(runtime));
    return globals;
}
Also used : GlobalProducer(org.kie.internal.runtime.manager.GlobalProducer) HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) RuntimeEngineImpl(org.jbpm.runtime.manager.impl.RuntimeEngineImpl) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) IOException(java.io.IOException)

Example 2 with RuntimeEngineImpl

use of org.jbpm.runtime.manager.impl.RuntimeEngineImpl in project jbpm by kiegroup.

the class InjectableRegisterableItemsFactory method getWorkItemHandlers.

@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
    Map<String, WorkItemHandler> handler = new HashMap<String, WorkItemHandler>();
    handler.put("Human Task", getHTWorkItemHandler(runtime));
    RuntimeManager manager = ((RuntimeEngineImpl) runtime).getManager();
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ksession", runtime.getKieSession());
    parameters.put("taskService", runtime.getTaskService());
    parameters.put("runtimeManager", manager);
    parameters.put("kieContainer", getRuntimeManager().getKieContainer());
    try {
        parameters.put("executorService", executorService.get());
    } catch (Exception e) {
        logger.debug("Executor service not available due to {}", e.getMessage());
    }
    if (kieContainer != null) {
        // add classloader as one of the parameters so it can be easily referenced
        parameters.put("classLoader", kieContainer.getClassLoader());
        KieSessionModel ksessionModel = null;
        if (StringUtils.isEmpty(ksessionName)) {
            ksessionModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieSession();
            if (ksessionModel == null) {
                ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(DEFAULT_KIE_SESSION);
            }
        } else {
            ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(ksessionName);
        }
        if (ksessionModel == null) {
            throw new IllegalStateException("Cannot find ksession, either it does not exist or there are multiple default ksession in kmodule.xml");
        }
        try {
            InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession(), parameters);
        } catch (Throwable e) {
            // use fallback mechanism
            InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession());
        }
    }
    try {
        for (WorkItemHandlerProducer producer : workItemHandlerProducer) {
            handler.putAll(producer.getWorkItemHandlers(manager.getIdentifier(), parameters));
        }
    } catch (Exception e) {
        // do nothing as work item handler is considered optional
        logger.warn("Exception while evalutating work item handler prodcuers {}", e.getMessage());
    }
    // add handlers from descriptor
    handler.putAll(getWorkItemHandlersFromDescriptor(runtime));
    return handler;
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) RuntimeEngineImpl(org.jbpm.runtime.manager.impl.RuntimeEngineImpl) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) IOException(java.io.IOException) KieSessionModel(org.kie.api.builder.model.KieSessionModel) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) WorkItemHandlerProducer(org.kie.internal.runtime.manager.WorkItemHandlerProducer)

Aggregations

IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)2 RuntimeEngineImpl (org.jbpm.runtime.manager.impl.RuntimeEngineImpl)2 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)2 KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)1 KieSessionModel (org.kie.api.builder.model.KieSessionModel)1 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)1 GlobalProducer (org.kie.internal.runtime.manager.GlobalProducer)1 WorkItemHandlerProducer (org.kie.internal.runtime.manager.WorkItemHandlerProducer)1