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;
}
}
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);
}
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);
}
Aggregations