public boolean isActive() { return eventManager.isActive(); } }
@Override public void update(InstanceView<?> item) { if (!isActive()) { return; } EventCollection collection = getCollection(); collection.update(item); }
@Override public void delete(InstanceView<?> item) { if (!isActive()) { return; } EventCollection collection = getCollection(); collection.remove(item); }
@Override public Task updateTask(Task task) { check(); Task updated = this.em.merge(task); EventManagerProvider.getInstance().get().update(new TaskInstanceView(task)); return updated; }
@Override public Task removeTask(Task task) { check(); em.remove( task ); EventManagerProvider.getInstance().get().delete(new TaskInstanceView(task)); return task; }
@Override public Task persistTask(Task task) { check(); this.em.persist( task ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(TaskImpl.class, task.getId(), lockMode ); } EventManagerProvider.getInstance().get().create(new TaskInstanceView(task)); return task; }
public void removeProcessInstance(ProcessInstance processInstance) { ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment().get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )).getProcessPersistenceContext(); ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo( processInstance.getId() ); if ( processInstanceInfo != null ) { context.remove( processInstanceInfo ); } internalRemoveProcessInstance(processInstance); EventManagerProvider.getInstance().get().delete(getInstanceViewFor(processInstance)); }
public void addProcessInstance(ProcessInstance processInstance, CorrelationKey correlationKey) { ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo( processInstance, this.kruntime.getEnvironment() ); ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment() .get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )) .getProcessPersistenceContext(); processInstanceInfo = (ProcessInstanceInfo) context.persist( processInstanceInfo ); ((org.jbpm.process.instance.ProcessInstance) processInstance).setId( processInstanceInfo.getId() ); processInstanceInfo.updateLastReadDate(); // generate correlation key if not given which is same as process instance id to keep uniqueness if (correlationKey == null) { correlationKey = new CorrelationKeyInfo(); ((CorrelationKeyInfo)correlationKey).addProperty(new CorrelationPropertyInfo(null, processInstanceInfo.getId().toString())); ((org.jbpm.process.instance.ProcessInstance) processInstance).getMetaData().put("CorrelationKey", correlationKey); } CorrelationKeyInfo correlationKeyInfo = (CorrelationKeyInfo) correlationKey; correlationKeyInfo.setProcessInstanceId(processInstanceInfo.getId()); context.persist(correlationKeyInfo); internalAddProcessInstance(processInstance); EventManagerProvider.getInstance().get().create(getInstanceViewFor(processInstance)); }
EventManagerProvider.getInstance().get().update(getInstanceViewFor(processInstance)); } finally { if (!readOnly && processInstance != null) { EventManagerProvider.getInstance().get().update(getInstanceViewFor(processInstance));
@Test public void testIntegrationWithEventManager3() { // Because of MapBasedPersistenceTest we have to be sure that we register TX sync on the right transaction manager ((TestTransactionalPersistenceEventManager) EventManagerProvider.getInstance().get()).resetTransactionManager(); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( new ClassPathResource( "WorkItemsProcess.rf" ), ResourceType.DRF ); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages( kbuilder.getKnowledgePackages() ); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new SystemOutWorkItemHandler()); ProcessInstance processInstance = ksession.startProcess( "org.drools.test.TestProcess" ); ksession.insert( "TestString" ); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); List<InstanceView<?>> events = TestEventEmitter.getEvents(); assertNotNull(events); assertEquals(1, events.size()); } }
if (EventManagerProvider.getInstance().isActive()) { taskContentService.loadTaskVariables(task);
@Override public void create(InstanceView<?> item) { if (!isActive()) { return; } EventCollection collection = getCollection(); collection.add(item); }
@Override public void beforeCompletion() { EventCollection collection = (EventCollection) tm.getResource(EVENT_COLLECTION); logger.debug("About to deliver {} to emitter {}", collection, emitter); Collection<InstanceView<?>> data = collection.getEvents(); this.events = data.stream() .map(event -> { event.copyFromSource(); return event; }) .collect(Collectors.toSet()); emitter.deliver(events); logger.debug("Collection {} delivered to {}", collection, emitter); }
@Override public void afterCompletion(int status) { if ( status == TransactionManager.STATUS_COMMITTED ) { logger.debug("Completed successfull so applying events on emitter {}", emitter); emitter.apply(events); logger.debug("Emitter {} successfully applied events", emitter); } else { logger.debug("Failed at completion so dropping events on emitter {}", emitter); emitter.drop(events); logger.debug("Emitter {} successfully dropped events", emitter); } } });
protected EventCollection getCollection() { EventCollection collection = (EventCollection) this.tm.getResource(EVENT_COLLECTION); if (collection == null) { collection = emitter.newCollection(); this.tm.putResource(EVENT_COLLECTION, collection); registerSync(); } return collection; }
@Override public Attachment removeAttachmentFromTask(Task task, long attachmentId) { Attachment removed = ((InternalTaskData) task.getTaskData()).removeAttachment(attachmentId); EventManagerProvider.getInstance().get().update(new TaskInstanceView(task)); return removed; }
@Override public Comment addCommentToTask(Comment comment, Task task) { ((InternalTaskData) task.getTaskData()).addComment(comment); EventManagerProvider.getInstance().get().update(new TaskInstanceView(task)); return comment; }
@Override public Attachment addAttachmentToTask(Attachment attachment, Task task) { ((InternalTaskData) task.getTaskData()).addAttachment(attachment); EventManagerProvider.getInstance().get().update(new TaskInstanceView(task)); return attachment; }
@Override public Comment removeCommentFromTask(Comment comment, Task task) { ((InternalTaskData) task.getTaskData()).removeComment(comment.getId()); EventManagerProvider.getInstance().get().update(new TaskInstanceView(task)); return comment; }