Search in sources :

Example 1 with SingleSessionCommandService

use of org.drools.core.command.SingleSessionCommandService in project jbpm by kiegroup.

the class IntermediateEventTest method testEventTypesLifeCycle.

@Test
@RequirePersistence
public void testEventTypesLifeCycle() throws Exception {
    // JBPM-4246
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2");
    EntityManagerFactory separateEmf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
    Environment env = createEnvironment(separateEmf);
    ksession = createKnowledgeSession(kbase, null, env);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
    ksession.startProcess("BPMN2-IntermediateCatchSignalBetweenUserTasks");
    int signalListSize = ksession.execute(new ExecutableCommand<Integer>() {

        public Integer execute(Context context) {
            SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
            InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
            ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
            List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
            return processInstancesToSignalList.size();
        }
    });
    // Process instance is not waiting for signal
    assertThat(signalListSize).isEqualTo(0);
    ksession.getWorkItemManager().completeWorkItem(1, null);
    signalListSize = ksession.execute(new ExecutableCommand<Integer>() {

        public Integer execute(Context context) {
            SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
            InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
            ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
            List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
            return processInstancesToSignalList.size();
        }
    });
    // Process instance is waiting for signal now
    assertThat(signalListSize).isEqualTo(1);
    ksession.signalEvent("MySignal", null);
    signalListSize = ksession.execute(new ExecutableCommand<Integer>() {

        public Integer execute(Context context) {
            SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
            InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
            ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
            List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
            return processInstancesToSignalList.size();
        }
    });
    // Process instance is not waiting for signal
    assertThat(signalListSize).isEqualTo(0);
    ksession.getWorkItemManager().completeWorkItem(2, null);
    ksession.dispose();
    ksession = null;
    separateEmf.close();
}
Also used : RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) Context(org.kie.api.runtime.Context) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) SingleSessionCommandService(org.drools.core.command.SingleSessionCommandService) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) Environment(org.kie.api.runtime.Environment) ExecutableCommand(org.drools.core.command.impl.ExecutableCommand) List(java.util.List) ArrayList(java.util.ArrayList) ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 2 with SingleSessionCommandService

use of org.drools.core.command.SingleSessionCommandService in project jbpm by kiegroup.

the class ConcurrentGlobalTimerServiceTest method testStartProcess.

private void testStartProcess(RuntimeEngine runtime) throws Exception {
    synchronized ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) runtime.getKieSession()).getRunner()) {
        UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
        try {
            ut.begin();
            logger.debug("Starting process on ksession {}", runtime.getKieSession().getIdentifier());
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("x", "R2/PT1S");
            ProcessInstance processInstance = runtime.getKieSession().startProcess("IntermediateCatchEvent", params);
            logger.debug("Started process instance {} on ksession {}", processInstance.getId(), runtime.getKieSession().getIdentifier());
            ut.commit();
        } catch (Exception ex) {
            ut.rollback();
            throw ex;
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) HashMap(java.util.HashMap) SingleSessionCommandService(org.drools.core.command.SingleSessionCommandService) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InitialContext(javax.naming.InitialContext) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) OptimisticLockException(javax.persistence.OptimisticLockException) StaleObjectStateException(org.hibernate.StaleObjectStateException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with SingleSessionCommandService

use of org.drools.core.command.SingleSessionCommandService in project jbpm by kiegroup.

the class GlobalTimerServiceVolumeTest method testStartProcess.

private void testStartProcess(RuntimeEngine runtime) throws Exception {
    synchronized ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) runtime.getKieSession()).getRunner()) {
        UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
        try {
            ut.begin();
            logger.debug("Starting process on ksession {}", runtime.getKieSession().getIdentifier());
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("x", "5s");
            ProcessInstance processInstance = runtime.getKieSession().startProcess("IntermediateCatchEvent", params);
            logger.debug("Started process instance {} on ksession {}", processInstance.getId(), runtime.getKieSession().getIdentifier());
            ut.commit();
        } catch (Exception ex) {
            ut.rollback();
            throw ex;
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) HashMap(java.util.HashMap) SingleSessionCommandService(org.drools.core.command.SingleSessionCommandService) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InitialContext(javax.naming.InitialContext)

Aggregations

SingleSessionCommandService (org.drools.core.command.SingleSessionCommandService)3 HashMap (java.util.HashMap)2 InitialContext (javax.naming.InitialContext)2 UserTransaction (javax.transaction.UserTransaction)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)1 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)1 StaleObjectStateException (org.hibernate.StaleObjectStateException)1 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)1 ProcessPersistenceContext (org.jbpm.persistence.api.ProcessPersistenceContext)1 ProcessPersistenceContextManager (org.jbpm.persistence.api.ProcessPersistenceContextManager)1 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1