use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.
the class GlobalJPATimerJobFactoryManager method createTimerJobInstance.
public TimerJobInstance createTimerJobInstance(Job job, JobContext ctx, Trigger trigger, JobHandle handle, InternalSchedulerService scheduler) {
long sessionId = -1;
if (ctx instanceof ProcessJobContext) {
sessionId = ((ProcessJobContext) ctx).getSessionId();
Map<Long, TimerJobInstance> instances = timerInstances.get(sessionId);
if (instances == null) {
instances = new ConcurrentHashMap<Long, TimerJobInstance>();
timerInstances.put(sessionId, instances);
}
}
ctx.setJobHandle(handle);
GlobalJpaTimerJobInstance jobInstance = new GlobalJpaTimerJobInstance(new SelfRemovalJob(job), new SelfRemovalJobContext(ctx, emptyStore), trigger, handle, scheduler);
return jobInstance;
}
use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.
the class ThreadPoolSchedulerService method scheduleJob.
@Override
public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) {
Date date = trigger.hasNextFireTime();
if (date != null) {
String jobname = null;
if (ctx instanceof ProcessJobContext) {
ProcessJobContext processCtx = (ProcessJobContext) ctx;
jobname = processCtx.getSessionId() + "-" + processCtx.getProcessInstanceId() + "-" + processCtx.getTimer().getId();
if (processCtx instanceof StartProcessJobContext) {
jobname = "StartProcess-" + ((StartProcessJobContext) processCtx).getProcessId() + "-" + processCtx.getTimer().getId();
}
if (activeTimer.containsKey(jobname)) {
return activeTimer.get(jobname);
}
}
GlobalJDKJobHandle jobHandle = new GlobalJDKJobHandle(idCounter.getAndIncrement());
TimerJobInstance jobInstance = globalTimerService.getTimerJobFactoryManager().createTimerJobInstance(job, ctx, trigger, jobHandle, (InternalSchedulerService) globalTimerService);
jobHandle.setTimerJobInstance((TimerJobInstance) jobInstance);
interceptor.internalSchedule((TimerJobInstance) jobInstance);
if (jobname != null) {
activeTimer.put(jobname, jobHandle);
}
return jobHandle;
} else {
return null;
}
}
use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestServiceRollback() throws Exception {
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
long ksessionId = ksession.getIdentifier();
ProcessInstance processInstance;
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
processInstance = ksession.startProcess("IntermediateCatchEvent");
} finally {
ut.rollback();
}
manager.disposeRuntimeEngine(runtime);
try {
// two types of checks as different managers will treat it differently
// per process instance will fail on getting runtime
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
// where singleton and per request will return runtime but there should not be process instance
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
}
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
if (runtime != null) {
manager.disposeRuntimeEngine(runtime);
}
}
use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateBoundaryTimerWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateBoundaryTimerWithGlobalTestServiceRollback() throws Exception {
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/HumanTaskWithBoundaryTimer.bpmn"), 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();
ProcessInstance processInstance;
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
processInstance = ksession.startProcess("PROCESS_1", params);
} finally {
ut.rollback();
}
manager.disposeRuntimeEngine(runtime);
try {
// two types of checks as different managers will treat it differently
// per process instance will fail on getting runtime
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
// where singleton and per request will return runtime but there should not be process instance
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
}
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
if (runtime != null) {
manager.disposeRuntimeEngine(runtime);
}
}
use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.
the class GlobalTimerServiceVolumeTest method testRuntimeManagerStrategyWithTimerService.
@Test(timeout = 30000)
public void testRuntimeManagerStrategyWithTimerService() throws Exception {
// prepare task service with users and groups
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
TaskService taskService = engine.getTaskService();
Group grouphr = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) grouphr).setId("HR");
Group groupadmins = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) groupadmins).setId("Administrators");
User mary = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) mary).setId("mary");
User john = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) john).setId("john");
User admin = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) admin).setId("Administrator");
((InternalTaskService) taskService).addGroup(grouphr);
((InternalTaskService) taskService).addGroup(groupadmins);
((InternalTaskService) taskService).addUser(mary);
((InternalTaskService) taskService).addUser(john);
((InternalTaskService) taskService).addUser(admin);
manager.disposeRuntimeEngine(engine);
int counter = numberOfProcesses;
// start processes until oom
while (counter > 0) {
new GlobalTimerServiceVolumeTest.StartProcessPerProcessInstanceRunnable(manager).run();
counter--;
}
Collection<TimerJobInstance> timers = null;
Map<Long, List<GlobalJobHandle>> jobs = null;
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null) {
if (timerService instanceof GlobalTimerService) {
jobs = ((GlobalTimerService) timerService).getTimerJobsPerSession();
timers = ((GlobalTimerService) timerService).getTimerJobFactoryManager().getTimerJobInstances();
}
}
assertNotNull("Jobs should not be null as number of timers have been created", jobs);
assertEquals("There should be no jobs in the global timer service", 0, jobs.size());
assertNotNull("Timer instances should not be null as number of timers have been created", timers);
assertEquals("There should be no timer instances in the global timer service manager", 0, timers.size());
RuntimeEngine empty = manager.getRuntimeEngine(EmptyContext.get());
AuditService logService = empty.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertEquals("Active process instances should be " + numberOfProcesses, numberOfProcesses, logs.size());
countDownListener.waitTillCompleted();
List<TaskSummary> tasks = empty.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals("Number of John's tasks should be " + numberOfProcesses, numberOfProcesses, tasks.size());
for (TaskSummary task : tasks) {
RuntimeEngine piEngine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
piEngine.getTaskService().start(task.getId(), "john");
piEngine.getTaskService().complete(task.getId(), "john", null);
manager.disposeRuntimeEngine(piEngine);
}
logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertEquals("Active process instances should be 0", 0, logs.size());
logService.dispose();
manager.disposeRuntimeEngine(empty);
}
Aggregations