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;
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations