Package javax.rules

Examples of javax.rules.StatefulRuleSession


      RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
      System.out.println( "Acquired RuleRuntime: " + ruleRuntime );

      // create a StatefulRuleSession
      StatefulRuleSession statefulRuleSession =
              (StatefulRuleSession) ruleRuntime.createRuleSession( uri,
              new HashMap(),
              RuleRuntime.STATEFUL_SESSION_TYPE );

      System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );

      // Add some clauses...
      ArrayList input = new ArrayList();
      input.add(new Clause("Socrate","is human"));

      // add an Object to the statefulRuleSession
      statefulRuleSession.addObjects( input );
      System.out.println( "Called addObject on Stateful Rule Session: "
                                              + statefulRuleSession );

      statefulRuleSession.executeRules();
      System.out.println( "Called executeRules" );

      // extract the Objects from the statefulRuleSession
      List results = statefulRuleSession.getObjects();

      System.out.println( "Result of calling getObjects: " +
                                              results.size() + " results." );


      // Loop over the results.

      Hashtable wm = ((StatefulRuleSessionImpl)statefulRuleSession).getWorkingMemory();
      Enumeration en = wm.keys();
      while(en.hasMoreElements()) {
        Object obj = en.nextElement();
        System.out.println("Clause Found: "+obj+" "+wm.get(obj));
      }

      // release the statefulRuleSession
      statefulRuleSession.release();
      System.out.println( "Released Stateful Rule Session." );
      System.out.println();

    }
    catch (NoClassDefFoundError e) {
View Full Code Here


      RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
      System.out.println( "Acquired RuleRuntime: " + ruleRuntime );

      // create a StatefulRuleSession
      StatefulRuleSession statefulRuleSession =
              (StatefulRuleSession) ruleRuntime.createRuleSession( uri,
              new HashMap(),
              RuleRuntime.STATEFUL_SESSION_TYPE );

      System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );

      // Add some clauses...
      ArrayList input = new ArrayList();
      input.add(new Clause("Socrate is human"));

      // add an Object to the statefulRuleSession
      statefulRuleSession.addObjects( input );
      System.out.println( "Called addObject on Stateful Rule Session: "
                                              + statefulRuleSession );

      statefulRuleSession.executeRules();
      System.out.println( "Called executeRules" );

      // extract the Objects from the statefulRuleSession
      List results = statefulRuleSession.getObjects();

      System.out.println( "Result of calling getObjects: " +
                                              results.size() + " results." );


      // Loop over the results.
      Iterator itr = results.iterator();
      while(itr.hasNext()) {
              Object obj = itr.next();
              System.out.println("Clause Found: "+obj.toString());
      }

      // release the statefulRuleSession
      statefulRuleSession.release();
      System.out.println( "Released Stateful Rule Session." );
      System.out.println();

    }
    catch (NoClassDefFoundError e) {
View Full Code Here

        final List list = new ArrayList();
        properties.put( "list",
                        list );
       
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
        StatefulRuleSession session = (StatefulRuleSession) ruleRuntime.createRuleSession( "IntegrationExampleTest.xls",
                                                                                           properties,
                                                                                           RuleRuntime.STATEFUL_SESSION_TYPE );

        //ASSERT AND FIRE
        session.addObject( new Cheese( "stilton",
                                       42 ) );
        session.addObject( new Person( "michael",
                                       "stilton",
                                       42 ) );

        session.executeRules();
        assertEquals( 1,
                      list.size() );
    }
View Full Code Here

                                                                                      null );
        this.ruleAdministrator.registerRuleExecutionSet( this.RULES_RESOURCE,
                                                         ruleSet,
                                                         null );

        final StatefulRuleSession statefulRuleSession = (StatefulRuleSession) ruleRuntime.createRuleSession( this.RULES_RESOURCE,
                                                                                                             null,
                                                                                                             RuleRuntime.STATEFUL_SESSION_TYPE );
        assertNotNull( "cannot obtain StatefulRuleSession",
                       statefulRuleSession );
View Full Code Here

        final List list = new ArrayList();
        properties.put( "list",
                        list );
       
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
        StatefulRuleSession session = (StatefulRuleSession) ruleRuntime.createRuleSession( "IntegrationExampleTest.xls",
                                                                                           properties,
                                                                                           RuleRuntime.STATEFUL_SESSION_TYPE );

        //ASSERT AND FIRE
        session.addObject( new Cheese( "stilton",
                                       42 ) );
        session.addObject( new Person( "michael",
                                       "stilton",
                                       42 ) );

        session.executeRules();
        assertEquals( 1,
                      list.size() );
    }
View Full Code Here

                                                                                      null );
        this.ruleAdministrator.registerRuleExecutionSet( this.RULES_RESOURCE,
                                                         ruleSet,
                                                         null );

        final StatefulRuleSession statefulRuleSession = (StatefulRuleSession) ruleRuntime.createRuleSession( this.RULES_RESOURCE,
                                                                                                             null,
                                                                                                             RuleRuntime.STATEFUL_SESSION_TYPE );
        assertNotNull( "cannot obtain StatefulRuleSession",
                       statefulRuleSession );
View Full Code Here

        final List list = new ArrayList();
        properties.put( "list",
                        list );
       
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
        StatefulRuleSession session = (StatefulRuleSession) ruleRuntime.createRuleSession( "IntegrationExampleTest.xls",
                                                                                           properties,
                                                                                           RuleRuntime.STATEFUL_SESSION_TYPE );

        //ASSERT AND FIRE
        session.addObject( new Cheese( "stilton",
                                       42 ) );
        session.addObject( new Person( "michael",
                                       "stilton",
                                       42 ) );

        session.executeRules();
        assertEquals( 1,
                      list.size() );
    }
View Full Code Here

                                                                                      null );
        this.ruleAdministrator.registerRuleExecutionSet( this.RULES_RESOURCE,
                                                         ruleSet,
                                                         null );

        final StatefulRuleSession statefulRuleSession = (StatefulRuleSession) ruleRuntime.createRuleSession( this.RULES_RESOURCE,
                                                                                                             null,
                                                                                                             RuleRuntime.STATEFUL_SESSION_TYPE );
        assertNotNull( "cannot obtain StatefulRuleSession",
                       statefulRuleSession );
View Full Code Here

   * 提供StatefulRuleSession给StatefulRuleCallback执行
   * @param callback
   * @throws Exception
   */
  public void execute(StatefulRuleCallback callback) throws Exception {
    StatefulRuleSession session = getStatefulRuleSession();
    try {
      callback.doInRuleSession(session);
    } finally {
      releaseStatefulRuleSession(session);
    }
View Full Code Here

TOP

Related Classes of javax.rules.StatefulRuleSession

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.