public AgendaItem createAgendaItem(final LeftTuple tuple, final int salience, final PropagationContext context, final RuleTerminalNode rtn) { return new AgendaItem( activationCounter++, tuple, salience, context, rtn ); }
public void cancelActivation(org.drools.runtime.rule.Activation act) { AgendaItem match = ( AgendaItem ) act; match.cancel(); if ( match.isActive() ) { LeftTuple leftTuple = match.getTuple(); leftTuple.getLeftTupleSink().retractLeftTuple( leftTuple, (PropagationContext) act.getPropagationContext(), workingMemory ); } }
public void remove() { dequeue(); }
public void removeActivation(final AgendaItem activation) { if ( declarativeAgenda ) { workingMemory.getEntryPointNode().retractActivation( activation.getFactHandle(), activation.getPropagationContext(), workingMemory ); if ( activation.getActivationGroupNode() != null ) { activation.getActivationGroupNode().getActivationGroup().removeActivation( activation ); } } if ( activation instanceof ScheduledAgendaItem ) { removeScheduleItem( (ScheduledAgendaItem) activation ); } }
public Object getProperty(String name, Object obj, VariableResolverFactory variableFactory) { AgendaItem item = ( AgendaItem ) obj; if ( "rule".equals( name ) ) { return item.getRule(); } else if ( "active".equals( name ) ) { return item.isActive(); } else if ( "objects".equals( name ) ) { return item.getObjects(); } else if ( "factHandles".equals( name ) ) { return item.getFactHandles(); } else if ( "declarationIDs".equals( name ) ) { return item.getDeclarationIDs(); } else if ( "this".equals( name ) ) { return item; } // FIXME hack as MVEL seems to be ignoring indexed variables VariableResolver vr = variableFactory.getNextFactory().getVariableResolver( name ); if ( vr != null ) { return vr.getValue(); } Declaration declr = item.getRuleTerminalNode().getSubRule().getOuterDeclarations().get( name ); if ( declr != null ) { return declr.getValue( null, item.getTuple().get( declr ).getObject() ); } else { return item.getRule().getMetaData().get( name ); } }
ObjectOutputStream stream = context.stream; stream.writeLong( agendaItem.getActivationNumber() ); stream.writeInt( agendaItem.getSalience() ); Rule rule = agendaItem.getRule(); stream.writeUTF( rule.getPackage() ); stream.writeUTF( rule.getName() ); stream.writeLong( agendaItem.getPropagationContext().getPropagationNumber() ); if ( agendaItem.getActivationGroupNode() != null ) { stream.writeBoolean( true ); stream.writeUTF( agendaItem.getActivationGroupNode().getActivationGroup().getName() ); stream.writeBoolean( agendaItem.isActivated() ); if ( agendaItem.getFactHandle() != null ) { stream.writeBoolean( true ); stream.writeInt( agendaItem.getFactHandle().getId() ); } else { stream.writeBoolean( false ); org.drools.core.util.LinkedList<LogicalDependency> list = agendaItem.getLogicalDependencies(); if ( list != null && !list.isEmpty() ) { for (LogicalDependency node = list.getFirst(); node != null; node = node.getNext() ) {
public static ProtobufMessages.Activation writeActivation(MarshallerWriteContext context, AgendaItem agendaItem) { ProtobufMessages.Activation.Builder _activation = ProtobufMessages.Activation.newBuilder(); Rule rule = agendaItem.getRule(); _activation.setPackageName(rule.getPackage()); _activation.setRuleName(rule.getName()); ProtobufMessages.Tuple.Builder _tb = ProtobufMessages.Tuple.newBuilder(); for (LeftTuple entry = agendaItem.getTuple(); entry != null; entry = entry.getParent()) { InternalFactHandle handle = entry.getLastHandle(); _tb.addHandleId(handle.getId()); } _activation.setTuple(_tb.build()); _activation.setSalience(agendaItem.getSalience()); _activation.setIsActivated(agendaItem.isActivated()); if (agendaItem.getActivationGroupNode() != null) { _activation.setActivationGroup(agendaItem.getActivationGroupNode().getActivationGroup().getName()); } if (agendaItem.getFactHandle() != null) { _activation.setHandleId(agendaItem.getFactHandle().getId()); } org.drools.core.util.LinkedList<LogicalDependency> list = agendaItem.getLogicalDependencies(); if (list != null && !list.isEmpty()) { for (LogicalDependency node = list.getFirst(); node != null; node = node.getNext()) { _activation.addLogicalDependency(((InternalFactHandle) node.getJustified()).getId()); } } return _activation.build(); }
public void modifyActivation(final AgendaItem activation, boolean previouslyActive) { if ( declarativeAgenda ) { InternalFactHandle factHandle = activation.getFactHandle(); workingMemory.getEntryPointNode().modifyActivation( factHandle, activation.getPropagationContext(), workingMemory ); if ( activation.isCanceled() || ( activation.getBlockers() != null && activation.getBlockers().size() > 0 ) ) { if ( activation.getActivationGroupNode() != null && activation.getActivationGroupNode().getActivationGroup() == activationGroup ) { addActivation( activation, true ); } else { Timer timer = activation.getRule().getTimer(); if ( timer != null && timer instanceof ExpressionIntervalTimer ) { ScheduledAgendaItem schItem = ( ScheduledAgendaItem ) activation;
public void blockActivation(org.drools.runtime.rule.Activation act) { AgendaItem targetMatch = ( AgendaItem ) act; // iterate to find previous equal logical insertion LogicalDependency dep = null; if ( this.previousJustified != null ) { for ( dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext() ) { if ( targetMatch == dep.getJustified() ) { this.previousJustified.remove( dep ); break; } } } if ( dep == null ) { dep = new SimpleLogicalDependency( activation, targetMatch ); } this.activation.addBlocked( dep ); if ( targetMatch.getBlockers().size() == 1 && targetMatch.isActive() ) { // it wasn't blocked before, but is now, so we must remove it from all groups, so it cannot be executed. targetMatch.remove(); if ( targetMatch.getActivationGroupNode() != null ) { targetMatch.getActivationGroupNode().getActivationGroup().removeActivation( targetMatch ); } if ( targetMatch.getActivationNode() != null ) { final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) targetMatch.getActivationNode().getParentContainer(); ruleFlowGroup.removeActivation( targetMatch ); } } }
public boolean addActivation(final AgendaItem activation) { if ( declarativeAgenda ) { if ( activationObjectTypeConf == null ) { EntryPoint ep = workingMemory.getEntryPoint(); activationObjectTypeConf = ((InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( ep.getEntryPointId() )).getObjectTypeConfigurationRegistry().getObjectTypeConf( ep, activation ); } InternalFactHandle factHandle = workingMemory.getFactHandleFactory().newFactHandle( activation, activationObjectTypeConf, workingMemory, workingMemory ); workingMemory.getEntryPointNode().assertActivation( factHandle, activation.getPropagationContext(), workingMemory ); activation.setFactHandle( factHandle ); if ( !activation.isCanceled() && ( activation.getBlockers() == null || activation.getBlockers().isEmpty() ) ) { // All activations started off staged, they are unstaged if they are blocked or // allowed to move onto the actual agenda for firing. getStageActivationsGroup().addActivation( activation ); } return true; } else { addActivation( activation, true ); return true; } }
scheduled = true; } else { activation = new AgendaItem( activationNumber, leftTuple, salience, activation.setActivated( activated ); activation.setFactHandle( handle ); handle.setObject( activation ); activation.setAgendaGroup( agendaGroup );
public void clearAndCancelAgendaGroup(final AgendaGroup agendaGroup) { final EventSupport eventsupport = (EventSupport) this.workingMemory; // this is thread safe for BinaryHeapQueue // Binary Heap locks while it returns the array and reset's it's own internal array. Lock is released afer getAndClear() for (Activation aQueueable : ((InternalAgendaGroup) agendaGroup).getAndClear()) { final AgendaItem item = (AgendaItem) aQueueable; if (item == null) { continue; } // this must be set false before removal from the activationGroup. // Otherwise the activationGroup will also try to cancel the Actvation // Also modify won't work properly item.setActivated(false); if (item.getActivationGroupNode() != null) { item.getActivationGroupNode().getActivationGroup().removeActivation(item); } if (item.getActivationNode() != null) { final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) item.getActivationNode().getParentContainer(); ruleFlowGroup.removeActivation(item); } eventsupport.getAgendaEventSupport().fireActivationCancelled( item, this.workingMemory, ActivationCancelledCause.CLEAR ); } }
public void clearAndCancelAndCancel(final RuleFlowGroup ruleFlowGroup) { final EventSupport eventsupport = (EventSupport) this.workingMemory; for (ActivationNode node : ruleFlowGroup) { AgendaItem item = (AgendaItem) node.getActivation(); if (item != null) { item.setActivated(false); item.remove(); if (item.getActivationGroupNode() != null) { item.getActivationGroupNode().getActivationGroup().removeActivation(item); } } eventsupport.getAgendaEventSupport().fireActivationCancelled( item, this.workingMemory, ActivationCancelledCause.CLEAR ); } ruleFlowGroup.clear(); if ( ruleFlowGroup.isActive() && ruleFlowGroup.isAutoDeactivate() ) { // deactivate callback WorkingMemoryAction action = new DeactivateCallback( (InternalRuleFlowGroup) ruleFlowGroup ); this.workingMemory.queueWorkingMemoryAction( action ); } }
public void removeAllBlockersAndBlocked(DefaultAgenda agenda){ if ( this.blockers != null ) { // Iterate and remove this node's logical dependency list from each of it's blockers for ( LinkedListEntry<LogicalDependency> node = blockers.getFirst(); node != null; node = node.getNext() ) { LogicalDependency dep = node.getObject(); dep.getJustifier().getBlocked().remove( dep ); } } this.blockers = null; if ( this.blocked != null ) { // Iterate and remove this node's logical dependency list from each of it's blocked for ( LogicalDependency dep = blocked.getFirst(); dep != null; ) { LogicalDependency tmp = dep.getNext(); removeBlocked( dep ); AgendaItem justified = ( AgendaItem ) dep.getJustified(); if ( justified.getBlockers().isEmpty() && justified.isActivated() ) { // the match is no longer blocked, so stage it agenda.getStageActivationsGroup().addActivation( justified ); } dep = tmp; } } this.blocked = null; }
public void unblockAllActivations(org.drools.runtime.rule.Activation act) { AgendaItem targetMatch = ( AgendaItem ) act; boolean wasBlocked = (targetMatch.getBlockers() != null && !targetMatch.getBlockers().isEmpty() ); for ( LinkedListEntry entry = ( LinkedListEntry ) targetMatch.getBlockers().getFirst(); entry != null; ) { LinkedListEntry tmp = ( LinkedListEntry ) entry.getNext(); LogicalDependency dep = ( LogicalDependency ) entry.getObject(); ((AgendaItem)dep.getJustifier()).removeBlocked( dep ); entry = tmp; } if ( wasBlocked ) { // the match is no longer blocked, so stage it ((DefaultAgenda)workingMemory.getAgenda()).getStageActivationsGroup().addActivation( targetMatch ); } }
final RuleTerminalNode rtn ) { AgendaItem item = (AgendaItem) activation; item.removeAllBlockersAndBlocked( this ); if ( item.getActivationUnMatchListener() != null ) { item.getActivationUnMatchListener().unMatch( workingMemory.getKnowledgeRuntime(), item );
public void cancelRemainingPreviousLogicalDependencies() { if ( this.previousJustified != null ) { for ( LogicalDependency dep = (LogicalDependency) this.previousJustified.getFirst(); dep != null; dep = (LogicalDependency) dep.getNext() ) { this.workingMemory.getTruthMaintenanceSystem().removeLogicalDependency( activation, dep, activation.getPropagationContext() ); } } if ( this.previousBlocked != null ) { for ( LogicalDependency dep = this.previousBlocked.getFirst(); dep != null; ) { LogicalDependency tmp = dep.getNext(); this.previousBlocked.remove( dep ); AgendaItem justified = ( AgendaItem ) dep.getJustified(); justified.getBlockers().remove( dep.getJustifierEntry() ); if (justified.getBlockers().isEmpty() ) { // the match is no longer blocked, so stage it ((DefaultAgenda)workingMemory.getAgenda()).getStageActivationsGroup().addActivation( justified ); } dep = tmp; } } }
if ( item.getActivationNode() != null ) { ruleFlowGroup = (InternalRuleFlowGroup) item.getActivationNode().getParentContainer();
public void addBlocked(final LogicalDependency dep) { // Adds the blocked to the blockers list if ( this.blocked == null ) { this.blocked = new LinkedList<LogicalDependency>(); } this.blocked.add( dep ); // now ad the blocker to the blocked's list - we need to check that references are null first AgendaItem blocked = (AgendaItem)dep.getJustified(); if ( blocked.blockers == null ) { blocked.blockers = new LinkedList<LinkedListEntry<LogicalDependency>>(); blocked.blockers.add( dep.getJustifierEntry() ); } else if ( dep.getJustifierEntry().getNext() == null && dep.getJustifierEntry().getPrevious() == null && blocked.getBlockers().getFirst() != dep.getJustifierEntry() ) { blocked.blockers.add( dep.getJustifierEntry() ); } }