Rule Execution Server API

Package ilog.rules.res.jsr94

Provides the classes that implement the JavaTM Rule Engine API (JSR-94) on top of Rule Execution Server.

See:
          Description

Class Summary
IlrRuleServiceProvider Deprecated. JSR94 support is deprecated and will be removed in a future ODM release.
 

Package ilog.rules.res.jsr94 Description

Provides the classes that implement the JavaTM Rule Engine API (JSR-94) on top of Rule Execution Server.

Overview

JSR-94 is not implemented in the engine API, it delegates the JRules rule sessions using the jrules-res-jsr94.jar archive. The JSR-94 specification includes a javax.rules package. This package contains classes and interfaces aimed at the runtime clients of the rule engine.

Code Example

The following code example illustrates how to use JSR-94:

public class JSR94CodeSample {
        /**
         * The path of the ruleset used to compute fibonacci numbers.
         * 
         * The ruleset takes an input parameter 'n' of type java.lang.Integer.
         * The result is inserted into the working memory.
         */
        public static final String rulesetPath = "/jsr94/1.0/fibo/1.0";

        public JSR94CodeSample() throws ClassNotFoundException {
                //Loads the rule service.               
                Class.forName(IlrRuleServiceProvider.class.getName());
        }
        
        /**
         * Returns the rule runtime.
         */
        RuleRuntime getRuleRuntime() throws RuleException {
                // Returns the rule runtime object.
                RuleServiceProvider provider
                = RuleServiceProviderManager.getRuleServiceProvider(IlrRuleServiceProvider.URI);

                RuleRuntime runtime = provider.getRuleRuntime();

                return runtime;
        }
        
        /**
         * Computes fibonacci numbers.
         */
        public int computeFibonacciWithStatelessRuleSession(int n) 
        throws RemoteException, RuleException {
                                
                
                // Prepares the parameters
                Map parameters = new HashMap();
                parameters.put("n", new Integer(n));

                // Creates the rule session
                StatelessRuleSession session 
                = (StatelessRuleSession)getRuleRuntime().createRuleSession("/jsr94/1.0/fibo/1.0", 
                                parameters, 
                                RuleRuntime.STATELESS_SESSION_TYPE);

                // Executes the rules
                List workingMemory = session.executeRules(null);

                // Returns the result which is in the working memory
                return (Integer)workingMemory.get(0);
        }
        
        /**
         * Computes fibonacci numbers.
         */
        public int computeFibonacciWithStatefulRuleSession(int n) 
        throws RemoteException, RuleException {                                         
                // Prepares the parameters
                Map parameters = new HashMap();
                parameters.put("n", new Integer(n));

                // Creates the rule session
                StatefulRuleSession session 
                = (StatefulRuleSession)getRuleRuntime().createRuleSession("/jsr94/1.0/fibo/1.0", 
                                parameters, 
                                RuleRuntime.STATEFUL_SESSION_TYPE);

                // Executes the rules
                session.executeRules();
                
                List workingMemory = session.getObjects();

                // Returns the result which is in the working memory
                return (Integer)workingMemory.get(0);
        }
}


Rule Execution Server API

© Copyright IBM Corp. 1987, 2013