public NamedEntryPoint(EntryPoint entryPoint, EntryPointNode entryPointNode, AbstractWorkingMemory wm, ReentrantLock lock) { this.entryPoint = entryPoint; this.entryPointNode = entryPointNode; this.wm = wm; this.ruleBase = (InternalRuleBase) this.wm.getRuleBase(); this.lock = lock; this.typeConfReg = new ObjectTypeConfigurationRegistry( this.ruleBase ); this.handleFactory = this.wm.getFactHandleFactory(); this.objectStore = new SingleThreadedObjectStore( this.ruleBase.getConfiguration(), this.lock ); }
/** * Retract a fact object from this <code>RuleBase</code> and the specified * <code>WorkingMemory</code>. * * @param handle * The handle of the fact to retract. * @param workingMemory * The working memory session. */ public void retractObject(final InternalFactHandle handle, final PropagationContext context, final InternalWorkingMemory workingMemory) { EntryPoint entryPoint = context.getEntryPoint(); EntryPointNode node = this.entryPoints.get( entryPoint ); ObjectTypeConf typeConf = ((InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( entryPoint.getEntryPointId() )).getObjectTypeConfigurationRegistry().getObjectTypeConf( entryPoint, handle.getObject() ); node.retractObject( handle, context, typeConf, workingMemory ); }
private static void writeObjectTypeConfiguration( MarshallerWriteContext context, ObjectTypeConfigurationRegistry otcr, org.drools.marshalling.impl.ProtobufMessages.EntryPoint.Builder _epb ) { Collection<ObjectTypeConf> values = otcr.values(); ObjectTypeConf[] otcs = values.toArray( new ObjectTypeConf[ values.size() ] ); Arrays.sort( otcs, new Comparator<ObjectTypeConf>() { public int compare(ObjectTypeConf o1, ObjectTypeConf o2) { return o1.getTypeName().compareTo(o2.getTypeName()); } }); for( ObjectTypeConf otc : otcs ) { final ObjectTypeNodeMemory memory = (ObjectTypeNodeMemory) context.wm.getNodeMemory(otc.getConcreteObjectTypeNode()); if (memory != null && !memory.memory.isEmpty()) { ObjectTypeConfiguration _otc = ObjectTypeConfiguration.newBuilder() .setType(otc.getTypeName()) .setTmsEnabled(otc.isTMSEnabled()) .build(); _epb.addOtc(_otc); } } }
/** * This is the entry point into the network for all asserted Facts. Iterates a cache * of matching <code>ObjectTypdeNode</code>s asserting the Fact. If the cache does not * exist it first iteraes and builds the cache. * * @param factHandle * The FactHandle of the fact to assert * @param context * The <code>PropagationContext</code> of the <code>WorkingMemory</code> action * @param workingMemory * The working memory session. */ public void assertObject(final InternalFactHandle factHandle, final PropagationContext context, final InternalWorkingMemory workingMemory) { EntryPoint entryPoint = context.getEntryPoint(); EntryPointNode node = this.entryPoints.get( entryPoint ); ObjectTypeConf typeConf = ((InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( entryPoint.getEntryPointId() )).getObjectTypeConfigurationRegistry().getObjectTypeConf( entryPoint, factHandle.getObject() ); node.assertObject( factHandle, context, typeConf, workingMemory ); }
public void dispose() { if( dynamicFacts != null ) { // first we check for facts that were inserted into the working memory // using the old API and setting a per instance dynamic flag and remove the // session from the listeners list in the bean for( InternalFactHandle handle : dynamicFacts ) { removePropertyChangeListener( handle, false ); } dynamicFacts = null; } for( ObjectTypeConf conf : this.typeConfReg.values() ) { // then, we check if any of the object types were configured using the // @propertyChangeSupport annotation, and clean them up if( conf.isDynamic() && conf.isSupportsPropertyChangeListeners() ) { // it is enough to iterate the facts on the concrete object type nodes // only, as the facts will always be in their concrete object type nodes // even if they were also asserted into higher level OTNs as well ObjectTypeNode otn = conf.getConcreteObjectTypeNode(); final ObjectHashSet memory = ((ObjectTypeNodeMemory) this.getInternalWorkingMemory().getNodeMemory( otn )).memory; Iterator it = memory.iterator(); for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) { InternalFactHandle handle = (InternalFactHandle) entry.getValue(); removePropertyChangeListener( handle, false ); } } } } }
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 ); } }
public void updateSink(final ObjectSink sink, final PropagationContext context, final InternalWorkingMemory workingMemory) { // @todo // JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so iterate and reset all caches. final ObjectTypeNode node = (ObjectTypeNode) sink; final ObjectType newObjectType = node.getObjectType(); InternalWorkingMemoryEntryPoint wmEntryPoint = (InternalWorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint( this.entryPoint.getEntryPointId() ); for ( ObjectTypeConf objectTypeConf : wmEntryPoint.getObjectTypeConfigurationRegistry().values() ) { if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) { objectTypeConf.resetCache(); ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode(); Iterator it = ((ObjectTypeNodeMemory) workingMemory.getNodeMemory( sourceNode )).memory.iterator(); for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) { sink.assertObject( (InternalFactHandle) entry.getValue(), context, workingMemory ); } } } }
@SuppressWarnings("unchecked") private InternalFactHandle createFactHandle(final LeftTuple leftTuple, final PropagationContext context, final InternalWorkingMemory workingMemory) { InternalFactHandle handle = null; ProtobufMessages.FactHandle _handle = null; if( context.getReaderContext() != null ) { Map<ProtobufInputMarshaller.TupleKey, ProtobufMessages.FactHandle> map = (Map<ProtobufInputMarshaller.TupleKey, ProtobufMessages.FactHandle>) context.getReaderContext().nodeMemories.get( getId() ); if( map != null ) { _handle = map.get( PersisterHelper.createTupleKey( leftTuple ) ); } } if( _handle != null ) { // create a handle with the given id handle = workingMemory.getFactHandleFactory().newFactHandle( _handle.getId(), leftTuple, _handle.getRecency(), workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(), leftTuple ), workingMemory, null ); // so far, result is not an event } else { handle = workingMemory.getFactHandleFactory().newFactHandle( leftTuple, workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(), leftTuple ), workingMemory, null ); // so far, result is not an event } return handle; }
result, _handle.getRecency(), workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(), result ), workingMemory, workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(), result ), workingMemory,
int factHandleId = stream.readInt(); InternalFactHandle handle = (InternalFactHandle) context.handles.get( factHandleId ); ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( ((NamedEntryPoint)handle.getEntryPoint()).getEntryPoint(), handle.getObject() ); tms.addLogicalDependency( handle,
ObjectTypeConf typeConf = ( (InternalWorkingMemoryEntryPoint) factHandle.getEntryPoint() ).getObjectTypeConfigurationRegistry().getObjectTypeConf( ep, object ); ObjectTypeNode[] cachedNodes = typeConf.getObjectTypeNodes();
ObjectTypeConfigurationRegistry reg = ep.getObjectTypeConfigurationRegistry(); ObjectTypeConf coreConf = reg.getObjectTypeConf( ep.getEntryPoint(), core ); ObjectTypeConf innerConf = reg.getObjectTypeConf( ep.getEntryPoint(), inner ); if ( coreConf.isTMSEnabled() ) { innerConf.enableTMS();
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( ((NamedEntryPoint)handle.getEntryPoint()).getEntryPoint(), handle.getObject() ); if (!typeConf.isTMSEnabled() && (!wasOTCSerialized || tmsEnabled.contains(typeConf.getTypeName()) ) ) { _activation.getTuple() ) ).getObject(); PropagationContext pc = activation.getPropagationContext(); ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( ((NamedEntryPoint)handle.getEntryPoint()).getEntryPoint(), handle.getObject() ); tms.readLogicalDependency( handle,
public void execute(InternalWorkingMemory workingMemory) { InternalFactHandle factHandle = (InternalFactHandle) leftTuple.getObject(); if ( node.isOpenQuery() ) { // iterate to the query terminal node, as the child leftTuples will get picked up there workingMemory.getEntryPointNode().retractObject( factHandle, context, workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( workingMemory.getEntryPoint(), factHandle.getObject() ), workingMemory ); //workingMemory.getFactHandleFactory().destroyFactHandle( factHandle ); } else { // get child left tuples, as there is no open query if ( leftTuple.getFirstChild() != null ) { node.getSinkPropagator().propagateRetractLeftTuple( leftTuple, context, workingMemory ); } } }
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( ((InternalWorkingMemoryEntryPoint) context.wm.getEntryPoints().get( _handle.getEntryPoint() ) ).getEntryPoint(), object );
public void initInitialFact( InternalRuleBase ruleBase, MarshallerReaderContext context ) { ruleBase.lock(); Object initialFact = InitialFactImpl.getInstance(); ObjectTypeConf otc = this.defaultEntryPoint.getObjectTypeConfigurationRegistry() .getObjectTypeConf( this.defaultEntryPoint.entryPoint, initialFact ); this.initialFactHandle = ruleBase.getConfiguration().getComponentFactory().getFactHandleFactoryService().newFactHandle( 0, initialFact, 0, otc, this, this.defaultEntryPoint ); final PropagationContext pctx = new PropagationContextImpl( 0, PropagationContext.ASSERTION, null, null , initialFactHandle, 0, 0, defaultEntryPoint.getEntryPoint(), context ); otc.getConcreteObjectTypeNode().assertObject( this.initialFactHandle, pctx, this ); // ADDED, NOT IN THE ORIGINAL 6.x COMMIT pctx.evaluateActionQueue( this ); ruleBase.unlock(); }
public InternalWorkingMemory newWorkingMemory() { this.ruleBase.readLock(); try { InternalWorkingMemory wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(), this.ruleBase, this.sessionConf, EnvironmentFactory.newEnvironment(), this.workingMemoryEventSupport, this.agendaEventSupport); wm.setGlobalResolver( this.globalResolver ); final InternalFactHandle handle = wm.getFactHandleFactory().newFactHandle( InitialFactImpl.getInstance(), wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( EntryPoint.DEFAULT, InitialFactImpl.getInstance() ), wm, wm); wm.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle, false, true, null, null ) ); return wm; } finally { this.ruleBase.readUnlock(); } }
confEP = context.wm.getEntryPoint(); ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( confEP, object );
final ObjectTypeConf typeConf = this.typeConfReg.getObjectTypeConf( this.entryPoint, object );
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; } }