Package org.drools.reteoo

Examples of org.drools.reteoo.ReteooStatefulSession


        Reader source = new InputStreamReader(DebugViewsTest.class.getResourceAsStream("/debug.drl"));
        PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl(source);
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage(builder.getPackage());
        ReteooStatefulSession session = (ReteooStatefulSession) ruleBase.newStatefulSession();
        List list = new ArrayList();
        session.setGlobal("list", list);
        session.insert("String1");
        String focusName = session.getAgenda().getFocusName();
        assertEquals("MAIN", focusName);
        AgendaGroup[] agendaGroups = session.getAgenda().getAgendaGroups();
        assertEquals(1, agendaGroups.length);
        assertEquals("MAIN", agendaGroups[0].getName());
        assertEquals(1, agendaGroups[0].getActivations().length);

        Activation activation = agendaGroups[0].getActivations()[0];
        assertEquals("ActivationCreator", activation.getRule().getName());
        Entry[] parameters = session.getActivationParameters(
            ((org.drools.spi.Activation) activation).getActivationNumber());
        assertEquals(1, parameters.length);
        assertEquals("o", parameters[0].getKey());
        assertEquals("String1", parameters[0].getValue());
    }
View Full Code Here


     */
   
    @Test
    public void testWorkingMemoryView() throws Exception {
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ReteooStatefulSession session = (ReteooStatefulSession) ruleBase.newStatefulSession();
        session.insert("Test1");
        session.insert("Test2");
        Object[] objects = session.iterateObjectsToList().toArray();
        assertEquals(2, objects.length);
        assertTrue(("Test1".equals(objects[0]) && "Test2".equals(objects[1])) ||
                   ("Test2".equals(objects[0]) && "Test1".equals(objects[1])));
    }
View Full Code Here

  }

  public void FIXMEtestTimer() {
        AbstractRuleBase ruleBase = (AbstractRuleBase) RuleBaseFactory.newRuleBase();
        ExecutorService executorService = new DefaultExecutorService();
        final StatefulSession workingMemory = new ReteooStatefulSession(1, ruleBase, executorService);
        executorService.setCommandExecutor( new CommandExecutor( workingMemory ) );

        RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance() {
      private static final long serialVersionUID = 4L;
      public void signalEvent(String type, Object event) {
            if ("timerTriggered".equals(type)) {
              TimerInstance timer = (TimerInstance) event;
                System.out.println("Timer " + timer.getId() + " triggered");
                counter++;
            }
          }
        };
        processInstance.setWorkingMemory((InternalWorkingMemory) workingMemory);
        processInstance.setId(1234);
        ((InternalWorkingMemory) workingMemory).getProcessInstanceManager()
          .internalAddProcessInstance(processInstance);

        new Thread(new Runnable() {
      public void run() {
            workingMemory.fireUntilHalt();        
      }
        }).start();

        TimerManager timerManager = workingMemory.getTimerManager();
        TimerInstance timer = new TimerInstance();
        timerManager.registerTimer(timer, processInstance);
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
View Full Code Here

       
      CommandService commandService = ((SessionConfiguration) conf).getCommandService(this, environment);
      if (commandService != null) {
      return new CommandBasedStatefulKnowledgeSession(commandService);
      } else {
        ReteooStatefulSession session = (ReteooStatefulSession) this.ruleBase.newStatefulSession( (SessionConfiguration) conf,
                                                                                                  environment );
        return new StatefulKnowledgeSessionImpl( session, this );
      }
    }   
View Full Code Here

        DefaultAgenda agenda = new DefaultAgenda( context.ruleBase,
                                                  false );
        readAgenda( context,
                    agenda );
        ReteooStatefulSession session = new ReteooStatefulSession( id,
                                                                   context.ruleBase,
                                                                   executor,
                                                                   handleFactory,
                                                                   initialFactHandle,
                                                                   propagationCounter,
                                                                   config, 
                                                                   agenda,
                                                                   environment );

        // RuleFlowGroups need to reference the session
        for ( RuleFlowGroup group : agenda.getRuleFlowGroupsMap().values() ) {
            ((RuleFlowGroupImpl) group).setWorkingMemory( session );
        }
        context.wm = session;

        readFactHandles( context );

        readActionQueue( context );

        if ( context.readBoolean() ) {
            readTruthMaintenanceSystem( context );
        }

        if ( context.marshalProcessInstances ) {
            readProcessInstances( context );
        }

        if ( context.marshalWorkItems ) {
            readWorkItems( context );
        }

        readTimers( context );

        if( multithread ) {
            session.startPartitionManagers();
        }

        return session;
    }   
View Full Code Here

        int id = ((ReteooRuleBase) ((KnowledgeBaseImpl) this.kbase).ruleBase).nextWorkingMemoryCounter();
        RuleBaseConfiguration conf = ((ReteooRuleBase) ((KnowledgeBaseImpl) this.kbase).ruleBase).getConfiguration();
        ExecutorService executor = ExecutorServiceFactory.createExecutorService( conf.getExecutorService() );

        ReteooStatefulSession session = InputMarshaller.readSession( context,
                                                                     id,
                                                                     executor,
                                                                     environment,
                                                                     (SessionConfiguration) config );
        executor.setCommandExecutor( new CommandExecutor( session ) );
View Full Code Here

        this.name = name;
        this.exitPoint = exitPoint;
    }

    public Object execute(ReteooWorkingMemory session) {
        ReteooStatefulSession reteooStatefulSession = (ReteooStatefulSession) session;

        reteooStatefulSession.registerExitPoint( name,
                                                 exitPoint );

        return null;
    }
View Full Code Here

    public UnregisterExitPointCommand(String name) {
        this.name = name;
    }

    public Object execute(ReteooWorkingMemory session) {
        ReteooStatefulSession reteooStatefulSession = (ReteooStatefulSession) session;

        reteooStatefulSession.unregisterExitPoint( name );

        return null;
    }
View Full Code Here

    public GetFactHandlesCommand(ObjectFilter filter) {
        this.filter = filter;
    }

    public Collection< ? extends FactHandle> execute(ReteooWorkingMemory session) {
        ReteooStatefulSession reteooStatefulSession = (ReteooStatefulSession) session;

        if ( filter != null ) {
            return new ObjectStoreWrapper( reteooStatefulSession.getObjectStore(),
                                           null,
                                           ObjectStoreWrapper.FACT_HANDLE );
        } else {
            return new ObjectStoreWrapper( reteooStatefulSession.getObjectStore(),
                                           filter,
                                           ObjectStoreWrapper.FACT_HANDLE );
        }
    }
View Full Code Here

        DefaultAgenda agenda = new DefaultAgenda( context.ruleBase,
                                                  false );
        readAgenda( context,
                    agenda );
        ReteooStatefulSession session = new ReteooStatefulSession( id,
                                                                   context.ruleBase,
                                                                   executor,
                                                                   handleFactory,
                                                                   initialFactHandle,
                                                                   propagationCounter,
                                                                   config,
                                                                   agenda,
                                                                   environment );
        new StatefulKnowledgeSessionImpl( session );

        initialFactHandle.setEntryPoint( session.getEntryPoints().get( EntryPoint.DEFAULT.getEntryPointId() ) );

        return readSession( session,
                            agenda,
                            time,
                            multithread,
View Full Code Here

TOP

Related Classes of org.drools.reteoo.ReteooStatefulSession

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.