Search in sources :

Example 1 with ExpireJobContext

use of org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext 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 2 with ExpireJobContext

use of org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext in project drools by kiegroup.

the class ExpireJobContextTimerOutputMarshaller method write.

public void write(JobContext jobCtx, MarshallerWriteContext outputCtx) throws IOException {
    // ExpireJob, no state
    ExpireJobContext ejobCtx = (ExpireJobContext) jobCtx;
    DefaultJobHandle jobHandle = (DefaultJobHandle) ejobCtx.getJobHandle();
    PointInTimeTrigger trigger = (PointInTimeTrigger) jobHandle.getTimerJobInstance().getTrigger();
    // There is no reason to serialize a timer when it has no future execution time.
    Date nextFireTime = trigger.hasNextFireTime();
    if (nextFireTime != null) {
        outputCtx.writeShort(PersisterEnums.EXPIRE_TIMER);
        outputCtx.writeLong(ejobCtx.getExpireAction().getFactHandle().getId());
        outputCtx.writeLong(nextFireTime.getTime());
    }
}
Also used : ExpireJobContext(org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext) PointInTimeTrigger(org.drools.core.time.impl.PointInTimeTrigger) Date(java.util.Date) DefaultJobHandle(org.drools.core.time.impl.DefaultJobHandle)

Example 3 with ExpireJobContext

use of org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext 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 4 with ExpireJobContext

use of org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext 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

ExpireJobContext (org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext)4 WorkingMemoryReteExpireAction (org.drools.core.impl.WorkingMemoryReteExpireAction)3 Date (java.util.Date)2 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 DefaultJobHandle (org.drools.core.time.impl.DefaultJobHandle)2 PointInTimeTrigger (org.drools.core.time.impl.PointInTimeTrigger)2