Package org.drools

Examples of org.drools.StatefulSession


    }

    public StatefulSession newStatefulSession(java.io.InputStream stream,
                                              boolean keepReference,
                                              SessionConfiguration conf) {
        StatefulSession session = null;
        try {
            readLock();
            try {
                // first unwrap the byte[]
                ObjectInputStream ois = new ObjectInputStream( stream );
   
                // standard serialisation would have written the statateful session instance info to the stream first
                // so we read it, but we don't need it, so just ignore.
                ReteooStatefulSession rsession = (ReteooStatefulSession) ois.readObject();
   
                // now unmarshall that byte[]
                ByteArrayInputStream bais = new ByteArrayInputStream( rsession.bytes );
                Marshaller marshaller = MarshallerFactory.newMarshaller( new KnowledgeBaseImpl( this )new ObjectMarshallingStrategy[] { MarshallerFactory.newSerializeMarshallingStrategy() }   );
               
                Environment environment = EnvironmentFactory.newEnvironment();
                KieSession ksession = marshaller.unmarshall( bais,
                                                                           conf,
                                                                           environment );
                session = (StatefulSession) ((StatefulKnowledgeSessionImpl) ksession).session;
   
                if ( keepReference ) {
                    super.addStatefulSession( session );
                    for (Object listener : session.getRuleBaseUpdateListeners()) {
                        addEventListener((RuleBaseEventListener) listener);
                    }
                }
   
                bais.close();
View Full Code Here


    }
   
    @Test
    public void testObjectIterator() {
        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        final StatefulSession session = ruleBase.newStatefulSession();
       
        session.insert( new Person( "bob", 35) );
        session.insert( new Cheese( "stilton", 35) );
        session.insert( new Cheese( "brie", 35) );
        session.insert( new Person( "steve", 55) );
        session.insert( new Person( "tom", 100) );
       
        int i = 0;
        for ( Iterator it = session.iterateFactHandles(); it.hasNext(); ) {
            Object object = it.next();
            if ( i++ > 5 ) {
                fail( "should not iterate for than 3 times" );
            }
        }
       
        i = 0;
        for ( Iterator it = session.iterateObjects(); it.hasNext(); ) {
            Object object = it.next();
            if ( i++ > 5 ) {
                fail( "should not iterate for than 3 times" );
            }
        }
View Full Code Here

    }

    private class TestTemplateRuleBase implements TemplateRuleBase {

        public StatefulSession newStatefulSession() {
            return new StatefulSession() {
                private static final long serialVersionUID = 510l;

                public void addEventListener(WorkingMemoryEventListener arg0) {

                }
View Full Code Here

        private SessionCreator() {
            super("Session Creator Thread");
        }

        void doOperation() {
            StatefulSession session = null;

            try {
                session = ruleBase.newStatefulSession();
            } finally {
                if (session != null) {
                    session.dispose();
                }
            }
        }
View Full Code Here

   
    public void testStartNode() {
       
        RuleBaseConfiguration conf = new RuleBaseConfiguration();
        RuleBase ruleBase = RuleBaseFactory.newRuleBase( conf );
        StatefulSession session = ruleBase.newStatefulSession();       
       
        MockNode mockNode = new MockNode();
        MockNodeInstanceFactory mockNodeFactory = new MockNodeInstanceFactory( new MockNodeInstance( mockNode ) );
        conf.getProcessNodeInstanceFactoryRegistry().register( mockNode.getClass(), mockNodeFactory );
       
View Full Code Here

public class EndNodeInstanceTest extends TestCase {
   
    public void testEndNode() {
        RuleBaseConfiguration conf = new RuleBaseConfiguration();
        RuleBase ruleBase = RuleBaseFactory.newRuleBase( conf );
        StatefulSession session = ruleBase.newStatefulSession();       
       
        MockNode mockNode = new MockNode();       
        MockNodeInstanceFactory factory = new MockNodeInstanceFactory( new MockNodeInstance( mockNode ) );
        conf.getProcessNodeInstanceFactoryRegistry().registermockNode.getClass(), factory );
       
View Full Code Here

public class AgendaItemTest {
   
    @Test
    public void testAddition() {
        ReteooRuleBase rbase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
        StatefulSession wm = rbase.newStatefulSession();
       
        DefaultAgenda agenda = ( DefaultAgenda ) wm.getAgenda();
        AgendaItem item1 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item2 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item3 = agenda.createAgendaItem( null, 0, null, null );
       
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( wm );
View Full Code Here

    }
   
    @Test
    public void testRemoval() {
        ReteooRuleBase rbase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
        StatefulSession wm = rbase.newStatefulSession();
       
        DefaultAgenda agenda = ( DefaultAgenda ) wm.getAgenda();
        AgendaItem item1 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item2 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item3 = agenda.createAgendaItem( null, 0, null, null );
       
        // use same data structure as testAddition
View Full Code Here

    }   
   
    @Test
    public void testUnblockAll() {
        ReteooRuleBase rbase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
        StatefulSession wm = rbase.newStatefulSession();
       
        DefaultAgenda agenda = ( DefaultAgenda ) wm.getAgenda();
        AgendaItem item1 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item2 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item3 = agenda.createAgendaItem( null, 0, null, null );
       
        // use same data structure as testAddition
View Full Code Here

    }       
   
    @Test
    public void testKnowledgeHelperUpdate() {
        ReteooRuleBase rbase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
        StatefulSession wm = rbase.newStatefulSession();
       
        DefaultAgenda agenda = ( DefaultAgenda ) wm.getAgenda();
        AgendaItem item1 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item2 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item3 = agenda.createAgendaItem( null, 0, null, null );
        AgendaItem item4 = agenda.createAgendaItem( null, 0, null, null );
       
View Full Code Here

TOP

Related Classes of org.drools.StatefulSession

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.