public void delete(LogicalDependency node, BeliefSet beliefSet, PropagationContext context) { beliefSet.remove( node.getJustifierEntry() ); WorkingMemoryAction action = new LogicalRetractCallback( tms, node, beliefSet, (InternalFactHandle) node.getJustified(), context, node.getJustifier() ); wm.queueWorkingMemoryAction( action ); }
public void removeBlocked(final LogicalDependency dep) { this.blocked.remove( dep ); AgendaItem blocked = (AgendaItem)dep.getJustified(); blocked.blockers.remove( dep.getJustifierEntry() ); }
for ( dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext() ) { if ( object.equals( ((InternalFactHandle) dep.getJustified()).getObject() ) ) { this.previousJustified.remove( dep ); break;
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; } } }
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 LogicalRetractCallback(MarshallerReaderContext context) throws IOException { this.tms = context.wm.getTruthMaintenanceSystem(); this.handle = context.handles.get( context.readInt() ); this.context = context.propagationContexts.get( context.readLong() ); this.activation = (Activation) context.terminalTupleMap.get( context.readInt() ).getObject(); this.beliefSet = (BeliefSet) this.tms.getJustifiedMap().get( handle.getId() ); for ( LinkedListEntry entry = (LinkedListEntry) beliefSet.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) { final LogicalDependency node = (LogicalDependency) entry.getObject(); if ( node.getJustifier() == this.activation ) { this.node = node; break; } } }
public void read(LogicalDependency node, BeliefSet beliefSet, PropagationContext context, ObjectTypeConf typeConf) { beliefSet.add( node.getJustifierEntry() ); }
public void removeLogicalDependency(final Activation activation, final LogicalDependency node, final PropagationContext context) { final InternalFactHandle handle = (InternalFactHandle) node.getJustified(); final BeliefSet beliefSet = (BeliefSet) this.justifiedMap.get( handle.getId() ); if ( beliefSet != null ) { beliefSystem.delete( node, beliefSet, context ); } }
/** * An Activation is no longer true so it no longer justifies any of the logical facts * it logically asserted. It iterates over the Activation's LinkedList of DependencyNodes * it retrieves the justitication set for each DependencyNode's FactHandle and removes * itself. If the Set is empty it retracts the FactHandle from the WorkingMemory. * * @param activation * @param context * @param rule * @throws FactException */ public void removeLogicalDependencies(final Activation activation, final PropagationContext context, final Rule rule) throws FactException { final LinkedList<LogicalDependency> list = activation.getLogicalDependencies(); if ( list == null || list.isEmpty() ) { return; } for ( LogicalDependency node = list.getFirst(); node != null; node = node.getNext() ) { removeLogicalDependency( activation, node, context ); } }
for (LogicalDependency node = list.getFirst(); node != null; node = node.getNext() ) { stream.writeShort( PersisterEnums.LOGICAL_DEPENDENCY ); stream.writeInt( ((InternalFactHandle) node.getJustified()).getId() );
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() ); } }
/** * The FactHandle is being removed from the system so remove any logical dependencies * between the justified FactHandle and its justifiers. Removes the FactHandle key * from the justifiedMap. It then iterates over all the LogicalDependency nodes, if any, * in the returned Set and removes the LogicalDependency node from the LinkedList maintained * by the Activation. * * @see LogicalDependency * * @param handle - The FactHandle to be removed * @throws FactException */ public void removeLogicalDependencies(final InternalFactHandle handle) throws FactException { final BeliefSet beliefSet = (BeliefSet) this.justifiedMap.remove( handle.getId() ); if ( beliefSet != null && !beliefSet.isEmpty() ) { for ( LinkedListEntry entry = (LinkedListEntry) beliefSet.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) { final LogicalDependency node = (LogicalDependency) entry.getObject(); node.getJustifier().getLogicalDependencies().remove( node ); } } }
public void insert(LogicalDependency node, BeliefSet beliefSet, PropagationContext context, ObjectTypeConf typeConf) { boolean empty = beliefSet.isEmpty(); beliefSet.add( node.getJustifierEntry() ); if ( empty) { InternalFactHandle handle = (InternalFactHandle) node.getJustified(); ((NamedEntryPoint)handle.getEntryPoint()).insert( handle, handle.getObject(), node.getJustifier().getRule(), node.getJustifier(), typeConf ); } }
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 LogicalRetractCallback(MarshallerReaderContext context, Action _action) { LogicalRetract _retract = _action.getLogicalRetract(); this.tms = context.wm.getTruthMaintenanceSystem(); this.handle = context.handles.get( _retract.getHandleId() ); this.activation = (Activation) context.filter .getTuplesCache().get( PersisterHelper.createActivationKey( _retract.getActivation().getPackageName(), _retract.getActivation().getRuleName(), _retract.getActivation().getTuple() ) ).getObject(); this.context = this.activation.getPropagationContext(); this.beliefSet = (BeliefSet) this.tms.getJustifiedMap().get( handle.getId() ); for ( LinkedListEntry entry = (LinkedListEntry) beliefSet.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) { final LogicalDependency node = (LogicalDependency) entry.getObject(); if ( node.getJustifier() == this.activation ) { this.node = node; break; } } }
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 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 ); } }
for (LinkedListEntry node = (LinkedListEntry) list.getFirst(); node != null; node = (LinkedListEntry) node.getNext()) { LogicalDependency dependency = (LogicalDependency) node.getObject(); org.drools.spi.Activation activation = dependency.getJustifier(); ProtobufMessages.Activation _activation = ProtobufMessages.Activation.newBuilder() .setPackageName(activation.getRule().getPackage())