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 static void readTruthMaintenanceSystem( MarshallerReaderContext context ) throws IOException { ObjectInputStream stream = context.stream; TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem(); while (stream.readShort() == PersisterEnums.EQUALITY_KEY) { int status = stream.readInt(); int factHandleId = stream.readInt(); InternalFactHandle handle = (InternalFactHandle) context.handles.get( factHandleId ); // ObjectTypeConf state is not marshalled, so it needs to be re-determined ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.wm.getEntryPoint(), handle.getObject() ); if (!typeConf.isTMSEnabled()) { typeConf.enableTMS(); } EqualityKey key = new EqualityKey( handle, status ); handle.setEqualityKey( key ); while (stream.readShort() == PersisterEnums.FACT_HANDLE) { factHandleId = stream.readInt(); handle = (InternalFactHandle) context.handles.get( factHandleId ); key.addFactHandle( handle ); handle.setEqualityKey( key ); } tms.put( key ); } }
TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem(); while (stream.readShort() == PersisterEnums.LOGICAL_DEPENDENCY) { int factHandleId = stream.readInt();
public static void writeTruthMaintenanceSystem(MarshallerWriteContext context) throws IOException { ObjectOutputStream stream = context.stream; ObjectHashMap assertMap = context.wm.getTruthMaintenanceSystem().getAssertMap(); EqualityKey[] keys = new EqualityKey[assertMap.size()]; org.drools.core.util.Iterator it = assertMap.iterator(); int i = 0; for ( org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next() ) { EqualityKey key = (EqualityKey) entry.getKey(); keys[i++] = key; } Arrays.sort( keys, EqualityKeySorter.instance ); // write the assert map of Equality keys for ( EqualityKey key : keys ) { stream.writeShort( PersisterEnums.EQUALITY_KEY ); stream.writeInt( key.getStatus() ); InternalFactHandle handle = key.getFactHandle(); stream.writeInt( handle.getId() ); //context.out.println( "EqualityKey int:" + key.getStatus() + " int:" + handle.getId() ); if ( key.getOtherFactHandle() != null && !key.getOtherFactHandle().isEmpty() ) { for ( InternalFactHandle handle2 : key.getOtherFactHandle() ) { stream.writeShort( PersisterEnums.FACT_HANDLE ); stream.writeInt( handle2.getId() ); //context.out.println( "OtherHandle int:" + handle2.getId() ); } } stream.writeShort( PersisterEnums.END ); } stream.writeShort( PersisterEnums.END ); }
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 void readTruthMaintenanceSystem( MarshallerReaderContext context, RuleData _session ) throws IOException { TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem(); ProtobufMessages.TruthMaintenanceSystem _tms = _session.getTms();
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(); } }
public static void writeTruthMaintenanceSystem(MarshallerWriteContext context, ProtobufMessages.RuleData.Builder _session) throws IOException { ObjectHashMap assertMap = context.wm.getTruthMaintenanceSystem().getAssertMap(); ObjectHashMap justifiedMap = context.wm.getTruthMaintenanceSystem().getJustifiedMap();
workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies(activation, context, rtn.getRule());