Search in sources :

Example 1 with WorkingMemoryReteExpireAction

use of org.drools.core.impl.WorkingMemoryReteExpireAction in project drools by kiegroup.

the class ExpireJobContextTimerOutputMarshaller method serialize.

@Override
public ProtobufMessages.Timers.Timer serialize(JobContext jobCtx, MarshallerWriteContext outputCtx) {
    // ExpireJob, no state
    ExpireJobContext ejobCtx = (ExpireJobContext) jobCtx;
    WorkingMemoryReteExpireAction expireAction = ejobCtx.getExpireAction();
    DefaultJobHandle jobHandle = (DefaultJobHandle) ejobCtx.getJobHandle();
    PointInTimeTrigger trigger = (PointInTimeTrigger) jobHandle.getTimerJobInstance().getTrigger();
    Date nextFireTime = trigger.hasNextFireTime();
    if (nextFireTime != null) {
        return ProtobufMessages.Timers.Timer.newBuilder().setType(ProtobufMessages.Timers.TimerType.EXPIRE).setExpire(ProtobufMessages.Timers.ExpireTimer.newBuilder().setHandleId(expireAction.getFactHandle().getId()).setNextFireTimestamp(nextFireTime.getTime()).build()).build();
    } else {
        // There is no reason to serialize a timer when it has no future execution time.
        return null;
    }
}
Also used : ExpireJobContext(org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext) PointInTimeTrigger(org.drools.core.time.impl.PointInTimeTrigger) WorkingMemoryReteExpireAction(org.drools.core.impl.WorkingMemoryReteExpireAction) Date(java.util.Date) DefaultJobHandle(org.drools.core.time.impl.DefaultJobHandle)

Example 2 with WorkingMemoryReteExpireAction

use of org.drools.core.impl.WorkingMemoryReteExpireAction in project drools by kiegroup.

the class ExpireJobContextTimerInputMarshaller method deserialize.

@Override
public void deserialize(MarshallerReaderContext inCtx, ProtobufMessages.Timers.Timer timer) {
    ProtobufMessages.Timers.ExpireTimer expire = timer.getExpire();
    InternalFactHandle factHandle = inCtx.getHandles().get(expire.getHandleId());
    TimerService clock = inCtx.getWorkingMemory().getTimerService();
    JobContext jobctx = new ExpireJobContext(new WorkingMemoryReteExpireAction((EventFactHandle) factHandle), inCtx.getWorkingMemory());
    JobHandle jobHandle = clock.scheduleJob(job, jobctx, PointInTimeTrigger.createPointInTimeTrigger(expire.getNextFireTimestamp(), null));
    jobctx.setJobHandle(jobHandle);
    ((EventFactHandle) factHandle).addJob(jobHandle);
}
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 3 with WorkingMemoryReteExpireAction

use of org.drools.core.impl.WorkingMemoryReteExpireAction 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)

Aggregations

WorkingMemoryReteExpireAction (org.drools.core.impl.WorkingMemoryReteExpireAction)3 ExpireJobContext (org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext)3 EventFactHandle (org.drools.core.common.EventFactHandle)2 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 JobContext (org.drools.core.time.JobContext)2 JobHandle (org.drools.core.time.JobHandle)2 TimerService (org.drools.core.time.TimerService)2 Date (java.util.Date)1 DefaultJobHandle (org.drools.core.time.impl.DefaultJobHandle)1 PointInTimeTrigger (org.drools.core.time.impl.PointInTimeTrigger)1