Search in sources :

Example 6 with JobHandle

use of org.drools.core.time.JobHandle in project jbpm by kiegroup.

the class TaskDeadlinesServiceImpl method unschedule.

public void unschedule(long taskId, Deadline deadline, DeadlineType type) {
    Task task = persistenceContext.findTask(taskId);
    String deploymentId = task.getTaskData().getDeploymentId();
    TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    if (timerService instanceof GlobalTimerService) {
        TaskDeadlineJob deadlineJob = new TaskDeadlineJob(taskId, deadline.getId(), type, deploymentId, task.getTaskData().getProcessInstanceId());
        logger.debug("unscheduling timer job for deadline {} {} and task {}  using timer service {}", deadlineJob.getId(), deadline.getId(), taskId, timerService);
        JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
        if (jobHandle == null) {
            jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId));
        }
        timerService.removeJob(jobHandle);
        // mark the deadlines so they won't be rescheduled again
        deadline.setEscalated(true);
    }
}
Also used : JobHandle(org.drools.core.time.JobHandle) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 7 with JobHandle

use of org.drools.core.time.JobHandle in project drools by kiegroup.

the class EventFactHandle method unscheduleAllJobs.

public void unscheduleAllJobs(ReteEvaluator reteEvaluator) {
    if (!jobs.isEmpty()) {
        synchronized (jobs) {
            TimerService clock = reteEvaluator.getTimerService();
            while (!jobs.isEmpty()) {
                JobHandle job = jobs.removeFirst();
                clock.removeJob(job);
            }
        }
    }
}
Also used : JobHandle(org.drools.core.time.JobHandle) TimerService(org.drools.core.time.TimerService)

Example 8 with JobHandle

use of org.drools.core.time.JobHandle in project drools by kiegroup.

the class ExpireJobContextTimerInputMarshaller method read.

public void read(ProtobufMarshallerReaderContext inCtx) throws IOException, ClassNotFoundException {
    InternalFactHandle factHandle = inCtx.getHandles().get(inCtx.readLong());
    long nextTimeStamp = inCtx.readLong();
    TimerService clock = inCtx.getWorkingMemory().getTimerService();
    JobContext jobctx = new ExpireJobContext(new WorkingMemoryReteExpireAction((EventFactHandle) factHandle), inCtx.getWorkingMemory());
    JobHandle handle = clock.scheduleJob(job, jobctx, PointInTimeTrigger.createPointInTimeTrigger(nextTimeStamp, null));
    jobctx.setJobHandle(handle);
}
Also used : ExpireJobContext(org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext) JobHandle(org.drools.core.time.JobHandle) EventFactHandle(org.drools.core.common.EventFactHandle) JobContext(org.drools.core.time.JobContext) ExpireJobContext(org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryReteExpireAction(org.drools.core.impl.WorkingMemoryReteExpireAction) TimerService(org.drools.core.time.TimerService)

Example 9 with JobHandle

use of org.drools.core.time.JobHandle in project drools by kiegroup.

the class EventFactHandle method unscheduleAllJobs.

public void unscheduleAllJobs(InternalWorkingMemory workingMemory) {
    if (!jobs.isEmpty()) {
        synchronized (jobs) {
            TimerService clock = workingMemory.getTimerService();
            while (!jobs.isEmpty()) {
                JobHandle job = jobs.removeFirst();
                clock.removeJob(job);
            }
        }
    }
}
Also used : JobHandle(org.drools.core.time.JobHandle) TimerService(org.drools.core.time.TimerService)

Example 10 with JobHandle

use of org.drools.core.time.JobHandle in project drools by kiegroup.

the class SlidingTimeWindow method updateNextExpiration.

protected void updateNextExpiration(final InternalFactHandle fact, final InternalWorkingMemory workingMemory, final Behavior.Context context, final int nodeId) {
    TimerService clock = workingMemory.getTimerService();
    if (fact != null) {
        long nextTimestamp = ((EventFactHandle) fact).getStartTimestamp() + getSize();
        if (nextTimestamp < clock.getCurrentTime()) {
            // Past and out-of-order events should not be insert,
            // but the engine silently accepts them anyway, resulting in possibly undesirable behaviors
            workingMemory.queueWorkingMemoryAction(new BehaviorExpireWMAction(nodeId, this, context));
        } else {
            JobContext jobctx = new BehaviorJobContext(nodeId, workingMemory, this, context);
            JobHandle handle = clock.scheduleJob(job, jobctx, new PointInTimeTrigger(nextTimestamp, null, null));
            jobctx.setJobHandle(handle);
        }
    }
}
Also used : JobHandle(org.drools.core.time.JobHandle) JobContext(org.drools.core.time.JobContext) PointInTimeTrigger(org.drools.core.time.impl.PointInTimeTrigger) TimerService(org.drools.core.time.TimerService)

Aggregations

JobHandle (org.drools.core.time.JobHandle)14 TimerService (org.drools.core.time.TimerService)9 Date (java.util.Date)5 JobContext (org.drools.core.time.JobContext)4 Trigger (org.drools.core.time.Trigger)4 IntervalTrigger (org.drools.core.time.impl.IntervalTrigger)4 CronTrigger (org.drools.core.time.impl.CronTrigger)3 GlobalTimerService (org.jbpm.process.core.timer.impl.GlobalTimerService)3 Task (org.kie.api.task.model.Task)3 InternalTask (org.kie.internal.task.api.model.InternalTask)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 EventFactHandle (org.drools.core.common.EventFactHandle)2 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 WorkingMemoryReteExpireAction (org.drools.core.impl.WorkingMemoryReteExpireAction)2 ExpireJobContext (org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext)2 Test (org.junit.Test)2 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 PointInTimeTrigger (org.drools.core.time.impl.PointInTimeTrigger)1 Deadline (org.kie.internal.task.api.model.Deadline)1