Search in sources :

Example 1 with TimerInstance

use of org.jbpm.services.api.admin.TimerInstance in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest method testUpdateTimerRelative.

@Test(timeout = 10000)
public void testUpdateTimerRelative() throws Exception {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "IntermediateCatchEvent");
    assertNotNull(processInstanceId);
    long scheduleTime = System.currentTimeMillis();
    Collection<NodeInstanceDesc> activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc active = activeNodes.iterator().next();
    assertEquals("timer", active.getName());
    Collection<TimerInstance> timers = processAdminService.getTimerInstances(processInstanceId);
    assertNotNull(timers);
    assertEquals(1, timers.size());
    TimerInstance timer = timers.iterator().next();
    assertNotNull(timer.getActivationTime());
    assertNotNull(timer.getDelay());
    assertNotNull(timer.getNextFireTime());
    assertNotNull(timer.getProcessInstanceId());
    assertNotNull(timer.getSessionId());
    assertNotNull(timer.getTimerId());
    assertNotNull(timer.getTimerName());
    // thread sleep to test the different in the time timer spent after upgrade
    // not to wait for any job to be done
    Thread.sleep(1000);
    processAdminService.updateTimerRelative(processInstanceId, timer.getTimerId(), 3, 0, 0);
    CountDownListenerFactory.getExisting("processAdminService").waitTillCompleted();
    long fireTime = System.currentTimeMillis();
    // since the update of timer was relative (to current time) then it must wait at least 3 secs
    long expirationTime = fireTime - scheduleTime;
    assertTrue(expirationTime > 3000);
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    processInstanceId = null;
}
Also used : TimerInstance(org.jbpm.services.api.admin.TimerInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 2 with TimerInstance

use of org.jbpm.services.api.admin.TimerInstance in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest method testUpdateTimer.

@Test(timeout = 10000)
public void testUpdateTimer() throws Exception {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "IntermediateCatchEvent");
    assertNotNull(processInstanceId);
    long scheduleTime = System.currentTimeMillis();
    Collection<NodeInstanceDesc> activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc active = activeNodes.iterator().next();
    assertEquals("timer", active.getName());
    Collection<TimerInstance> timers = processAdminService.getTimerInstances(processInstanceId);
    assertNotNull(timers);
    assertEquals(1, timers.size());
    TimerInstance timer = timers.iterator().next();
    assertNotNull(timer.getActivationTime());
    assertNotNull(timer.getDelay());
    assertNotNull(timer.getNextFireTime());
    assertNotNull(timer.getProcessInstanceId());
    assertNotNull(timer.getSessionId());
    assertNotNull(timer.getTimerId());
    assertNotNull(timer.getTimerName());
    // thread sleep to test the different in the time timer spent after upgrade
    // not to wait for any job to be done
    Thread.sleep(1000);
    processAdminService.updateTimer(processInstanceId, timer.getTimerId(), 3, 0, 0);
    CountDownListenerFactory.getExisting("processAdminService").waitTillCompleted();
    long fireTime = System.currentTimeMillis();
    long expirationTime = fireTime - scheduleTime;
    // since the update of timer was including time already spent (thread sleep above) then it must wait less than 4 secs
    assertTrue(expirationTime < 4000);
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    processInstanceId = null;
}
Also used : TimerInstance(org.jbpm.services.api.admin.TimerInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 3 with TimerInstance

use of org.jbpm.services.api.admin.TimerInstance in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImpl method getTimerInstances.

@Override
public Collection<TimerInstance> getTimerInstances(long processInstanceId) throws ProcessInstanceNotFoundException {
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    if (pi == null) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
    }
    Collection<TimerInstance> timers = processService.execute(pi.getDeploymentId(), ProcessInstanceIdContext.get(processInstanceId), new ListTimersCommand(processInstanceId));
    return timers;
}
Also used : TimerInstance(org.jbpm.services.api.admin.TimerInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) ListTimersCommand(org.jbpm.kie.services.impl.admin.commands.ListTimersCommand) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 4 with TimerInstance

use of org.jbpm.services.api.admin.TimerInstance in project jbpm by kiegroup.

the class ListTimersCommand method processNodeInstance.

protected void processNodeInstance(TimerManager tm, NodeInstanceContainer container, List<TimerInstance> timers) {
    for (NodeInstance nodeInstance : container.getNodeInstances()) {
        if (nodeInstance instanceof TimerNodeInstance) {
            TimerNodeInstance tni = (TimerNodeInstance) nodeInstance;
            org.jbpm.process.instance.timer.TimerInstance timer = tm.getTimerMap().get(tni.getTimerId());
            TimerInstanceImpl details = buildTimer(timer);
            details.setTimerName(resolveVariable(tni.getNodeName(), tni));
            timers.add(details);
        } else if (nodeInstance instanceof StateBasedNodeInstance) {
            StateBasedNodeInstance sbni = (StateBasedNodeInstance) nodeInstance;
            List<Long> timerList = sbni.getTimerInstances();
            if (timerList != null) {
                for (Long timerId : timerList) {
                    org.jbpm.process.instance.timer.TimerInstance timer = tm.getTimerMap().get(timerId);
                    TimerInstanceImpl details = buildTimer(timer);
                    details.setTimerName(resolveVariable(sbni.getNodeName(), sbni));
                    timers.add(details);
                }
            }
        }
        if (nodeInstance instanceof NodeInstanceContainer) {
            processNodeInstance(tm, (NodeInstanceContainer) nodeInstance, timers);
        }
    }
}
Also used : StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) TimerInstance(org.jbpm.services.api.admin.TimerInstance) ArrayList(java.util.ArrayList) List(java.util.List) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) TimerInstanceImpl(org.jbpm.kie.services.impl.admin.TimerInstanceImpl)

Example 5 with TimerInstance

use of org.jbpm.services.api.admin.TimerInstance in project jbpm by kiegroup.

the class ListTimersCommand method execute.

public List<TimerInstance> execute(Context context) {
    List<TimerInstance> timers = new ArrayList<TimerInstance>();
    KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
    TimerManager tm = getTimerManager(kieSession);
    RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, true);
    if (wfp == null) {
        throw new ProcessInstanceNotFoundException("No process instance can be found for id " + processInstanceId);
    }
    processNodeInstance(tm, wfp, timers);
    return timers;
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) TimerInstance(org.jbpm.services.api.admin.TimerInstance) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) TimerManager(org.jbpm.process.instance.timer.TimerManager) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Aggregations

TimerInstance (org.jbpm.services.api.admin.TimerInstance)5 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)3 ArrayList (java.util.ArrayList)2 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)2 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)2 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)2 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)2 Test (org.junit.Test)2 List (java.util.List)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 TimerInstanceImpl (org.jbpm.kie.services.impl.admin.TimerInstanceImpl)1 ListTimersCommand (org.jbpm.kie.services.impl.admin.commands.ListTimersCommand)1 TimerManager (org.jbpm.process.instance.timer.TimerManager)1 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)1 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)1 StateBasedNodeInstance (org.jbpm.workflow.instance.node.StateBasedNodeInstance)1 TimerNodeInstance (org.jbpm.workflow.instance.node.TimerNodeInstance)1 KieSession (org.kie.api.runtime.KieSession)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1