Examples of ObjectTypeConf


Examples of org.drools.core.reteoo.ObjectTypeConf

        if ( needsWrapping ) {
            InternalFactHandle h = (InternalFactHandle) lookupFactHandle( core );
            InternalWorkingMemoryEntryPoint ep = h != null ? (InternalWorkingMemoryEntryPoint) h.getEntryPoint() : (InternalWorkingMemoryEntryPoint) workingMemory.getEntryPoints().get( "DEFAULT" );
            ObjectTypeConfigurationRegistry reg = ep.getObjectTypeConfigurationRegistry();

            ObjectTypeConf coreConf = reg.getObjectTypeConf( ep.getEntryPoint(), core );

            ObjectTypeConf innerConf = reg.getObjectTypeConf( ep.getEntryPoint(), inner );
            if ( coreConf.isTMSEnabled() ) {
                innerConf.enableTMS();
            }
            if ( inner._getFieldTMS() != null && inner._getFieldTMS().needsInit() ) {
                inner._getFieldTMS().init( workingMemory );
            }
        } else {
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

    }

    public void initInitialFact(InternalRuleBase ruleBase, MarshallerReaderContext context) {
        this.initialFactHandle = new DefaultFactHandle(0, InitialFactImpl.getInstance(), 0,  defaultEntryPoint );

        ObjectTypeConf otc = this.defaultEntryPoint.getObjectTypeConfigurationRegistry()
                                                   .getObjectTypeConf(this.defaultEntryPoint.entryPoint, this.initialFactHandle.getObject());
        PropagationContextFactory ctxFact = ruleBase.getConfiguration().getComponentFactory().getPropagationContextFactory();


        final PropagationContext pctx = ctxFact.createPropagationContext(0, PropagationContext.INSERTION, null,
                                                                         null , initialFactHandle, defaultEntryPoint.getEntryPoint(),
                                                                         context );

        otc.getConcreteObjectTypeNode().assertObject(this.initialFactHandle, pctx, this );
    }
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

        assertEquals(
                "Now that a logical insert was done, it should have an element.",
                1, tms.getEqualityKeyMap().size());

        // Make sure the internals are fine.
        ObjectTypeConf typeConf = wm.getObjectTypeConfigurationRegistry()
                .getObjectTypeConf(wm.getEntryPoint(), fact1);

        assertTrue("Should have enabled TMS", typeConf.isTMSEnabled());

    }
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

        final Integer intFact1 = 99;
        final Integer intFact2 = 99;

        final Double doubleFact = 77.8;

        ObjectTypeConf stringTypeConf = wm.getObjectTypeConfigurationRegistry()
                .getObjectTypeConf(wm.getEntryPoint(), stringFact1);

        ObjectTypeConf intTypeConf = wm.getObjectTypeConfigurationRegistry()
                .getObjectTypeConf(wm.getEntryPoint(), intFact1);

        wm.insert(stringFact1);
        wm.insert(anotherString);
        wm.insert(intFact1);
        wm.insert(doubleFact);

        for (ObjectTypeConf conf : wm.getObjectTypeConfigurationRegistry()
                .values()) {

            assertFalse(
                    "TMS shouldn't be enabled for any type, since no logical insert was done.",
                    conf.isTMSEnabled());

        }

        wm.insertLogical(stringFact2);

        assertTrue("Should have enabled TMS for Strings.", stringTypeConf
                .isTMSEnabled());

        assertFalse("Shouldn't have enabled TMS for Integers.", intTypeConf
                .isTMSEnabled());

        wm.insertLogical(intFact2);

        assertTrue("Now it should have enabled TMS for Integers!.", intTypeConf
                .isTMSEnabled());

    }
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

        }

        try {
            this.wm.startOperation();

            ObjectTypeConf typeConf = this.typeConfReg.getObjectTypeConf( this.entryPoint,
                                                                          object );
            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 );
                }

                insert( handle,
                        object,
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

        if ( key == null ) {
            // Edge case: another object X, equivalent (equals+hashcode) to "object" Y
            // has been previously stated. However, if X is a subclass of Y, TMS
            // may have not been enabled yet, and key would be null.
            ObjectTypeConf typeC = this.typeConfReg.getObjectTypeConf( this.entryPoint, handle.getObject() );
            enableTMS( handle.getObject(), typeC );
            key = handle.getEqualityKey();
        }

        if ( key.getStatus() == EqualityKey.STATED ) {
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

           
            if ( handle.getEntryPoint() != this ) {
                throw new IllegalArgumentException( "Invalid Entry Point. You updated the FactHandle on entry point '" + handle.getEntryPoint().getEntryPointId() + "' instead of '" + getEntryPointId() + "'" );
            }
           
            final ObjectTypeConf typeConf = this.typeConfReg.getObjectTypeConf( this.entryPoint,
                                                                                object );

            // only needed if we maintain tms, but either way we must get it before we do the update
            int status = -1;
            if ( typeConf.isTMSEnabled() ) {
                status = handle.getEqualityKey().getStatus();
            }


            if ( handle.getId() == -1 || object == null || (handle.isEvent() && ((EventFactHandle) handle).isExpired()) ) {
                // the handle is invalid, most likely already retracted, so return and we cannot assert a null object
                return handle;
            }

            if ( activation != null ) {
                // release resources so that they can be GC'ed
                activation.getPropagationContext().releaseResources();
            }

            if ( originalObject != object || !AssertBehaviour.IDENTITY.equals( this.ruleBase.getConfiguration().getAssertBehaviour() ) ) {
                this.objectStore.removeHandle( handle );

                // set anyway, so that it updates the hashCodes
                handle.setObject( object );
                this.objectStore.addHandle( handle,
                                            object );
            }

            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
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

                throw new IllegalArgumentException( "Invalid Entry Point. You updated the FactHandle on entry point '" + handle.getEntryPoint().getEntryPointId() + "' instead of '" + getEntryPointId() + "'" );
            }           

            final Object object = handle.getObject();
           
            final ObjectTypeConf typeConf = this.typeConfReg.getObjectTypeConf( this.entryPoint,
                                                                                object );

            if( typeConf.isSupportsPropertyChangeListeners() ) {
                removePropertyChangeListener( handle, true );
            }         
           
            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.
View Full Code Here

Examples of org.drools.core.reteoo.ObjectTypeConf

    }

    public void initInitialFact(InternalRuleBase ruleBase, MarshallerReaderContext context) {
        this.initialFactHandle = new DefaultFactHandle(0, InitialFactImpl.getInstance(), 0,  defaultEntryPoint );

        ObjectTypeConf otc = this.defaultEntryPoint.getObjectTypeConfigurationRegistry()
                                                   .getObjectTypeConf(this.defaultEntryPoint.entryPoint, this.initialFactHandle.getObject());
        PropagationContextFactory ctxFact = ruleBase.getConfiguration().getComponentFactory().getPropagationContextFactory();


        final PropagationContext pctx = ctxFact.createPropagationContext(0, PropagationContext.INSERTION, null,
                                                                         null , initialFactHandle, defaultEntryPoint.getEntryPoint(),
                                                                         context );

        otc.getConcreteObjectTypeNode().assertObject(this.initialFactHandle, pctx, this );
    }
View Full Code Here

Examples of org.drools.reteoo.ObjectTypeConf

    private static void assertHandleIntoOTN(MarshallerReaderContext context,
                                            InternalWorkingMemory wm,
                                            InternalFactHandle handle) {
        Object object = handle.getObject();
        InternalWorkingMemoryEntryPoint ep = (InternalWorkingMemoryEntryPoint) handle.getEntryPoint();
        ObjectTypeConf typeConf = ((InternalWorkingMemoryEntryPoint) handle.getEntryPoint()).getObjectTypeConfigurationRegistry().getObjectTypeConf( ep.getEntryPoint(),
                                                                                                                                                     object );
        final PropagationContext propagationContext = new PropagationContextImpl( wm.getNextPropagationIdCounter(),
                                                                                  PropagationContext.ASSERTION,
                                                                                  null,
                                                                                  null,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.