use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class SingletonRuntimeManagerTest method testEventSignalingBetweenProcesses.
@Test
public void testEventSignalingBetweenProcesses() {
final Map<String, Integer> processStates = new HashMap<String, Integer>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().persistence(false).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = new ArrayList<ProcessEventListener>();
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ksession.startProcess("com.sample.bpmn.hello");
assertEquals(2, processStates.size());
assertTrue(processStates.containsKey("com.sample.bpmn.hello"));
assertTrue(processStates.containsKey("com.sample.bpmn.Second"));
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.hello").intValue());
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.Second").intValue());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class EjbTimerServiceIntegrationTest method testProcessWithTimerOverEJBTimerServiceCancelTimer.
@Test
public void testProcessWithTimerOverEJBTimerServiceCancelTimer() throws InterruptedException {
cleanupSingletonSessionId();
final List<String> timerExecution = new ArrayList<String>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-TimerTask.bpmn2"), ResourceType.BPMN2).schedulerService(new EjbSchedulerService()).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Event")) {
timerExecution.add(event.getNodeInstance().getNodeName());
}
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance instance = ksession.startProcess("IntermediateCatchEvent");
assertNotNull(instance);
ksession.abortProcessInstance(instance.getId());
instance = ksession.getProcessInstance(instance.getId());
assertNull(instance);
Thread.sleep(3000);
assertEquals(0, timerExecution.size());
manager.disposeRuntimeEngine(runtime);
// close manager which will close session maintained by the manager
manager.close();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class AsyncThreadIsolationTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
executorService = ExecutorServiceFactory.newExecutorService(getEmf());
executorService.setInterval(1);
executorService.init();
addEnvironmentEntry("ExecutorService", executorService);
addWorkItemHandler("Service Task", new ServiceTaskHandler());
addProcessEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Async Hello Service Exception")) {
if (firstAttempt) {
firstAttempt = false;
} else {
synchronized (LOCK) {
LOCK.notifyAll();
}
}
}
}
});
}
Aggregations