Search in sources :

Example 16 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class KogitoProcessEventSupportImpl method fireAfterNodeLeft.

@Override
public void fireAfterNodeLeft(final KogitoNodeInstance nodeInstance, KieRuntime kruntime) {
    final ProcessNodeLeftEvent event = new KogitoProcessNodeLeftEventImpl(nodeInstance, kruntime);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        if (hasListeners()) {
            notifyAllListeners(event, (l, e1) -> l.afterNodeLeft(e1));
        }
    }));
}
Also used : ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) WorkUnit(org.kie.kogito.uow.WorkUnit) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) AbstractEventSupport(org.drools.core.event.AbstractEventSupport) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeadlineType(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent.DeadlineType) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) SLAViolatedEventImpl(org.drools.core.event.SLAViolatedEventImpl) SignalEvent(org.kie.api.event.process.SignalEvent) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) SignalEventImpl(org.drools.core.event.SignalEventImpl) ProcessCompletedEventImpl(org.drools.core.event.ProcessCompletedEventImpl) MessageEvent(org.kie.api.event.process.MessageEvent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) MessageEventImpl(org.drools.core.event.MessageEventImpl) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Transition(org.kie.kogito.process.workitem.Transition) KieRuntime(org.kie.api.runtime.KieRuntime) KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent)

Example 17 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class KogitoProcessEventSupportImpl method fireAfterNodeTriggered.

@Override
public void fireAfterNodeTriggered(final KogitoNodeInstance nodeInstance, KieRuntime kruntime) {
    final ProcessNodeTriggeredEvent event = new KogitoProcessNodeTriggeredEventImpl(nodeInstance, kruntime);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        if (hasListeners()) {
            notifyAllListeners(event, (l, e1) -> l.afterNodeTriggered(e1));
        }
    }));
}
Also used : ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) WorkUnit(org.kie.kogito.uow.WorkUnit) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) AbstractEventSupport(org.drools.core.event.AbstractEventSupport) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeadlineType(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent.DeadlineType) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) SLAViolatedEventImpl(org.drools.core.event.SLAViolatedEventImpl) SignalEvent(org.kie.api.event.process.SignalEvent) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) SignalEventImpl(org.drools.core.event.SignalEventImpl) ProcessCompletedEventImpl(org.drools.core.event.ProcessCompletedEventImpl) MessageEvent(org.kie.api.event.process.MessageEvent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) MessageEventImpl(org.drools.core.event.MessageEventImpl) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Transition(org.kie.kogito.process.workitem.Transition) KieRuntime(org.kie.api.runtime.KieRuntime) KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent)

Example 18 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class KogitoProcessEventSupportImpl method fireBeforeNodeLeft.

@Override
public void fireBeforeNodeLeft(final KogitoNodeInstance nodeInstance, KieRuntime kruntime) {
    final ProcessNodeLeftEvent event = new KogitoProcessNodeLeftEventImpl(nodeInstance, kruntime);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        if (hasListeners()) {
            notifyAllListeners(event, (l, e1) -> l.beforeNodeLeft(e1));
        }
    }));
}
Also used : ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) WorkUnit(org.kie.kogito.uow.WorkUnit) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) AbstractEventSupport(org.drools.core.event.AbstractEventSupport) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeadlineType(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent.DeadlineType) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) SLAViolatedEventImpl(org.drools.core.event.SLAViolatedEventImpl) SignalEvent(org.kie.api.event.process.SignalEvent) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) SignalEventImpl(org.drools.core.event.SignalEventImpl) ProcessCompletedEventImpl(org.drools.core.event.ProcessCompletedEventImpl) MessageEvent(org.kie.api.event.process.MessageEvent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) MessageEventImpl(org.drools.core.event.MessageEventImpl) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Transition(org.kie.kogito.process.workitem.Transition) KieRuntime(org.kie.api.runtime.KieRuntime) KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent)

Example 19 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class AsyncEventNodeInstance method internalTrigger.

@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
    addEventListeners();
    addAsyncStatus();
    final InternalProcessRuntime processRuntime = (InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime();
    // Deffer the timer scheduling to the end of current UnitOfWork execution chain
    processRuntime.getUnitOfWorkManager().currentUnitOfWork().intercept(new BaseWorkUnit<>(this, instance -> {
        ExpirationTime expirationTime = ExactExpirationTime.of(ZonedDateTime.now().plus(1, ChronoUnit.MILLIS));
        ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new AsyncJobId(instance.getStringId()), expirationTime, instance.getProcessInstance().getStringId(), instance.getProcessInstance().getRootProcessInstanceId(), instance.getProcessInstance().getProcessId(), instance.getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
        JobsService jobService = processRuntime.getJobsService();
        String jobId = jobService.scheduleProcessInstanceJob(jobDescription);
        setJobId(jobId);
    }, i -> {
    }, WorkUnit.LOW_PRIORITY));
}
Also used : JobsService(org.kie.kogito.jobs.JobsService) Logger(org.slf4j.Logger) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) WorkUnit(org.kie.kogito.uow.WorkUnit) ZonedDateTime(java.time.ZonedDateTime) NodeInstance(org.kie.api.runtime.process.NodeInstance) AsyncJobId(org.kie.kogito.jobs.AsyncJobId) LoggerFactory(org.slf4j.LoggerFactory) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) BaseWorkUnit(org.kie.kogito.services.uow.BaseWorkUnit) Objects(java.util.Objects) ChronoUnit(java.time.temporal.ChronoUnit) ProcessInstance(org.kie.kogito.process.ProcessInstance) Node(org.kie.api.definition.process.Node) ASYNC_WAITING(org.jbpm.ruleflow.core.Metadata.ASYNC_WAITING) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) KogitoEventListener(org.kie.kogito.internal.process.event.KogitoEventListener) Optional(java.util.Optional) ExactExpirationTime(org.kie.kogito.jobs.ExactExpirationTime) ExpirationTime(org.kie.kogito.jobs.ExpirationTime) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) JobsService(org.kie.kogito.jobs.JobsService) AsyncJobId(org.kie.kogito.jobs.AsyncJobId) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) ExactExpirationTime(org.kie.kogito.jobs.ExactExpirationTime) ExpirationTime(org.kie.kogito.jobs.ExpirationTime)

Example 20 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class NodeInstanceImpl method trigger.

@Override
public final void trigger(KogitoNodeInstance from, String type) {
    boolean hidden = false;
    if (getNode().getMetaData().get(HIDDEN) != null) {
        hidden = true;
    }
    if (from != null) {
        int level = ((org.jbpm.workflow.instance.NodeInstance) from).getLevel();
        ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(level);
        Collection<Connection> incoming = getNode().getIncomingConnections(type);
        for (Connection conn : incoming) {
            if (conn.getFrom().getId() == from.getNodeId()) {
                this.metaData.put(INCOMING_CONNECTION, conn.getMetaData().get(UNIQUE_ID));
                break;
            }
        }
    }
    if (dynamicParameters != null) {
        for (Entry<String, Object> entry : dynamicParameters.entrySet()) {
            setVariable(entry.getKey(), entry.getValue());
        }
    }
    configureSla();
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeTriggered(this, kruntime);
    }
    try {
        internalTrigger(from, type);
    } catch (Exception e) {
        logger.debug("Node instance causing process instance error in id {}", this.getStringId(), e);
        captureError(e);
        // stop after capturing error
        return;
    }
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeTriggered(this, kruntime);
    }
}
Also used : KogitoNodeInstanceContainer(org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer) NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) Connection(org.kie.api.definition.process.Connection) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) ActionNodeInstance(org.jbpm.workflow.instance.node.ActionNodeInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance)

Aggregations

KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)33 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)15 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)14 Map (java.util.Map)12 SLAViolatedEvent (org.kie.api.event.process.SLAViolatedEvent)12 KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)12 List (java.util.List)11 HumanTaskWorkItem (org.kie.kogito.process.workitem.HumanTaskWorkItem)9 WorkUnit (org.kie.kogito.uow.WorkUnit)9 AbstractEventSupport (org.drools.core.event.AbstractEventSupport)8 MessageEventImpl (org.drools.core.event.MessageEventImpl)8 ProcessCompletedEventImpl (org.drools.core.event.ProcessCompletedEventImpl)8 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)8 SLAViolatedEventImpl (org.drools.core.event.SLAViolatedEventImpl)8 SignalEventImpl (org.drools.core.event.SignalEventImpl)8 Date (java.util.Date)7 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 MessageEvent (org.kie.api.event.process.MessageEvent)5