Search in sources :

Example 1 with JobsService

use of org.kie.kogito.jobs.JobsService in project kogito-runtimes by kiegroup.

the class StateBasedNodeInstance method internalTrigger.

@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getStringId()) == null) {
        return;
    }
    // activate timers
    Map<Timer, DroolsAction> timers = getEventBasedNode().getTimers();
    if (timers != null) {
        addTimerListener();
        timerInstances = new ArrayList<>(timers.size());
        JobsService jobService = ((KogitoProcessRuntime.Provider) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getKogitoProcessRuntime().getJobsService();
        for (Timer timer : timers.keySet()) {
            ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new TimerJobId(timer.getId()), createTimerInstance(timer), getProcessInstance().getStringId(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
            timerInstances.add(jobService.scheduleProcessInstanceJob(jobDescription));
        }
    }
    if (getEventBasedNode().getBoundaryEvents() != null) {
        for (String name : getEventBasedNode().getBoundaryEvents()) {
            boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()).isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", name, getProcessInstance().getId());
            if (isActive) {
                getProcessInstance().getKnowledgeRuntime().signalEvent(name, null);
            } else {
                addActivationListener();
            }
        }
    }
    ((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) InternalAgenda(org.drools.core.common.InternalAgenda) Timer(org.jbpm.process.core.timer.Timer) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) JobsService(org.kie.kogito.jobs.JobsService) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) TimerJobId(org.kie.kogito.jobs.TimerJobId)

Example 2 with JobsService

use of org.kie.kogito.jobs.JobsService in project kogito-runtimes by kiegroup.

the class TimerNodeInstance method internalTrigger.

@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
    if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A TimerNode only accepts default incoming connections!");
    }
    triggerTime = new Date();
    ExpirationTime expirationTime = createTimerInstance(getTimerNode().getTimer());
    if (getTimerInstances() == null) {
        addTimerListener();
    }
    ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new TimerJobId(getTimerNode().getTimer().getId()), expirationTime, getProcessInstance().getStringId(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
    JobsService jobService = InternalProcessRuntime.asKogitoProcessRuntime(getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getJobsService();
    timerId = jobService.scheduleProcessInstanceJob(jobDescription);
}
Also used : KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) JobsService(org.kie.kogito.jobs.JobsService) ExpirationTime(org.kie.kogito.jobs.ExpirationTime) TimerJobId(org.kie.kogito.jobs.TimerJobId) Date(java.util.Date)

Example 3 with JobsService

use of org.kie.kogito.jobs.JobsService 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 4 with JobsService

use of org.kie.kogito.jobs.JobsService in project kogito-runtimes by kiegroup.

the class EventNodeInstance method cancelSlaTimer.

private void cancelSlaTimer() {
    if (this.slaTimerId != null && !this.slaTimerId.trim().isEmpty()) {
        JobsService jobService = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getJobsService();
        jobService.cancelJob(this.slaTimerId);
        logger.debug("SLA Timer {} has been canceled", this.slaTimerId);
    }
}
Also used : JobsService(org.kie.kogito.jobs.JobsService) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime)

Example 5 with JobsService

use of org.kie.kogito.jobs.JobsService in project kogito-runtimes by kiegroup.

the class StateBasedNodeInstance method cancelSlaTimer.

private void cancelSlaTimer() {
    if (this.slaTimerId != null && !this.slaTimerId.trim().isEmpty()) {
        JobsService jobService = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getJobsService();
        jobService.cancelJob(this.slaTimerId);
        logger.debug("SLA Timer {} has been canceled", this.slaTimerId);
    }
}
Also used : JobsService(org.kie.kogito.jobs.JobsService) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime)

Aggregations

JobsService (org.kie.kogito.jobs.JobsService)6 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)4 ProcessInstanceJobDescription (org.kie.kogito.jobs.ProcessInstanceJobDescription)4 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)3 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)2 ExpirationTime (org.kie.kogito.jobs.ExpirationTime)2 TimerJobId (org.kie.kogito.jobs.TimerJobId)2 ZonedDateTime (java.time.ZonedDateTime)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Date (java.util.Date)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 InternalAgenda (org.drools.core.common.InternalAgenda)1 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 Timer (org.jbpm.process.core.timer.Timer)1 ASYNC_WAITING (org.jbpm.ruleflow.core.Metadata.ASYNC_WAITING)1 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 DroolsAction (org.jbpm.workflow.core.DroolsAction)1 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)1