Package org.drools.runtime.rule

Examples of org.drools.runtime.rule.WorkingMemoryEntryPoint


        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

        final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
        final WorkingMemoryEntryPoint ep = ksession.getWorkingMemoryEntryPoint( "testep" );

        List list = new ArrayList();
        ksession.setGlobal( "list",
                            list );

        list.add( new Person( "darth" ) );
        ep.insert( new Cheese( "cheddar" ) );

        ksession.fireAllRules();
        assertEquals( 3,
                      list.size() );
    }
View Full Code Here


        StockTickInterface tick8 = new StockTick(8,
                "DROO",
                50,
                System.currentTimeMillis());

        WorkingMemoryEntryPoint entry = session.getWorkingMemoryEntryPoint("StockStream");

        InternalFactHandle handle5 = (InternalFactHandle) entry.insert(tick5);
        InternalFactHandle handle6 = (InternalFactHandle) entry.insert(tick6);
        InternalFactHandle handle7 = (InternalFactHandle) entry.insert(tick7);
        InternalFactHandle handle8 = (InternalFactHandle) entry.insert(tick8);

        assertNotNull(handle5);
        assertNotNull(handle6);
        assertNotNull(handle7);
        assertNotNull(handle8);
View Full Code Here

        StockTickInterface tick8 = new StockTick(8,
                "DROO",
                50,
                System.currentTimeMillis());

        WorkingMemoryEntryPoint entry = session.getWorkingMemoryEntryPoint("stream1");

        InternalFactHandle handle5 = (InternalFactHandle) entry.insert(tick5);
        InternalFactHandle handle6 = (InternalFactHandle) entry.insert(tick6);
        InternalFactHandle handle7 = (InternalFactHandle) entry.insert(tick7);
        InternalFactHandle handle8 = (InternalFactHandle) entry.insert(tick8);

        assertNotNull(handle5);
        assertNotNull(handle6);
        assertNotNull(handle7);
        assertNotNull(handle8);
View Full Code Here

        StockTickInterface tick8 = new StockTick( 8,
                "DROO",
                50,
                System.currentTimeMillis() );

        WorkingMemoryEntryPoint entry = session.getWorkingMemoryEntryPoint( "stream1" );

        InternalFactHandle handle5 = (InternalFactHandle) entry.insert( tick5 );
        InternalFactHandle handle6 = (InternalFactHandle) entry.insert( tick6 );
        InternalFactHandle handle7 = (InternalFactHandle) entry.insert( tick7 );
        InternalFactHandle handle8 = (InternalFactHandle) entry.insert( tick8 );

        assertNotNull( handle5 );
        assertNotNull( handle6 );
        assertNotNull( handle7 );
        assertNotNull( handle8 );

        assertTrue( handle5.isEvent() );
        assertTrue( handle6.isEvent() );
        assertTrue( handle7.isEvent() );
        assertTrue( handle8.isEvent() );

        session.fireAllRules();

        System.out.println(results);
        assertEquals( 2,
                results.size() );
        assertEquals( 30,
                ( (Number) results.get( 0 ) ).intValue() );
        assertEquals( 110,
                ( (Number) results.get( 1 ) ).intValue() );

        // the 3 non-matched facts continue to exist in the entry point
        assertEquals(3,
                entry.getObjects().size());
        // but no fact was inserted into the main session
        assertEquals(0,
                session.getObjects().size());

    }
View Full Code Here

        StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);

        org.drools.event.rule.AgendaEventListener ael = mock(org.drools.event.rule.AgendaEventListener.class);
        ksession.addEventListener(ael);

        WorkingMemoryEntryPoint ep1 = ksession.getWorkingMemoryEntryPoint("ep1");
        WorkingMemoryEntryPoint ep2 = ksession.getWorkingMemoryEntryPoint("ep2");
        WorkingMemoryEntryPoint ep3 = ksession.getWorkingMemoryEntryPoint("ep3");

        ep1.insert(new StockTick(1,
                "RHT",
                10,
                1000));
        ep2.insert(new StockTick(1,
                "RHT",
                10,
                1000));
        ep3.insert(new StockTick(1,
                "RHT",
                10,
                1000));
        int rulesFired = ksession.fireAllRules();
        assertEquals(3,
View Full Code Here

    public void testGetEntryPointList() throws Exception {
        // read in the source
        KnowledgeBase kbase = loadKnowledgeBase("test_EntryPointReference.drl");
        StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();

        WorkingMemoryEntryPoint def = session.getWorkingMemoryEntryPoint(EntryPoint.DEFAULT.getEntryPointId());
        WorkingMemoryEntryPoint s1 = session.getWorkingMemoryEntryPoint("stream1");
        WorkingMemoryEntryPoint s2 = session.getWorkingMemoryEntryPoint( "stream2" );
        WorkingMemoryEntryPoint s3 = session.getWorkingMemoryEntryPoint( "stream3" );
        Collection<? extends WorkingMemoryEntryPoint> eps = session.getWorkingMemoryEntryPoints();

        assertEquals( 4,
                eps.size() );
        assertTrue(eps.contains(def));
View Full Code Here

        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
        AgendaEventListener ael = mock(AgendaEventListener.class);
        ksession.addEventListener(ael);

        WorkingMemoryEntryPoint ep = ksession.getWorkingMemoryEntryPoint("ticks");
        ep.insert(new StockTick(1, "ACME", 20, 1000)); // not in the window
        ep.insert(new StockTick(2, "RHT", 20, 1000)); // not > 20
        ep.insert(new StockTick(3, "RHT", 30, 1000));
        ep.insert(new StockTick(4, "ACME", 30, 1000)); // not in the window
        ep.insert(new StockTick(5, "RHT", 25, 1000));
        ep.insert(new StockTick(6, "ACME", 10, 1000)); // not in the window
        ep.insert(new StockTick(7, "RHT", 10, 1000)); // not > 20
        ep.insert(new StockTick(8, "RHT", 40, 1000));

        ksession.fireAllRules();

        ArgumentCaptor<org.drools.event.rule.AfterActivationFiredEvent> captor = ArgumentCaptor.forClass(org.drools.event.rule.AfterActivationFiredEvent.class);
        verify(ael,
View Full Code Here

        ((SessionConfiguration) ksconf).setTimerJobFactoryManager( new TrackableTimeJobFactoryManager() );
        StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession( ksconf, null );

        List list = new ArrayList();
        ksession.setGlobal( "list", list );
        WorkingMemoryEntryPoint aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        aep.insert( new A() );

        ksession = marsallStatefulKnowledgeSession( ksession );

        WorkingMemoryEntryPoint bep = ksession.getWorkingMemoryEntryPoint( "b-ep" );
        bep.insert( new B() );

        ksession = marsallStatefulKnowledgeSession( ksession );

        WorkingMemoryEntryPoint cep = ksession.getWorkingMemoryEntryPoint( "c-ep" );
        cep.insert( new C() );

        ksession = marsallStatefulKnowledgeSession( ksession );

        ksession.fireAllRules();

        ksession = marsallStatefulKnowledgeSession( ksession );

        assertEquals( 3,
                      list.size() );

        aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        assertEquals( 1, aep.getFactHandles().size() );

        bep = ksession.getWorkingMemoryEntryPoint( "b-ep" );
        assertEquals( 1, bep.getFactHandles().size() );

        cep = ksession.getWorkingMemoryEntryPoint( "c-ep" );
        assertEquals( 1, cep.getFactHandles().size() );

        PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock> getSessionClock();
        timeService.advanceTime( 11, TimeUnit.SECONDS );

        ksession = marsallStatefulKnowledgeSession( ksession );

        ksession.fireAllRules();

        ksession = marsallStatefulKnowledgeSession( ksession );

        aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        assertEquals( 0, aep.getFactHandles().size() );

        bep = ksession.getWorkingMemoryEntryPoint( "b-ep" );
        assertEquals( 0, bep.getFactHandles().size() );

        cep = ksession.getWorkingMemoryEntryPoint( "c-ep" );
        assertEquals( 1, cep.getFactHandles().size() );
    }
View Full Code Here

        ((SessionConfiguration) ksconf).setTimerJobFactoryManager( new TrackableTimeJobFactoryManager() );
        StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession( ksconf, null );

        List list = new ArrayList();
        ksession.setGlobal( "list", list );
        WorkingMemoryEntryPoint aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        aep.insert( new A() );

        ksession = marsallStatefulKnowledgeSession( ksession );

        PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock> getSessionClock();
        timeService.advanceTime( 3, TimeUnit.SECONDS );
View Full Code Here

        StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession( ksconf, null );

        List list = new ArrayList();
        ksession.setGlobal( "list", list );

        WorkingMemoryEntryPoint aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        aep.insert( new A() );
        ksession = marsallStatefulKnowledgeSession( ksession );

        aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        aep.insert( new A() );
        ksession = marsallStatefulKnowledgeSession( ksession );

        list.clear();
        ksession.fireAllRules();
        ksession = marsallStatefulKnowledgeSession( ksession );
        assertEquals( 2, ((List) list.get( 0 )).size() );

        PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock> getSessionClock();
        timeService.advanceTime( 15, TimeUnit.SECONDS );
        ksession = marsallStatefulKnowledgeSession( ksession );

        aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        aep.insert( new A() );
        ksession = marsallStatefulKnowledgeSession( ksession );

        aep = ksession.getWorkingMemoryEntryPoint( "a-ep" );
        aep.insert( new A() );
        ksession = marsallStatefulKnowledgeSession( ksession );

        list.clear();
        ksession.fireAllRules();
        ksession = marsallStatefulKnowledgeSession( ksession );
View Full Code Here

TOP

Related Classes of org.drools.runtime.rule.WorkingMemoryEntryPoint

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.