Package org.drools.core.spi

Examples of org.drools.core.spi.PropagationContext


        RightTupleSets stagedRightTuples = memory.getStagedRightTuples();

        boolean stagedDeleteWasEmpty = false;
        if ( isStreamMode() ) {
            stagedDeleteWasEmpty = memory.getSegmentMemory().getTupleQueue().isEmpty();
            PropagationContext pctx = rightTuple.getPropagationContext();
            int propagationType = pctx.getType() == PropagationContext.MODIFICATION ? PropagationContext.DELETION : pctx.getType();
            memory.getSegmentMemory().getTupleQueue().add(new RightTupleEntry(rightTuple, pctx, memory, propagationType));
            if ( log.isTraceEnabled() ) {
                log.trace( "JoinNode delete queue={} size={} pctx={} lt={}", System.identityHashCode( memory.getSegmentMemory().getTupleQueue() ), memory.getSegmentMemory().getTupleQueue().size(), PhreakPropagationContext.intEnumToString(rightTuple.getPropagationContext()), rightTuple );
            }
        } else {
View Full Code Here



        boolean stagedUpdateWasEmpty = false;
        if ( streamMode ) {
            stagedUpdateWasEmpty = memory.getSegmentMemory().getTupleQueue().isEmpty();
            PropagationContext pctx = rightTuple.getPropagationContext();
            memory.getSegmentMemory().getTupleQueue().add(new RightTupleEntry(rightTuple, pctx, memory, pctx.getType()));
        } else {
            stagedUpdateWasEmpty = stagedRightTuples.addUpdate( rightTuple );
        }

        if ( stagedUpdateWasEmpty  ) {
View Full Code Here

                                                                                                workingMemory,
                                                                                                MatchCancelledCause.CLEAR );
            }

            PropagationContextFactory pctxFactory =((InternalRuleBase)workingMemory.getRuleBase()).getConfiguration().getComponentFactory().getPropagationContextFactory();
            final PropagationContext propagationContext = pctxFactory.createPropagationContext(workingMemory.getNextPropagationIdCounter(), PropagationContext.RULE_REMOVAL, null, null, null);
            TruthMaintenanceSystemHelper.removeLogicalDependencies( activation,
                                                                    propagationContext,
                                                                    node.getRule() );
            leftTuple.unlinkFromLeftParent();
            leftTuple.unlinkFromRightParent();
View Full Code Here

            return;
        }

        for ( InternalWorkingMemory workingMemory : context.getWorkingMemories() ) {
            PropagationContextFactory pctxFactory =((InternalRuleBase)workingMemory.getRuleBase()).getConfiguration().getComponentFactory().getPropagationContextFactory();
            final PropagationContext propagationContext = pctxFactory.createPropagationContext(workingMemory.getNextPropagationIdCounter(), PropagationContext.RULE_ADDITION, null, null, null);
            this.tupleSource.updateSink( this,
                                         propagationContext,
                                         workingMemory );
        }
    }
View Full Code Here

            return;
        }

        for ( InternalWorkingMemory workingMemory : context.getWorkingMemories() ) {
            PropagationContextFactory pctxFactory = context.getComponentFactory().getPropagationContextFactory();
            final PropagationContext propagationContext = pctxFactory.createPropagationContext(workingMemory.getNextPropagationIdCounter(), PropagationContext.RULE_ADDITION,
                                                                                               null, null, null);
            this.leftInput.updateSink( this,
                                         propagationContext,
                                         workingMemory );
        }
View Full Code Here

            if ( logical && !typeConf.isTMSEnabled()) {
                enableTMS(object, typeConf);
            }

            InternalFactHandle handle = null;
            final PropagationContext propagationContext = this.pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.INSERTION, rule,
                                                                                                    (activation == null) ? null : activation.getTuple(), handle, entryPoint);

            if ( this.wm.isSequential() ) {
                handle = createHandle( object,
                                       typeConf );
                propagationContext.setFactHandle(handle);
                insert( handle,
                        object,
                        rule,
                        activation,
                        typeConf,
                        propagationContext );
                return handle;
            }

           
            try {
                this.lock.lock();
                this.ruleBase.readLock();
                // check if the object already exists in the WM
                handle = this.objectStore.getHandleForObject( object );

                if ( typeConf.isTMSEnabled() ) {
                    TruthMaintenanceSystem tms = getTruthMaintenanceSystem();
                   
                    if ( handle != null ) {
                        propagationContext.setFactHandle(handle);
                        insertWhenHandleExists( object, tmsValue, logical, rule, activation, typeConf, handle, tms, propagationContext );
                        return handle;
                    }

                    // get the key for other "equal" objects, returns null if none exist
                    EqualityKey key = tms.get( object );
                   
                    if ( logical ) { 
                        if ( key != null && key.getStatus() == EqualityKey.STATED ) {
                            // You cannot logically insert a previously stated equality equal object, so return null                           
                            return null;
                        }
                       

                       
                        if ( key == null ) {
                            handle = createHandle( object,
                                                   typeConf ); // we know the handle is null
                           
                            key = new EqualityKey( handle );
                            handle.setEqualityKey( key );
                            tms.put( key );                          
                            key.setStatus( EqualityKey.JUSTIFIED ); // new Key, so we know it's JUSTIFIED                
                        } else {
                            handle = key.getFactHandle();
                        }
                       
                       // Any logical propagations are handled via the TMS.addLogicalDependency
                       tms.addLogicalDependency( handle,
                                                 object,
                                                 tmsValue,
                                                 activation,
                                                 activation.getPropagationContext(),
                                                 rule,
                                                 typeConf );
                       
                        return key.getFactHandle();
                                                   
                    } else { // !logical                    
                        if ( key == null ) {
                            handle = createHandle( object,
                                                   typeConf ); // we know the handle is null                           
                            key = new EqualityKey( handle );                       
                            handle.setEqualityKey( key );                           
                            tms.put( key );                 
                        } else if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
                                // Its previous justified, so switch to stated
                                key.setStatus( EqualityKey.STATED ); // must be done before the justifiedHandle retract 
                               
                                // remove logical dependencies
                                final InternalFactHandle justifiedHandle = key.getFactHandle();
                                propagationContext.setFactHandle( justifiedHandle ); // necessary to stop recursive retractions
                                TruthMaintenanceSystemHelper.clearLogicalDependencies( justifiedHandle, propagationContext );
                               
                                // now update existing handle to new value
                                return update( justifiedHandle, true, object, Long.MAX_VALUE, Object.class, activation );
                        } else   // STATED
                            handle = createHandle( object,
                                                   typeConf ); // we know the handle is null                                                   
                            handle.setEqualityKey( key );                                                   
                            key.addFactHandle( handle );
                        }
                        key.setStatus( EqualityKey.STATED ); // KEY is always stated
                    }                   
                } else {
                    // TMS not enabled for this object type
                    if ( handle != null ) {
                        return handle;
                    }
                    handle = createHandle( object,
                                           typeConf );
                }
                propagationContext.setFactHandle(handle);

                // if the dynamic parameter is true or if the user declared the fact type with the meta tag:
                // @propertyChangeSupport
                if ( dynamic || typeConf.isDynamic() ) {
                    addPropertyChangeListener( handle, dynamic );
View Full Code Here

        if ( activation != null ) {
            // release resources so that they can be GC'ed
            activation.getPropagationContext().releaseResources();
        }
        PropagationContext propagationContext = pctx;
        if ( pctx == null ) {
            propagationContext = pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.INSERTION,
                                                                      rule, (activation == null) ? null : activation.getTuple(), handle, entryPoint);
        }

        this.entryPointNode.assertObject( handle,
                                          propagationContext,
                                          typeConf,
                                          this.wm );
       
        propagationContext.evaluateActionQueue( this.wm );

        this.wm.workingMemoryEventSupport.fireObjectInserted( propagationContext,
                                                              handle,
                                                              object,
                                                              this.wm );
View Full Code Here

            }

            this.handleFactory.increaseFactHandleRecency( handle );
            Rule rule = activation == null ? null : activation.getRule();

            final PropagationContext propagationContext = pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.MODIFICATION,
                                                                                               rule, (activation == null) ? null : activation.getTuple(),
                                                                                               handle, entryPoint, mask, modifiedClass, null);
           
            if ( typeConf.isTMSEnabled() ) {
                EqualityKey newKey = tms.get( object );
                EqualityKey oldKey = handle.getEqualityKey();
                if ( newKey == null ) {                   
                    if ( oldKey.getStatus() == EqualityKey.JUSTIFIED ) {
                        // new target key is JUSTFIED, updates are always STATED
                        TruthMaintenanceSystemHelper.removeLogicalDependencies( oldKey.getFactHandle(), propagationContext );
                    }
                   
                    oldKey.removeFactHandle( handle );
                    // If the equality key is now empty, then remove it
                    if ( oldKey.isEmpty() ) {
                        getTruthMaintenanceSystem().remove( oldKey );
                    }                   
                   
                    newKey = new EqualityKey( handle,
                                              EqualityKey.STATED ); // updates are always stated
                    handle.setEqualityKey( newKey );
                    getTruthMaintenanceSystem().put( newKey );
                } else if ( newKey != oldKey ) {
                    oldKey.removeFactHandle( handle );
                    // If the equality key is now empty, then remove it
                    if ( oldKey.isEmpty() ) {
                        getTruthMaintenanceSystem().remove( oldKey );
                   
                   
                    if ( newKey.getStatus() == EqualityKey.JUSTIFIED ) {
                        // new target key is JUSTITIED, updates are always STATED
                        TruthMaintenanceSystemHelper.removeLogicalDependencies( newKey.getFactHandle(), propagationContext );
                        newKey.setStatus( EqualityKey.STATED );
                    }
                    // the caller needs the new handle
                    handle = newKey.getFactHandle();
                } else if ( !updateLogical &&  oldKey.getStatus() == EqualityKey.JUSTIFIED  ) {
                    // new target key is JUSTIFIED, updates are always STATED
                    TruthMaintenanceSystemHelper.removeLogicalDependencies( oldKey.getFactHandle(), propagationContext );                    
                }
            }

            this.entryPointNode.modifyObject( handle,
                                              propagationContext,
                                              typeConf,
                                              this.wm );
           
            propagationContext.evaluateActionQueue( this.wm );

            this.wm.workingMemoryEventSupport.fireObjectUpdated( propagationContext,
                                                                 handle,
                                                                 originalObject,
                                                                 object,
View Full Code Here

           
            if ( activation != null ) {
                // release resources so that they can be GC'ed
                activation.getPropagationContext().releaseResources();
            }
            final PropagationContext propagationContext = pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.DELETION,
                                                                                               rule, (activation == null) ? null : activation.getTuple(),
                                                                                               handle, this.entryPoint);

            this.entryPointNode.retractObject( handle,
                                               propagationContext,
                                               typeConf,
                                               this.wm );

            if ( typeConf.isTMSEnabled() ) {
                TruthMaintenanceSystem tms = getTruthMaintenanceSystem();

                // TMS.removeLogicalDependency also cleans up Handles from the EqualityKey
                // This can happen on the logical retraction of the last FH, where it's cleaned up in the TMS and also in the main network.
                // However when the user retracts the FH to a logical set of insertions, then we need to clean up the TMS here.
                                                  
                // Update the equality key, which maintains a list of stated FactHandles
                final EqualityKey key = handle.getEqualityKey();

                // Its justified so attempt to remove any logical dependencies for the handle
                if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
                    TruthMaintenanceSystemHelper.removeLogicalDependencies( handle, propagationContext );
                }
                key.removeFactHandle( handle );
                handle.setEqualityKey( null );
               
                // If the equality key is now empty, then remove it
                if ( key.isEmpty() ) {
                    tms.remove( key );
                }
            }

            if ( handle.isTraiting() && handle.getObject() instanceof TraitProxy ) {
                (( (TraitProxy) handle.getObject() ).getObject()).removeTrait( ( (TraitProxy) handle.getObject() ).getTypeCode() );
            }

            propagationContext.evaluateActionQueue( this.wm );
           

            this.wm.workingMemoryEventSupport.fireObjectRetracted( propagationContext,
                                                                   handle,
                                                                   object,
View Full Code Here

        for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
            LeftTuple next = leftTuple.getStagedNext();

            FastIterator it = notNode.getRightIterator(rtm);
            PropagationContext context = leftTuple.getPropagationContext();

            boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(notNode, leftTuple);

            constraints.updateFromTuple(contextEntry,
                                        wm,
View Full Code Here

TOP

Related Classes of org.drools.core.spi.PropagationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.