/** * @inheritDoc * * @see org.drools.rule.Behavior#assertRightTuple(java.lang.Object, org.drools.reteoo.RightTuple, org.drools.common.InternalWorkingMemory) */ public boolean assertFact(final WindowMemory memory, final Object context, final InternalFactHandle fact, final InternalWorkingMemory workingMemory) { final SlidingTimeWindowContext queue = (SlidingTimeWindowContext) context; final EventFactHandle handle = (EventFactHandle) fact; long currentTime = workingMemory.getTimerService().getCurrentTime(); if ( isExpired( currentTime, handle ) ) { return false; } queue.lock.lock(); queue.queue.add( handle ); if ( queue.queue.peek() == handle ) { // update next expiration time updateNextExpiration( handle, workingMemory, memory, this, queue, nodeId ); } queue.lock.unlock(); return true; }
public static void removeAgendaItem(final ScheduledAgendaItem item, final InternalAgenda agenda) { ((InternalWorkingMemory)agenda.getWorkingMemory()).getTimerService().removeJob( item.getJobHandle() ); }
public Trigger createTrigger( Activation item, WorkingMemory wm ) { long timestamp = ((InternalWorkingMemory) wm).getTimerService().getCurrentTime(); String[] calendarNames = item.getRule().getCalendars(); Calendars calendars = ((InternalWorkingMemory) wm).getCalendars(); return createTrigger( timestamp, calendarNames, calendars ); }
public Trigger createTrigger( Activation item, WorkingMemory wm ) { long timestamp = ((InternalWorkingMemory) wm).getTimerService().getCurrentTime(); String[] calendarNames = item.getRule().getCalendars(); Calendars calendars = ((InternalWorkingMemory) wm).getCalendars(); return createTrigger( timestamp, calendarNames, calendars ); }
public Trigger createTrigger( Activation item, WorkingMemory wm ) { long timestamp = ((InternalWorkingMemory) wm).getTimerService().getCurrentTime(); String[] calendarNames = item.getRule().getCalendars(); Calendars calendars = ((InternalWorkingMemory) wm).getCalendars(); return createTrigger( timestamp, calendarNames, calendars ); }
public void read(MarshallerReaderContext inCtx) throws IOException, ClassNotFoundException { int leftTupleId = inCtx.readInt(); LeftTuple leftTuple = inCtx.terminalTupleMap.get( leftTupleId ); ScheduledAgendaItem item = ( ScheduledAgendaItem ) leftTuple.getObject(); Trigger trigger = InputMarshaller.readTrigger( inCtx ); DefaultAgenda agenda = ( DefaultAgenda ) inCtx.wm.getAgenda(); ActivationTimerJob job = new ActivationTimerJob(); ActivationTimerJobContext ctx = new ActivationTimerJobContext( trigger, item, agenda ); JobHandle jobHandle = ((InternalWorkingMemory)agenda.getWorkingMemory()).getTimerService().scheduleJob( job, ctx, trigger ); item.setJobHandle( jobHandle ); }
public void expireFacts(final WindowMemory memory, final Object context, final InternalWorkingMemory workingMemory) { TimerService clock = workingMemory.getTimerService(); long currentTime = clock.getCurrentTime(); SlidingTimeWindowContext queue = (SlidingTimeWindowContext) context;
public Trigger createTrigger( Activation item, WorkingMemory wm ) { long timestamp; if (eventFactHandleDecl != null) { LeftTuple leftTuple = item.getTuple(); EventFactHandle fh = (EventFactHandle) leftTuple.get(eventFactHandleDecl); timestamp = fh.getStartTimestamp(); } else { timestamp = ((InternalWorkingMemory)wm).getTimerService().getCurrentTime(); } String[] calendarNames = item.getRule().getCalendars(); Calendars calendars = ((InternalWorkingMemory) wm).getCalendars(); return createTrigger( timestamp, calendarNames, calendars ); }
/** * Schedule an agenda item. * * @param item * The item to schedule. * @param agenda * @param wm * The working memory session. */ public static void scheduleAgendaItem(final ScheduledAgendaItem item, InternalAgenda agenda, InternalWorkingMemory wm) { Trigger trigger = item.getRule().getTimer().createTrigger( item, wm ); ActivationTimerJob job = new ActivationTimerJob(); ActivationTimerJobContext ctx = new ActivationTimerJobContext( trigger, item, agenda ); JobHandle jobHandle = ((InternalWorkingMemory)agenda.getWorkingMemory()).getTimerService().scheduleJob( job, ctx, trigger ); item.setJobHandle( jobHandle ); }
public void deserialize(MarshallerReaderContext inCtx, Timer _timer) throws ClassNotFoundException { ExpireTimer _expire = _timer.getExpire(); InternalFactHandle factHandle = inCtx.handles.get( _expire.getHandleId() ); EntryPointNode epn = ((ReteooRuleBase)inCtx.wm.getRuleBase()).getRete().getEntryPointNode( new EntryPoint( _expire.getEntryPointId() ) ); Class<?> cls = ((ReteooRuleBase)inCtx.wm.getRuleBase()).getRootClassLoader().loadClass( _expire.getClassName() ); ObjectTypeNode otn = epn.getObjectTypeNodes().get( new ClassObjectType( cls ) ); TimerService clock = inCtx.wm.getTimerService(); JobContext jobctx = new ExpireJobContext( new WorkingMemoryReteExpireAction(factHandle, otn), inCtx.wm ); JobHandle handle = clock.scheduleJob( job, jobctx, new PointInTimeTrigger( _expire.getNextFireTimestamp(), null, null ) ); jobctx.setJobHandle( handle ); } }
public void read(MarshallerReaderContext inCtx) throws IOException, ClassNotFoundException { InternalFactHandle factHandle = inCtx.handles.get( inCtx.readInt() ); String entryPointId = inCtx.readUTF(); EntryPointNode epn = ((ReteooRuleBase) inCtx.wm.getRuleBase()).getRete().getEntryPointNode( new EntryPoint( entryPointId ) ); String className = inCtx.readUTF(); Class< ? > cls = ((ReteooRuleBase) inCtx.wm.getRuleBase()).getRootClassLoader().loadClass( className ); ObjectTypeNode otn = epn.getObjectTypeNodes().get( new ClassObjectType( cls ) ); long nextTimeStamp = inCtx.readLong(); TimerService clock = inCtx.wm.getTimerService(); JobContext jobctx = new ExpireJobContext( new WorkingMemoryReteExpireAction( factHandle, otn ), inCtx.wm ); JobHandle handle = clock.scheduleJob( job, jobctx, new PointInTimeTrigger( nextTimeStamp, null, null ) ); jobctx.setJobHandle( handle ); }
public Trigger createTrigger( Activation item, WorkingMemory wm ) { long timestamp = ((InternalWorkingMemory) wm).getTimerService().getCurrentTime(); String[] calendarNames = item.getRule().getCalendars(); Calendars calendars = ((InternalWorkingMemory) wm).getCalendars(); long timeSinceLastFire = 0; ScheduledAgendaItem schItem = ( ScheduledAgendaItem ) item; if ( schItem.getJobHandle() != null ) { DefaultJobHandle jh = ( DefaultJobHandle) schItem.getJobHandle(); IntervalTrigger preTrig = ( IntervalTrigger ) jh.getTimerJobInstance().getTrigger(); if ( preTrig.hasNextFireTime() != null ) { timeSinceLastFire = timestamp - preTrig.getLastFireTime().getTime(); } } long newDelay = (delay != null ? evalDelay( item, wm ) : 0) - timeSinceLastFire; if ( newDelay < 0 ) { newDelay = 0; } return new IntervalTrigger( timestamp, this.startTime, this.endTime, this.repeatLimit, newDelay, period != null ? evalPeriod( item, wm ) : 0, calendarNames, calendars ); }
final Object context, final int nodeId ) { TimerService clock = workingMemory.getTimerService(); if ( fact != null ) { long nextTimestamp = ((EventFactHandle) fact).getStartTimestamp() + stw.getSize();
public void deserialize(MarshallerReaderContext inCtx, Timer _timer) throws ClassNotFoundException { ActivationTimer _activation = _timer.getActivation(); LeftTuple leftTuple = inCtx.filter.getTuplesCache().get( PersisterHelper.createActivationKey( _activation.getActivation().getPackageName(), _activation.getActivation().getRuleName(), _activation.getActivation().getTuple() ) ); ScheduledAgendaItem item = (ScheduledAgendaItem) leftTuple.getObject(); Trigger trigger = ProtobufInputMarshaller.readTrigger( inCtx, _activation.getTrigger() ); DefaultAgenda agenda = ( DefaultAgenda ) inCtx.wm.getAgenda(); ActivationTimerJob job = new ActivationTimerJob(); ActivationTimerJobContext ctx = new ActivationTimerJobContext( trigger, item, agenda ); JobHandle jobHandle = ((InternalWorkingMemory)agenda.getWorkingMemory()).getTimerService().scheduleJob( job, ctx, trigger ); item.setJobHandle( jobHandle ); } }
object ); } else { timestamp = workingMemory.getTimerService().getCurrentTime();
TimerService clock = workingMemory.getTimerService();
public void cleanUp(final LeftTuple leftTuple, final InternalWorkingMemory workingMemory) { if ( leftTuple.getLeftTupleSink() != node ) { return; } final Activation activation = (Activation) leftTuple.getObject(); // this is to catch a race condition as activations are activated and unactivated on timers if ( activation instanceof ScheduledAgendaItem ) { ScheduledAgendaItem scheduled = (ScheduledAgendaItem) activation; workingMemory.getTimerService().removeJob( scheduled.getJobHandle() ); scheduled.getJobHandle().setCancel( true ); } if ( activation.isActivated() ) { activation.remove(); ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation, workingMemory, ActivationCancelledCause.CLEAR ); } final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(), PropagationContext.RULE_REMOVAL, null, null, null ); workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation, propagationContext, node.getRule() ); leftTuple.unlinkFromLeftParent(); leftTuple.unlinkFromRightParent(); } }
if ( context.wm.getTimerService() instanceof PseudoClockScheduler ) { time = context.clockTime; writeTimers( context.wm.getTimerService().getTimerJobInstances(), context );
if (context.wm.getTimerService() instanceof PseudoClockScheduler) { time = context.clockTime; Timers _timers = writeTimers(context.wm.getTimerService().getTimerJobInstances(), context); if (_timers != null) {