Search in sources :

Example 21 with TimerService

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

the class GlobalQuartzDBTimerServiceTest method testContinueGlobalTestService.

/**
 * Test that illustrates that jobs are persisted and survives server restart
 * and as soon as GlobalTimerService is active jobs are fired
 * NOTE: this test is disabled by default as it requires real db (not in memory)
 * and test to be executed separately each with new jvm process
 */
@Test
@Ignore
public void testContinueGlobalTestService() throws Exception {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle2.bpmn2"), ResourceType.BPMN2).addConfiguration("drools.timerService", "org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate").get();
    RuntimeManager manger = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    // build GlobalTimerService instance
    TimerService globalTs = new GlobalTimerService(manger, globalScheduler);
    // and register it in the registry under 'default' key
    TimerServiceRegistry.getInstance().registerTimerService("default", globalTs);
    // prepare listener to assert results
    final List<Long> timerExporations = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("timer")) {
                timerExporations.add(event.getProcessInstance().getId());
            }
        }
    };
    Thread.sleep(5000);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 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 23 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)23 GlobalTimerService (org.jbpm.process.core.timer.impl.GlobalTimerService)11 Test (org.junit.Test)9 JobHandle (org.drools.core.time.JobHandle)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 ArrayList (java.util.ArrayList)4 Trigger (org.drools.core.time.Trigger)4 TimerJobInstance (org.drools.core.time.impl.TimerJobInstance)4 KieSession (org.kie.api.runtime.KieSession)4 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)4 UserTransaction (javax.transaction.UserTransaction)3 SessionConfiguration (org.drools.core.SessionConfiguration)3 LeftTuple (org.drools.core.reteoo.LeftTuple)3 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)3 Task (org.kie.api.task.model.Task)3 Disposable (org.kie.internal.runtime.manager.Disposable)3 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Properties (java.util.Properties)2