Search in sources :

Example 31 with TimerService

use of org.drools.core.time.TimerService in project jbpm by kiegroup.

the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback.

@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback() throws Exception {
    // prepare listener to assert results
    Properties properties = new Properties();
    properties.setProperty("mary", "HR");
    properties.setProperty("john", "HR");
    UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
    manager = getManager(environment, true);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    long ksessionId = ksession.getIdentifier();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "R3/PT1S");
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    // get tasks
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwnerByStatus("john", statuses, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    runtime.getTaskService().start(task.getId(), "john");
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    try {
        ut.begin();
        runtime.getTaskService().complete(task.getId(), "john", null);
    } finally {
        ut.rollback();
    }
    processInstance = ksession.getProcessInstance(processInstance.getId());
    Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertTrue(activeNodes.iterator().next() instanceof HumanTaskNodeInstance);
    TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
    assertNotNull(timerInstances);
    assertEquals(0, timerInstances.size());
    // clean up
    ksession.abortProcessInstance(processInstance.getId());
    manager.disposeRuntimeEngine(runtime);
}
Also used : Status(org.kie.api.task.model.Status) UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) TimerService(org.drools.core.time.TimerService) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 32 with TimerService

use of org.drools.core.time.TimerService in project jbpm by kiegroup.

the class AbstractRuntimeManager method close.

public void close(boolean removeJobs) {
    cacheManager.dispose();
    environment.close();
    registry.remove(identifier);
    TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    if (timerService != null) {
        try {
            if (removeJobs && timerService instanceof GlobalTimerService) {
                ((GlobalTimerService) timerService).destroy();
            }
            timerService.shutdown();
            GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService();
            if (schedulerService != null) {
                schedulerService.shutdown();
            }
        } finally {
            TimerServiceRegistry.getInstance().remove(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
        }
    }
    this.closed = true;
}
Also used : GlobalSchedulerService(org.jbpm.process.core.timer.GlobalSchedulerService) SchedulerProvider(org.jbpm.runtime.manager.api.SchedulerProvider) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Aggregations

TimerService (org.drools.core.time.TimerService)32 GlobalTimerService (org.jbpm.process.core.timer.impl.GlobalTimerService)11 JobHandle (org.drools.core.time.JobHandle)9 Test (org.junit.Test)9 LeftTuple (org.drools.core.reteoo.LeftTuple)6 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 ArrayList (java.util.ArrayList)4 EventFactHandle (org.drools.core.common.EventFactHandle)4 PropagationContext (org.drools.core.spi.PropagationContext)4 JobContext (org.drools.core.time.JobContext)4 Trigger (org.drools.core.time.Trigger)4 DefaultJobHandle (org.drools.core.time.impl.DefaultJobHandle)4 Timer (org.drools.core.time.impl.Timer)4 TimerJobInstance (org.drools.core.time.impl.TimerJobInstance)4 Calendars (org.kie.api.runtime.Calendars)4 KieSession (org.kie.api.runtime.KieSession)4 UserTransaction (javax.transaction.UserTransaction)3 SessionConfiguration (org.drools.core.SessionConfiguration)3 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3