Examples of BetaMemory


Examples of org.drools.core.reteoo.BetaMemory

        assertEquals( (indexedPositions.length > 0),
                      betaConstraints.isIndexed() );
        assertEquals( indexedPositions.length,
                      betaConstraints.getIndexCount() );
        BetaMemory betaMemory = betaConstraints.createBetaMemory( config, NodeTypeEnums.JoinNode );

        if ( indexedPositions.length > 0 ) {
            if (((IndexableConstraint)constraints[indexedPositions[0]]).getConstraintType() == ConstraintType.EQUAL) {
                LeftTupleIndexHashTable tupleHashTable = (LeftTupleIndexHashTable) betaMemory.getLeftTupleMemory();
                assertTrue( tupleHashTable.isIndexed() );
                Index index = tupleHashTable.getIndex();

                for ( int i = 0; i < indexedPositions.length; i++ ) {
                    checkSameConstraintForIndex( (IndexableConstraint)constraints[indexedPositions[i]],
                                                 index.getFieldIndex( i ) );
                }

                RightTupleIndexHashTable factHashTable = (RightTupleIndexHashTable) betaMemory.getRightTupleMemory();
                assertTrue( factHashTable.isIndexed() );
                index = factHashTable.getIndex();

                for ( int i = 0; i < indexedPositions.length; i++ ) {
                    checkSameConstraintForIndex( (IndexableConstraint)constraints[indexedPositions[i]],
                                                 index.getFieldIndex( i ) );
                }
            } else {

            }
        } else {
            LeftTupleList tupleHashTable = (LeftTupleList) betaMemory.getLeftTupleMemory();
            assertFalse( tupleHashTable.isIndexed() );

            RightTupleList factHashTable = (RightTupleList) betaMemory.getRightTupleMemory();
            assertFalse( factHashTable.isIndexed() );
        }
    }
View Full Code Here

Examples of org.drools.core.reteoo.BetaMemory

        BetaConstraints betaConstraints = null;
       
        betaConstraints = new SingleBetaConstraints(constraints, config);
       
        BetaMemory betaMemory = betaConstraints.createBetaMemory( config, NodeTypeEnums.JoinNode );
       
        RuleBase rb = RuleBaseFactory.newRuleBase();
        StatefulSession ss = rb.newStatefulSession();
       
        InternalFactHandle fh1 = (InternalFactHandle) ss.insert( new Foo( "brie", 1) );
        InternalFactHandle fh2 = (InternalFactHandle) ss.insert( new Foo( "brie", 1) );
        InternalFactHandle fh3 = (InternalFactHandle) ss.insert( new Foo( "soda", 1) );
        InternalFactHandle fh4 = (InternalFactHandle) ss.insert( new Foo( "soda", 1) );
        InternalFactHandle fh5 = (InternalFactHandle) ss.insert( new Foo( "bread", 3) );
        InternalFactHandle fh6 = (InternalFactHandle) ss.insert( new Foo( "bread", 3) );
        InternalFactHandle fh7 = (InternalFactHandle) ss.insert( new Foo( "cream", 3) );
        InternalFactHandle fh8 = (InternalFactHandle) ss.insert( new Foo( "gorda", 15) );
        InternalFactHandle fh9 = (InternalFactHandle) ss.insert( new Foo( "beer", 16) );
       
        InternalFactHandle fh10 = (InternalFactHandle) ss.insert( new Foo( "mars", 0) );
        InternalFactHandle fh11 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
        InternalFactHandle fh12 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
        InternalFactHandle fh13 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
       
        betaMemory.getRightTupleMemory().add( new RightTuple( fh1, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh2, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh3, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh4, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh5, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh6, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh7, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh8, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh9, null ) );
       
        RightTupleIndexHashTable hashTable = (RightTupleIndexHashTable) betaMemory.getRightTupleMemory();
        // can't create a 0 hashCode, so forcing
        RightTupleList rightTupleList = new RightTupleList();
        rightTupleList.add( new RightTuple( fh10, null) );
        hashTable.getTable()[0] = rightTupleList;
        rightTupleList = new RightTupleList();
        rightTupleList.add( new RightTuple( fh11, null ) );
        rightTupleList.add( new RightTuple( fh12, null ) );
        rightTupleList.add( new RightTuple( fh13, null ) );
        ((RightTupleList)hashTable.getTable()[0]).setNext( rightTupleList );
       
        Entry[] table = hashTable.getTable();
        List list = new ArrayList();
        for ( int i = 0; i < table.length; i++ ) {
            if ( table[i] != null ) {
                List entries = new ArrayList();
                entries.add( i );
                Entry entry = table[i];
                while ( entry != null ) {
                    entries.add( entry );
                    entry = entry.getNext();
                }
                list.add( entries.toArray() );
            }
        }
        assertEquals( 5, list.size() );
       
        Object[] entries = (Object[]) list.get( 0 );
        assertEquals( 0, entries[0]);
        assertEquals( 3, entries.length );
       
        entries = (Object[]) list.get( 1 );
        assertEquals( 102, entries[0]);
        assertEquals( 2, entries.length );
       
        entries = (Object[]) list.get( 2 );
        assertEquals( 103, entries[0]);
        assertEquals( 2, entries.length );
       
        entries = (Object[]) list.get( 3 );
        assertEquals( 115, entries[0]);
        assertEquals( 3, entries.length );
       
        entries = (Object[]) list.get( 4 );
        assertEquals( 117, entries[0]);
        assertEquals( 3, entries.length );
       
       
        //System.out.println( entries );

        list = new ArrayList<LeftTupleImpl>();
        Iterator it = betaMemory.getRightTupleMemory().iterator();
        for ( RightTuple rightTuple = ( RightTuple ) it.next(); rightTuple != null; rightTuple = ( RightTuple ) it.next() ) {
            list.add( rightTuple );
        }
       
        assertEquals( 13, list.size() );
View Full Code Here

Examples of org.drools.core.reteoo.BetaMemory

            }
        }

        assertNotNull(joinNode);
        InternalWorkingMemory wm = (InternalWorkingMemory)ksession;
        BetaMemory memory = (BetaMemory)wm.getNodeMemory(joinNode);
        RightTupleSets stagedRightTuples = memory.getStagedRightTuples();
        assertEquals(0, stagedRightTuples.deleteSize());
        assertNull(stagedRightTuples.getDeleteFirst());
        assertEquals(0, stagedRightTuples.insertSize());
        assertNull(stagedRightTuples.getInsertFirst());
    }
View Full Code Here

Examples of org.drools.core.reteoo.BetaMemory

                    case PropagationContext.RULE_REMOVAL:
                        tuples.addDelete(tupleEntry.getLeftTuple());
                        break;
                }
            } else {
                BetaMemory bm = (BetaMemory) tupleEntry.getNodeMemory();
                tupleEntry.getRightTuple().setPropagationContext(tupleEntry.getPropagationContext());
                switch (tupleEntry.getPropagationType()) {
                    case PropagationContext.INSERTION:
                    case PropagationContext.RULE_ADDITION:
                        bm.getStagedRightTuples().addInsert(tupleEntry.getRightTuple());
                        break;
                    case PropagationContext.MODIFICATION:
                        bm.getStagedRightTuples().addUpdate(tupleEntry.getRightTuple());
                        break;
                    case PropagationContext.DELETION:
                    case PropagationContext.EXPIRATION:
                    case PropagationContext.RULE_REMOVAL:
                        bm.getStagedRightTuples().addDelete(tupleEntry.getRightTuple());
                        break;
                }
            }
            if (!pmem.getTupleQueue().isEmpty()) {
                tupleEntry = pmem.getTupleQueue().peek();
View Full Code Here

Examples of org.drools.reteoo.BetaMemory

    public LeftTuple getFirstLeftTuple(LeftTupleSource source,
                                       LeftTupleSink sink,
                                       InternalWorkingMemory wm) {
        if ( source instanceof JoinNode || source instanceof NotNode || source instanceof FromNode ||source instanceof AccumulateNode ) {

            BetaMemory memory;
            FastIterator localIt;
            if ( source instanceof FromNode ) {
                memory = ((FromMemory) wm.getNodeMemory( (MemoryFactory) source )).betaMemory;
            } else if ( source instanceof AccumulateNode ) {
                memory = ((AccumulateMemory) wm.getNodeMemory( (MemoryFactory) source )).betaMemory;
            } else {
                memory = (BetaMemory) wm.getNodeMemory( (MemoryFactory) source );
            }

            localIt = memory.getLeftTupleMemory().fullFastIterator();
            LeftTuple leftTuple = BetaNode.getFirstLeftTuple( memory.getLeftTupleMemory(),
                                                              localIt );

            while ( leftTuple != null ) {
                for ( LeftTuple childleftTuple = leftTuple.getFirstChild(); childleftTuple != null; childleftTuple = childleftTuple.getLeftParentNext() ) {
                    if ( childleftTuple.getLeftTupleSink() == sink ) {
                        return childleftTuple;
                    }
                }
                leftTuple = (LeftTuple) localIt.next( leftTuple );
            }
        }
        if ( source instanceof ExistsNode ) {
            BetaMemory memory = (BetaMemory) wm.getNodeMemory( (MemoryFactory) source );
            FastIterator localIt = memory.getRightTupleMemory().fullFastIterator();

            RightTuple rightTuple = BetaNode.getFirstRightTuple( memory.getRightTupleMemory(),
                                                                 localIt );

            while ( rightTuple != null ) {
                if ( rightTuple.getBlocked() != null ) {
                    for ( LeftTuple leftTuple = rightTuple.getBlocked(); leftTuple != null; leftTuple = leftTuple.getBlockedNext() ) {
                        for ( LeftTuple childleftTuple = leftTuple.getFirstChild(); childleftTuple != null; childleftTuple = childleftTuple.getLeftParentNext() ) {
                            if ( childleftTuple.getLeftTupleSink() == sink ) {
                                return childleftTuple;
                            }
                        }
                    }

                }
                rightTuple = (RightTuple) localIt.next( rightTuple );
            }
        } else if ( source instanceof LeftInputAdapterNode ) {
            ObjectTypeNode otn = null;
            ObjectSource os = ((LeftInputAdapterNode) source).getParentObjectSource();
            while ( !(os instanceof ObjectTypeNode) ) {
                os = os.getParentObjectSource();
            }
            otn = (ObjectTypeNode) os;

            ObjectHashSet memory = ((ObjectTypeNodeMemory) wm.getNodeMemory( otn )).memory;
            otnIterator = memory.iterator();

            for ( factHandleEntry = (ObjectEntry) otnIterator.next(); factHandleEntry != null; factHandleEntry = (ObjectEntry) otnIterator.next() ) {
                InternalFactHandle handle = (InternalFactHandle) factHandleEntry.getValue();
                for ( LeftTuple leftTuple = handle.getFirstLeftTuple(); leftTuple != null; leftTuple = leftTuple.getLeftParentNext() ) {
                    if ( leftTuple.getLeftTupleSink() == sink ) {
View Full Code Here

Examples of org.drools.reteoo.BetaMemory

            // We've exhausted this OTN so set the iterator to null
            factHandleEntry = null;
            otnIterator = null;

        } else if ( source instanceof JoinNode || source instanceof NotNode|| source instanceof FromNode || source instanceof AccumulateNode ) {
            BetaMemory memory;
            FastIterator localIt;
            if ( source instanceof FromNode ) {
                memory = ((FromMemory) wm.getNodeMemory( (MemoryFactory) source )).betaMemory;
            } else if ( source instanceof AccumulateNode ) {
                memory = ((AccumulateMemory) wm.getNodeMemory( (MemoryFactory) source )).betaMemory;
            } else {
                memory = (BetaMemory) wm.getNodeMemory( (MemoryFactory) source );
            }

            localIt = memory.getLeftTupleMemory().fullFastIterator( leftTuple.getLeftParent() );

            LeftTuple childLeftTuple = leftTuple;
            if ( childLeftTuple != null ) {
                leftTuple = childLeftTuple.getLeftParent();

                while ( leftTuple != null ) {
                    if ( childLeftTuple == null ) {
                        childLeftTuple = leftTuple.getFirstChild();
                    } else {
                        childLeftTuple = childLeftTuple.getLeftParentNext();
                    }
                    for ( ; childLeftTuple != null; childLeftTuple = childLeftTuple.getLeftParentNext() ) {
                        if ( childLeftTuple.getLeftTupleSink() == sink ) {
                            return childLeftTuple;
                        }
                    }
                    leftTuple = (LeftTuple) localIt.next( leftTuple );
                }
            }
        }
        if ( source instanceof ExistsNode ) {
            BetaMemory memory = (BetaMemory) wm.getNodeMemory( (MemoryFactory) source );

            RightTuple rightTuple = leftTuple.getLeftParent().getBlocker();
            FastIterator localIt = memory.getRightTupleMemory().fullFastIterator( rightTuple );

            for ( LeftTuple childleftTuple = leftTuple.getLeftParentNext(); childleftTuple != null; childleftTuple = childleftTuple.getLeftParentNext() ) {
                if ( childleftTuple.getLeftTupleSink() == sink ) {
                    return childleftTuple;
                }
View Full Code Here

Examples of org.drools.reteoo.BetaMemory

            trgTuples = new StagedLeftTuples();
           
            if ( NodeTypeEnums.isBetaNode( node ) ) {
                BetaNode betaNode = ( BetaNode )node;
                BetaMemory bm = (BetaMemory) nodeMem;
                if ( betaNode.isRightInputIsRiaNode() ) {
                    StagedLeftTuples peerTuples = new StagedLeftTuples();
                    SegmentPropagator.processPeers( srcTuples, peerTuples, betaNode );
                   
                    // Make sure subnetwork Segment has tuples to process
                    SegmentMemory subSmem = bm.getSubnetworkSegmentMemory();
                    StagedLeftTuples subnetworkStaged =  subSmem.getStagedLeftTuples();
                    subnetworkStaged.addAllDeletes( srcTuples.getDeleteFirst() );
                    subnetworkStaged.addAllUpdates( srcTuples.getUpdateFirst() );
                    subnetworkStaged.addAllInserts( srcTuples.getInsertFirst() );
                  
                    List<RuleMemory> ruleMemories = subSmem.getRuleMemories();
                   
                    RiaRuleMemory rm = null;
                    if ( ruleMemories.size() == 1 ) {
                        rm = ( RiaRuleMemory) ruleMemories.get( 0 ) ;
                    } else {
                        for ( int i = 0, size = ruleMemories.size(); i < size; i++ ) {
                            if ( ruleMemories.get( i ) instanceof RiaRuleMemory ) {
                                rm = ( RiaRuleMemory) ruleMemories.get( i ) ;
                            }
                        }
                    }
                   
                    RightInputAdapterNode riaNode = ( RightInputAdapterNode ) betaNode.getRightInput();
                    // At this point we have the tuples to apply to the left and to the right of the subnetwork root node
                    StagedLeftTuples riaStagedTuples = eval( subSmem.getRootNode(), subSmem.getNodeMemories().getFirst(), rm.getSegmentMemories(), 0, srcTuples, null, wm );
                    StagedRightTuples riaStageRight = bm.getStagedRightTuples();
                    for ( LeftTuple leftTuple = riaStagedTuples.getInsertFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext() ) {
                        InternalFactHandle handle = riaNode.createFactHandle( leftTuple, leftTuple.getPropagationContext(), wm );
                        RightTuple rightTuple = betaNode.createRightTuple( handle, betaNode, leftTuple.getPropagationContext() );
                        //riaStagedTuples.
                    }
View Full Code Here

Examples of org.drools.reteoo.BetaMemory

      long nodePosMask = 1
      long allLinkedTestMask = 0;
     
      while ( true ) {
            if ( NodeTypeEnums.isBetaNode( tupleSource ) ) {
                BetaMemory betaMemory;
                BetaNode betaNode = ( BetaNode ) tupleSource;
                if ( NodeTypeEnums.AccumulateNode == tupleSource.getType() ) {      
                    betaMemory = (( AccumulateMemory ) smem.createNodeMemory( ( AccumulateNode ) tupleSource, wm  )).getBetaMemory();
                } else {                   
                    betaMemory = ( BetaMemory ) smem.createNodeMemory( betaNode, wm );
   
                }
   
                if ( betaNode.isRightInputIsRiaNode() ) {
                    // we need to iterate to find correct pair
                    // as there may be more than one set of sub networks, due to sharing.
                    LeftTupleSinkNode sinkNode = betaNode.getLeftTupleSource().getSinkPropagator().getFirstLeftTupleSink();
                    while ( sinkNode.getNextLeftTupleSinkNode() != betaNode ) {
                        sinkNode = sinkNode.getNextLeftTupleSinkNode();
                    }
                   
                    SegmentMemory subNetworkSegmentMemory = createSegmentMemory( ( LeftTupleSource ) sinkNode, wm );
                    betaMemory.setSubnetworkSegmentMemor( subNetworkSegmentMemory );
                }
               
                betaMemory.setSegmentMemory( smem );
                betaMemory.setNodePosMaskBit( nodePosMask );
                allLinkedTestMask = allLinkedTestMask | nodePosMask;
                if ( NodeTypeEnums.NotNode == tupleSource.getType() ||  NodeTypeEnums.AccumulateNode == tupleSource.getType())  {
                    // NotNode's and Accumulate are initialised as linkedin
                    smem.linkNode( nodePosMask, wm );
                }
View Full Code Here

Examples of org.drools.reteoo.BetaMemory

                                                  SegmentMemory smem,
                                                  InternalWorkingMemory wm) {
        for ( LeftTupleSink sink : lt.getSinkPropagator().getSinks() ) {
          if (NodeTypeEnums.isLeftTupleSource( sink ) ) {
              if ( sink.getType() == NodeTypeEnums.NotNode ) {
                  BetaMemory bm = ( BetaMemory) smem.createNodeMemory( (MemoryFactory) sink, wm  );
                   if ( bm.getSegmentMemory() == null ) {
                       // Not nodes must be initialised
                       createSegmentMemory( (NotNode) sink, wm );
                   }
              }
              updateRiaAndTerminalMemory(++pos, ( LeftTupleSource ) sink, originalLt, smem, wm);
View Full Code Here

Examples of org.drools.reteoo.BetaMemory

        return true;
    }

    public BetaMemory createBetaMemory(final RuleBaseConfiguration config,
                                       final short nodeType) {
        final BetaMemory memory = new BetaMemory( config.isSequential() ? null : new LeftTupleList(),
                                                  new RightTupleList(),
                                                  this.createContext(),
                                                  nodeType );

        return memory;
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.