Package javax.rules

Examples of javax.rules.RuleRuntime


        LocalRuleExecutionSetProvider ruleSetProvider = ruleAdministrator.getLocalRuleExecutionSetProvider( null );
        InputStream rules = this.getClass( ).getResourceAsStream( ruleUri );
        RuleExecutionSet ruleExecutionSet = ruleSetProvider.createRuleExecutionSet( rules, null );
        ruleAdministrator.registerRuleExecutionSet( ruleUri, ruleExecutionSet, null );

        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime( );
        statelessRuleSession = ( StatelessRuleSession ) ruleRuntime.createRuleSession( ruleUri,
                                                                                       null,
                                                                                       RuleRuntime.STATELESS_SESSION_TYPE );
    }
View Full Code Here


    /**
     * Test createRuleSession.
     */
    public void testCreateRuleStatelessRuleSession( ) throws Exception
    {
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime( );
        assertNotNull( "cannot obtain RuleRuntime", ruleRuntime );

        // expect RuleExecutionSetNotFoundException
        try
        {
            ruleRuntime.createRuleSession( "someUri",
                                           null,
                                           RuleRuntime.STATELESS_SESSION_TYPE );
            fail( "RuleExecutionSetNotFoundException expected" );
        }
        catch ( RuleExecutionSetNotFoundException ex )
        {
            // ignore exception
        }

        // read rules and register with administrator
        Reader ruleReader = new InputStreamReader(
            RuleRuntimeTestCase.class.getResourceAsStream( RULES_RESOURCE ) );
        RuleExecutionSet ruleSet =
            ruleSetProvider.createRuleExecutionSet( ruleReader, null );
        ruleAdministrator.registerRuleExecutionSet(
            RULES_RESOURCE, ruleSet, null );

        StatelessRuleSession statelessRuleSession = ( StatelessRuleSession ) ruleRuntime.createRuleSession( RULES_RESOURCE,
                                                                                                            null,
                                                                                                            RuleRuntime.STATELESS_SESSION_TYPE );
        assertNotNull( "cannot obtain StatelessRuleSession",
                       statelessRuleSession );

View Full Code Here

    /**
     * Test createRuleSession.
     */
    public void testCreateRuleStatefulRuleSession( ) throws Exception
    {
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime( );
        assertNotNull( "cannot obtain RuleRuntime", ruleRuntime );

        // expect RuleExecutionSetNotFoundException
        try
        {
            ruleRuntime.createRuleSession( "someUri",
                                           null,
                                           RuleRuntime.STATEFUL_SESSION_TYPE );
            fail( "RuleExecutionSetNotFoundException expected" );
        }
        catch ( RuleExecutionSetNotFoundException ex )
        {
            // ignore exception
        }

        // read rules and register with administrator
        Reader ruleReader = new InputStreamReader(
            RuleRuntimeTestCase.class.getResourceAsStream( RULES_RESOURCE ) );
        RuleExecutionSet ruleSet =
            ruleSetProvider.createRuleExecutionSet( ruleReader, null );
        ruleAdministrator.registerRuleExecutionSet(
            RULES_RESOURCE, ruleSet, null );

        StatefulRuleSession statefulRuleSession = ( StatefulRuleSession )
                    ruleRuntime.createRuleSession( RULES_RESOURCE,
                                                   null,
                                                   RuleRuntime.STATEFUL_SESSION_TYPE );
        assertNotNull(
            "cannot obtain StatefulRuleSession", statefulRuleSession );

View Full Code Here

    /**
     * Test getRegistrations.
     */
    public void testGetRegistrations( ) throws Exception
    {
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime( );
        assertNotNull( "cannot obtain RuleRuntime", ruleRuntime );

        // read rules and register with administrator
        Reader ruleReader = new InputStreamReader(
            RuleRuntimeTestCase.class.getResourceAsStream( RULES_RESOURCE ) );
        RuleExecutionSet ruleSet =
            ruleSetProvider.createRuleExecutionSet( ruleReader, null );
        ruleAdministrator.registerRuleExecutionSet(
            RULES_RESOURCE, ruleSet, null );

        List list = ruleRuntime.getRegistrations( );
        assertTrue( "no registrations found", list.size( ) > 0 );

        ruleAdministrator.deregisterRuleExecutionSet( RULES_RESOURCE, null );
    }
View Full Code Here

    /**
     * Test getRuleRuntime.
     */
    public void testRuleRuntime( ) throws Exception
    {
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime( );
        assertNotNull( "cannot obtain RuleRuntime", ruleRuntime );
        assertTrue( "not a class instance",
                    ruleRuntime == ruleServiceProvider.getRuleRuntime( ) );
    }
View Full Code Here

   *
   * @throws Exception
   */
  public void testMultipleInstances() throws Exception {
    // create 2 different runtimes with different rulesets
    RuleRuntime ruleRuntime1 = getServiceProvider("engine1",
        "multiple-engine1.java.drl").getRuleRuntime();
    RuleRuntime ruleRuntime2 = getServiceProvider("engine2",
        "multiple-engine2.java.drl").getRuleRuntime();

    // there should be only 1
    System.out.println(ruleRuntime1.getRegistrations().size());
    assertTrue(ruleRuntime1.getRegistrations().size() == 1);

    // there should be only 1
    System.out.println(ruleRuntime2.getRegistrations().size());
    assertTrue(ruleRuntime2.getRegistrations().size() == 1);

    // execute them both for good measure...
    execute(ruleRuntime1, "Engine1", new Object[] { "value1" });
    execute(ruleRuntime2, "Engine2", new Object[] { "value2" });

View Full Code Here

        String uri = "uri_" + System.currentTimeMillis( );
        ruleAdministrator
                         .registerRuleExecutionSet( uri, ruleExecutionSet, null );
        log( "Bound RuleExecutionSet to URI: " + uri );
        log( "Runtime API - Query Deployed RuleSets" );
        RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime( );
        // get the RuleRuntime from JNDI
        log( "Acquired RuleRuntime: " + ruleRuntime );
        // print the uris of the registered rulesets
        List uriList = ruleRuntime.getRegistrations( );
        log( "Registered RuleExecutionSets:" );
        for ( Iterator it = uriList.iterator( ); it.hasNext( ); )
        {
            log( "Ruleset URI: " + it.next( ) );
        }
        log( "Runtime API - Stateless Execution" );
        // create a StatelessRuleSession
        StatelessRuleSession statelessRuleSession = ( StatelessRuleSession )
            ruleRuntime.createRuleSession(
                uri, new HashMap( ), RuleRuntime.STATELESS_SESSION_TYPE );
        log( "Got Stateful Rule Session " + uri );
        log( "Implementation: " + statelessRuleSession );
        // add the user's User-Agent string to the session and execute it
        List inputList = new LinkedList( );
        inputList.add( userAgent );
        log( "Adding browser User-Agent to session: " + userAgent );
        List resultList = statelessRuleSession.executeRules( inputList );
        log( "Called executeRules on Stateless Rule Session: "
            + statelessRuleSession );
        log( "Result of calling executeRules: " + resultList );
        // release the session
        statelessRuleSession.release( );
        log( "Released Stateless Rule Session." );
        log( "Runtime API - Stateful Execution" );
        // create a StatefulRuleSession
        StatefulRuleSession statefulRuleSession = ( StatefulRuleSession )
            ruleRuntime.createRuleSession(
                uri, new HashMap( ), RuleRuntime.STATEFUL_SESSION_TYPE );
        log( "Got Stateful Rule Session " + uri );
        log( ": " + statefulRuleSession );
        // add an Object to the statefulRuleSession
        log( "Adding browser User-Agent to session: " + userAgent );
View Full Code Here

                                                                                    null );
        ruleAdministrator.registerRuleExecutionSet( RULE_URI,
                                                    ruleExecutionSet,
                                                    null );

        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
        statelessRuleSession = (StatelessRuleSession) ruleRuntime.createRuleSession( RULE_URI,
                                                                                     null,
                                                                                     RuleRuntime.STATELESS_SESSION_TYPE );
    }
View Full Code Here

      // expected
    }
    bean.setServiceProvider(getProvider());
    bean.afterPropertiesSet();

    RuleRuntime runtime = (RuleRuntime) bean.getObject();
    assertNotNull("Created RuleRuntime is null", runtime);
  }
View Full Code Here

    /**
     * Test createRuleSession.
     */
    @Test
    public void testCreateRuleStatelessRuleSession() throws Exception {
        final RuleRuntime ruleRuntime = this.ruleServiceProvider.getRuleRuntime();
        assertNotNull( "cannot obtain RuleRuntime",
                       ruleRuntime );

        // expect RuleExecutionSetNotFoundException
        try {
            ruleRuntime.createRuleSession( "someUri",
                                           null,
                                           RuleRuntime.STATELESS_SESSION_TYPE );
            fail( "RuleExecutionSetNotFoundException expected" );
        } catch ( final RuleExecutionSetNotFoundException ex ) {
            // ignore exception
        }

        // read rules and register with administrator
        final Reader ruleReader = new InputStreamReader( RuleRuntimeTest.class.getResourceAsStream( this.RULES_RESOURCE ) );
        final RuleExecutionSet ruleSet = this.ruleSetProvider.createRuleExecutionSet( ruleReader,
                                                                                      null );
        this.ruleAdministrator.registerRuleExecutionSet( this.RULES_RESOURCE,
                                                         ruleSet,
                                                         null );

        final StatelessRuleSession statelessRuleSession = (StatelessRuleSession) ruleRuntime.createRuleSession( this.RULES_RESOURCE,
                                                                                                                null,
                                                                                                                RuleRuntime.STATELESS_SESSION_TYPE );
        assertNotNull( "cannot obtain StatelessRuleSession",
                       statelessRuleSession );

View Full Code Here

TOP

Related Classes of javax.rules.RuleRuntime

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.