Search in sources :

Example 1 with SelfRemovalJobContext

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

the class JpaJDKTimerService method createCallableJob.

protected Callable<Void> createCallableJob(Job job, JobContext ctx, Trigger trigger, JDKJobHandle handle, InternalSchedulerService scheduler) {
    JpaJDKCallableJob jobInstance = new JpaJDKCallableJob(new SelfRemovalJob(job), new SelfRemovalJobContext(ctx, timerInstances), trigger, handle, scheduler);
    this.timerInstances.put(handle.getId(), jobInstance);
    return jobInstance;
}
Also used : SelfRemovalJob(org.drools.core.time.SelfRemovalJob) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext)

Example 2 with SelfRemovalJobContext

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

the class ProtobufOutputMarshaller method writeTimers.

private static ProtobufMessages.Timers writeTimers(Collection<TimerJobInstance> timers, MarshallerWriteContext outCtx) {
    if (!timers.isEmpty()) {
        List<TimerJobInstance> sortedTimers = new ArrayList<TimerJobInstance>(timers);
        Collections.sort(sortedTimers, new Comparator<TimerJobInstance>() {

            public int compare(TimerJobInstance o1, TimerJobInstance o2) {
                return (int) (o1.getJobHandle().getId() - o2.getJobHandle().getId());
            }
        });
        ProtobufMessages.Timers.Builder _timers = ProtobufMessages.Timers.newBuilder();
        for (TimerJobInstance timer : sortedTimers) {
            JobContext jctx = ((SelfRemovalJobContext) timer.getJobContext()).getJobContext();
            if (jctx instanceof ObjectTypeNode.ExpireJobContext && !((ObjectTypeNode.ExpireJobContext) jctx).getExpireAction().getFactHandle().isValid()) {
                continue;
            }
            TimersOutputMarshaller writer = outCtx.writersByClass.get(jctx.getClass());
            Timer _timer = writer.serialize(jctx, outCtx);
            if (_timer != null) {
                _timers.addTimer(_timer);
            }
        }
        return _timers.build();
    }
    return null;
}
Also used : TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) ArrayList(java.util.ArrayList) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) Timer(org.drools.core.marshalling.impl.ProtobufMessages.Timers.Timer) JobContext(org.drools.core.time.JobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) Timers(org.drools.core.marshalling.impl.ProtobufMessages.Timers)

Aggregations

SelfRemovalJobContext (org.drools.core.time.SelfRemovalJobContext)2 ArrayList (java.util.ArrayList)1 Timers (org.drools.core.marshalling.impl.ProtobufMessages.Timers)1 Timer (org.drools.core.marshalling.impl.ProtobufMessages.Timers.Timer)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 JobContext (org.drools.core.time.JobContext)1 SelfRemovalJob (org.drools.core.time.SelfRemovalJob)1 TimerJobInstance (org.drools.core.time.impl.TimerJobInstance)1