com.haley.haleyrules.jsr94
Class StatefulRuleSessionImpl

java.lang.Object
  |
  +--com.haley.haleyrules.jsr94.HaleyRuleSession
        |
        +--com.haley.haleyrules.jsr94.StatefulRuleSessionImpl
All Implemented Interfaces:
javax.rules.RuleSession, java.io.Serializable, javax.rules.StatefulRuleSession

public class StatefulRuleSessionImpl
extends HaleyRuleSession
implements javax.rules.StatefulRuleSession

This class implements StatefulRuleSession interface. For Haley rules engine, there can be only one thread to access a StatefulRuleSession at any one time.

The StatefulRuleSession is a representation of a stateful rules engine session. A stateful rules engine session exposes a stateful rule execution API to an underlying rules engine. The session allows arbitrary objects to be added and removed to and from the rule session state. Additionally, objects currently part of the rule session state may be updated.

There are inherently side-effects to adding objects to the rule session state. The execution of a RuleExecutionSet can add, remove and update objects in the rule session state. The objects in the rule session state are therefore dependent on the rules within the RuleExecutionSet as well as the rule engine vendor's specific rule engine behavior.

Handle instances are used by the rule engine vendor to track Objects added to the rule session state. This allows multiple instances of equivalent Objects to be added to the session state and identified, even after serialization.

See Also:
Serialized Form

Method Summary
 javax.rules.Handle addObject(java.lang.Object object)
          Adds a given object to the rule session state of this rule session.
 java.util.List addObjects(java.util.List objList)
          Adds a List of Objects to the rule session state of this rule session.
 boolean containsObject(javax.rules.Handle objectHandle)
           
 void executeRules()
          Executes the rules in the bound rule execution set using the objects present in the rule session state.
 java.util.List getHandles()
          Returns a List of the Handles being used for object identity.
 java.lang.Object getObject(javax.rules.Handle handle)
          Returns the Object within the StatefulRuleSession associated with a Handle.
 java.util.List getObjects()
          Returns a List of all objects in the rule session state of this rule session.
 java.util.List getObjects(javax.rules.ObjectFilter filter)
          Returns a List over the objects in rule session state of this rule session.
 int getType()
          Gets the type identifier for this RuleSession.
 void release()
          Releases all resources used by this rule session.
 void removeObject(javax.rules.Handle handle)
          Removes a given object from the rule session state of this rule session.
 void reset()
          Resets this rule session.
 void updateObject(javax.rules.Handle objectHandle, java.lang.Object newObject)
          Notifies the rules engine that a given object in the rule session state has changed.
 
Methods inherited from class com.haley.haleyrules.jsr94.HaleyRuleSession
getRuleExecutionSetMetadata
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.rules.RuleSession
getRuleExecutionSetMetadata
 

Method Detail

containsObject

public boolean containsObject(javax.rules.Handle objectHandle)
                       throws javax.rules.InvalidRuleSessionException,
                              javax.rules.InvalidHandleException
Specified by:
containsObject in interface javax.rules.StatefulRuleSession
Parameters:
objectHandle - the handle to the target object.
Returns:
true if the given object is contained within the rule session state of this rule session.
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.
javax.rules.InvalidHandleException -  

addObject

public javax.rules.Handle addObject(java.lang.Object object)
                             throws javax.rules.InvalidRuleSessionException
Adds a given object to the rule session state of this rule session. The argument to this method is Object because in the non-managed environment, not all objects should have to implement Serializable. If the RuleSession is Serializable and it contains non-serializable fields a runtime exception will be thrown.
Specified by:
addObject in interface javax.rules.StatefulRuleSession
Parameters:
object - the object to be added.
Returns:
the Handle for the newly added Object
Throws:
InvalidRuleSessionExceptionAdds - on illegal rule session state.

addObjects

public java.util.List addObjects(java.util.List objList)
                          throws javax.rules.InvalidRuleSessionException
Adds a List of Objects to the rule session state of this rule session.
Specified by:
addObjects in interface javax.rules.StatefulRuleSession
Parameters:
objList - the objects to be added.
Returns:
a List of Handles, one for each added Object. The List must be ordered in the same order as the input objList.
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.

updateObject

public void updateObject(javax.rules.Handle objectHandle,
                         java.lang.Object newObject)
                  throws javax.rules.InvalidRuleSessionException,
                         javax.rules.InvalidHandleException
Notifies the rules engine that a given object in the rule session state has changed. The semantics of this call are equivalent to calling removeObject followed by addObject. The original Handle is rebound to the new value for the Object however.
Specified by:
updateObject in interface javax.rules.StatefulRuleSession
Parameters:
objectHandle - Handle - the handle to the original object.
newObject - the new object to bind to the handle.
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.
javax.rules.InvalidHandleException - if the input Handle is no longer valid

removeObject

public void removeObject(javax.rules.Handle handle)
                  throws javax.rules.InvalidHandleException,
                         javax.rules.InvalidRuleSessionException
Removes a given object from the rule session state of this rule session.
Specified by:
removeObject in interface javax.rules.StatefulRuleSession
Parameters:
handle - the handle to the object to be removed from the rule session state.
Throws:
javax.rules.InvalidHandleException - if the input Handle is no longer valid
javax.rules.InvalidRuleSessionException - on illegal rule session state.

getObjects

public java.util.List getObjects()
                          throws javax.rules.InvalidRuleSessionException
Returns a List of all objects in the rule session state of this rule session. The objects should pass the default filter test of the default RuleExecutionSet filter (if present). This may not neccessarily include all objects added by calls to addObject, and may include Objects created by side-effects. The execution of a RuleExecutionSet can add, remove and update objects as part of the rule session state. Therefore the rule session state is dependent on the rules that are part of the executed RuleExecutionSet as well as the rule vendor's specific rule engine behavior.
Specified by:
getObjects in interface javax.rules.StatefulRuleSession
Returns:
a List of all objects part of the rule session state.
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.

getHandles

public java.util.List getHandles()
                          throws javax.rules.InvalidRuleSessionException
Returns a List of the Handles being used for object identity.
Specified by:
getHandles in interface javax.rules.StatefulRuleSession
Returns:
a List of Handles present in the current state of the rule session.
Throws:
javax.rules.InvalidRuleSessionException -  

getObjects

public java.util.List getObjects(javax.rules.ObjectFilter filter)
                          throws javax.rules.InvalidRuleSessionException
Returns a List over the objects in rule session state of this rule session. The objects should pass the filter test on the specified ObjectFilter. This may not neccessarily include all objects added by calls to addObject, and may include Objects created by side-effects. The execution of a RuleExecutionSet can add, remove and update objects as part of the rule session state. Therefore the rule session state is dependent on the rules that are part of the executed RuleExecutionSet as well as the rule vendor's specific rule engine behavior.
Specified by:
getObjects in interface javax.rules.StatefulRuleSession
Parameters:
filter - the object filter.
Returns:
a List of all the objects in the rule session state of this rule session based upon the given object filter.
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.

executeRules

public void executeRules()
                  throws javax.rules.InvalidRuleSessionException
Executes the rules in the bound rule execution set using the objects present in the rule session state. This will typically modify the rule session state - and may add, remove or update Objects bound to Handles.
Specified by:
executeRules in interface javax.rules.StatefulRuleSession
Throws:
javax.rules.InvalidRuleSessionException - - on illegal rule session state.

reset

public void reset()
           throws javax.rules.InvalidRuleSessionException
Resets this rule session. Calling this method will bring the rule session state to its initial state for this rule session and will reset any other state associated with this rule session. A reset will not reset the state on the default object filter for a RuleExecutionSet.
Specified by:
reset in interface javax.rules.StatefulRuleSession
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.

getObject

public java.lang.Object getObject(javax.rules.Handle handle)
                           throws javax.rules.InvalidHandleException,
                                  javax.rules.InvalidRuleSessionException
Returns the Object within the StatefulRuleSession associated with a Handle.
Specified by:
getObject in interface javax.rules.StatefulRuleSession
Parameters:
handle - Handle
Returns:
Object
Throws:
javax.rules.InvalidHandleException - if the Handle is no longer valid for this StatefulRuleSession
javax.rules.InvalidRuleSessionException -  

getType

public int getType()
            throws javax.rules.InvalidRuleSessionException
Gets the type identifier for this RuleSession. The type identifiers are defined in the RuleRuntime interface
Specified by:
getType in interface javax.rules.RuleSession
Overrides:
getType in class HaleyRuleSession
Returns:
stateful rule session type
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state

release

public void release()
             throws javax.rules.InvalidRuleSessionException
Releases all resources used by this rule session. This method renders this rule session unusable until it is reacquired through the RuleRuntime
Specified by:
release in interface javax.rules.RuleSession
Overrides:
release in class HaleyRuleSession
Throws:
javax.rules.InvalidRuleSessionException -  


Copyright © 2005-2006 Haley Systems, Inc. All Rights Reserved.