Package org.drools.reteoo.ReteooBuilder

Examples of org.drools.reteoo.ReteooBuilder.IdGenerator


                                                                       PropagationContext.ASSERTION,
                                                                       null,
                                                                       null );

        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) ruleBase.newStatefulSession();

        final Rete source = ruleBase.getRete();

        final Class shadowClass = ShadowProxyFactory.getProxy( Person.class );
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( Person.class ),
                                                                  source,
                                                                  3 );

        final MockObjectSink sink = new MockObjectSink();
View Full Code Here


    public void testHierarchy() {
        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();

        final Rete rete = ruleBase.getRete();
        final IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        // Attach a List ObjectTypeNode
        final ObjectTypeNode listOtn = new ObjectTypeNode( idGenerator.getNextId(),
                                                           new ClassObjectType( List.class ),
                                                           rete,
                                                           3 );
        listOtn.attach();

        // Will automatically create an ArrayList ObjectTypeNode
        FactHandle handle = workingMemory.insert( new ArrayList() );

        // Check we have three ObjectTypeNodes, List, ArrayList and InitialFactImpl
        assertEquals( 3,
                      rete.getObjectTypeNodes().size() );

        // double check that the Listreference is the same as the one we created, i.e. engine should try and recreate it
        assertSame( listOtn,
                    rete.getObjectTypeNodes().get( new ClassObjectType( List.class ) ) );

        // ArrayConf should match two ObjectTypenodes for List and ArrayList
        ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( rete );
        ObjectTypeConf arrayConf = (ObjectTypeConf) memory.get( ArrayList.class );
        final ObjectTypeNode arrayOtn = arrayConf.getConcreteObjectTypeNode();
        assertEquals( 2,
                      arrayConf.getObjectTypeNodes().length );
       
        // Check it contains List and ArrayList
        List nodes = Arrays.asList( arrayConf.getObjectTypeNodes() );
        assertEquals(2, nodes.size() );
        assertTrue( nodes.contains( arrayOtn ) );
        assertTrue( nodes.contains( listOtn ) );
       
        // Nodes are there, retract the fact so we can check both nodes are populated
        workingMemory.retract( handle );

        // Add MockSinks so we can track assertions
        final MockObjectSink listSink = new MockObjectSink();
        listOtn.addObjectSink( listSink );

        final MockObjectSink arraySink = new MockObjectSink();
        listOtn.addObjectSink( arraySink );

        workingMemory.insert( new ArrayList() );
        assertEquals( 1,
                      listSink.getAsserted().size() );
        assertEquals( 1,
                      arraySink.getAsserted().size() );

        // Add a Collection ObjectTypeNode, so that we can check that the data from ArrayList is sent to it
        final ObjectTypeNode collectionOtn = new ObjectTypeNode( idGenerator.getNextId(),
                                                                 new ClassObjectType( Collection.class ),
                                                                 rete,
                                                                 3 );
        final MockObjectSink collectionSink = new MockObjectSink();
        collectionOtn.addObjectSink( collectionSink );
View Full Code Here

    /**
     * Test auto-deactivation of RuleFlowGroup.
     */
    public void testRuleFlowGroup4() {
        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
        final InternalWorkingMemory workingMemory = ( InternalWorkingMemory ) ruleBase.newStatefulSession();                ;

        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

        // create rule0
        final Consequence consequence0 = new Consequence() {
            private static final long serialVersionUID = 400L;

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory w) {
                // do nothing
            }
        };

        final Rule rule0 = new Rule( "test-rule0" );
        rule0.setRuleFlowGroup( "rule-flow-group-0" );
        rule0.setConsequence( consequence0 );

        final RuleTerminalNode node0 = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule0,
                                                             rule0.getLhs() );

        final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
        assertTrue( ruleFlowGroup0.isAutoDeactivate() );
View Full Code Here

    @Test
    public void testHierarchy() {
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) this.ruleBase.newStatefulSession();

        final Rete rete = ruleBase.getRete();
        final IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        // Attach a List ObjectTypeNode
        final ObjectTypeNode listOtn = new ObjectTypeNode( idGenerator.getNextId(),
                                                           this.entryPoint,
                                                           new ClassObjectType( List.class ),
                                                           buildContext );
        listOtn.attach();

        // Will automatically create an ArrayList ObjectTypeNode
        FactHandle handle = workingMemory.insert( new ArrayList() );

        // Check we have three ObjectTypeNodes, List, ArrayList and InitialFactImpl
        assertEquals( 3,
                      rete.getObjectTypeNodes().size() );

        // double check that the List reference is the same as the one we created, i.e. engine should try and recreate it
        assertSame( listOtn,
                    rete.getObjectTypeNodes( EntryPoint.DEFAULT ).get( new ClassObjectType( List.class ) ) );

        // ArrayConf should match two ObjectTypenodes for List and ArrayList
        ClassObjectTypeConf arrayConf = ( ClassObjectTypeConf ) workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( this.entryPoint.getEntryPoint(), new ArrayList() );
        final ObjectTypeNode arrayOtn = arrayConf.getConcreteObjectTypeNode();
        assertEquals( 2,
                      arrayConf.getObjectTypeNodes().length );

        // Check it contains List and ArrayList
        List nodes = Arrays.asList( arrayConf.getObjectTypeNodes() );
        assertEquals( 2,
                      nodes.size() );
        assertTrue( nodes.contains( arrayOtn ) );
        assertTrue( nodes.contains( listOtn ) );

        // Nodes are there, retract the fact so we can check both nodes are populated
        workingMemory.retract( handle );

        // Add MockSinks so we can track assertions
        final MockObjectSink listSink = new MockObjectSink();
        listOtn.addObjectSink( listSink );

        final MockObjectSink arraySink = new MockObjectSink();
        listOtn.addObjectSink( arraySink );

        workingMemory.insert( new ArrayList() );
        assertEquals( 1,
                      listSink.getAsserted().size() );
        assertEquals( 1,
                      arraySink.getAsserted().size() );

        // Add a Collection ObjectTypeNode, so that we can check that the data from ArrayList is sent to it
        final ObjectTypeNode collectionOtn = new ObjectTypeNode( idGenerator.getNextId(),
                                                                 this.entryPoint,
                                                                 new ClassObjectType( Collection.class ),
                                                                 buildContext );
        final MockObjectSink collectionSink = new MockObjectSink();
        collectionOtn.addObjectSink( collectionSink );
View Full Code Here

        ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
    }
   
    public void testSingleLogicalRelationship() throws Exception {
        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        final Rete rete = ruleBase.getRete();
        // create a RuleBase with a single ObjectTypeNode we attach a
        // MockObjectSink so we can detect assertions and retractions
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach();
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );

        final Rule rule1 = new Rule( "test-rule1" );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
                                                            buildContext );
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
View Full Code Here

    public void testEqualsMap() throws Exception {
        // create a RuleBase with a single ObjectTypeNode we attach a
        // MockObjectSink so w can detect assertions and retractions
        final Rule rule1 = new Rule( "test-rule1" );

        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        final Rete rete = ruleBase.getRete();
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach();
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );

        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
                                                            buildContext );

        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
View Full Code Here

     */
    public void testStatedOverrideDiscard() throws Exception {
        // create a RuleBase with a single ObjectTypeNode we attach a
        // MockObjectSink so we can detect assertions and retractions
        final Rule rule1 = new Rule( "test-rule1" );
        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        final Rete rete = ruleBase.getRete();
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach();
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
                                                            buildContext  );

        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
View Full Code Here

        conf.setLogicalOverride( LogicalOverride.PRESERVE );
        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase(conf);
       
        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
       
        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        final Rete rete = ruleBase.getRete();
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach();
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
                                                            buildContext  );
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
View Full Code Here

    public void testRetract() throws Exception {
        // create a RuleBase with a single ObjectTypeNode we attach a
        // MockObjectSink so we can detect assertions and retractions
        final Rule rule1 = new Rule( "test-rule1" );
        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        final Rete rete = ruleBase.getRete();
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach();
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
                                                            buildContext  );

        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();

        final Consequence consequence = new Consequence() {
            /**
             *
             */
            private static final long serialVersionUID = 400L;

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                // do nothing
            }
        };

        // create the first activation which will justify the fact "logical"
        rule1.setConsequence( consequence );

        final DefaultFactHandle handle1 = new DefaultFactHandle( 1,
                                                                 "cheese" );
        final ReteTuple tuple1 = new ReteTuple( handle1 );

        final PropagationContext context = new PropagationContextImpl( 0,
                                                                       PropagationContext.ASSERTION,
                                                                       null,
                                                                       null );

        node.assertTuple( tuple1,
                          context,
                          workingMemory );

        // Assert the logical "logical" fact
        final String logicalString1 = new String( "logical" );
        final FactHandle logicalHandle1 = workingMemory.insert( logicalString1,
                                                                false,
                                                                true,
                                                                rule1,
                                                                tuple1.getActivation() );

        // create the second activation to justify the "logical" fact
        final Rule rule2 = new Rule( "test-rule2" );
        final RuleTerminalNode node2 = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( 3 ),
                                                             rule2,
                                                             rule2.getLhs(),
                                                             buildContext  );
        rule2.setConsequence( consequence );
View Full Code Here

    }

    public void testMultipleLogicalRelationships() throws FactException {
        final Rule rule1 = new Rule( "test-rule1" );
        IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();

        final Rete rete = ruleBase.getRete();

        // Create a RuleBase with a single ObjectTypeNode we attach a
        // MockObjectSink so we can detect assertions and retractions
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach();
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSourceidGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
                                                            buildContext  );
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();

        final Agenda agenda = workingMemory.getAgenda();

        final Consequence consequence = new Consequence() {
            /**
             *
             */
            private static final long serialVersionUID = 400L;

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                // do nothing
            }
        };

        // Create first justifier
        rule1.setConsequence( consequence );

        final DefaultFactHandle handle1 = new DefaultFactHandle( 1,
                                                                 "cheese" );
        final ReteTuple tuple1 = new ReteTuple( handle1 );

        final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
        // get the activation onto the agenda
        node.assertTuple( tuple1,
                          context1,
                          workingMemory );

        // Create the second justifer
        final Rule rule2 = new Rule( "test-rule2" );
        final RuleTerminalNode node2 = new RuleTerminalNodeidGenerator.getNextId(),
                                                             new MockTupleSourceidGenerator.getNextId() ),
                                                             rule2,
                                                             rule2.getLhs(),
                                                             buildContext  );
        rule2.setConsequence( consequence );

View Full Code Here

TOP

Related Classes of org.drools.reteoo.ReteooBuilder.IdGenerator

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.