站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss RULES 4.0.0.11754MR2 API 英文版文档

StatefulRuleSessionImpl (Drools 4.0.0.11754MR2 API) - JBoss RULES 4.0.0.11754MR2 API 英文版文档


org.drools.jsr94.rules
Class StatefulRuleSessionImpl

java.lang.Object
  extended by org.drools.jsr94.rules.StatefulRuleSessionImpl
All Implemented Interfaces:
Serializable, javax.rules.RuleSession, javax.rules.StatefulRuleSession

public class StatefulRuleSessionImpl
extends Object
implements javax.rules.StatefulRuleSession

The Drools implementation of the StatefulRuleSession interface which 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.

Author:
N. Alex Rupp (n_alex codehaus.org), thomas diesler
See Also:
StatefulRuleSession, Serialized Form

Method Summary
 javax.rules.Handle addObject(Object object)
          Adds a given object to the rule session state of this rule session.
 List addObjects(List objList)
          Adds a List of Objects to the rule session state of this rule session.
protected  void checkRuleSessionValidity()
          Ensures this RuleSession is not in an illegal rule session state.
 boolean containsObject(javax.rules.Handle objectHandle)
          Returns true if the given object is contained within rulesession state of this rule session.
 void executeRules()
          Executes the rules in the bound rule execution set using the objects present in the rule session state.
 List getHandles()
          Returns a List of the Handles being used for object identity.
 Object getObject(javax.rules.Handle handle)
           
 List getObjects()
          Returns a List of all objects in the rule session state of this rule session.
 List getObjects(javax.rules.ObjectFilter filter)
          Returns a List over the objects in rule session state of this rule session.
protected  Map getProperties()
          Returns the additional properties used to create this RuleSession.
protected  RuleExecutionSetImpl getRuleExecutionSet()
          Returns the Drools RuleExecutionSet associated with this RuleSession.
 javax.rules.RuleExecutionSetMetadata getRuleExecutionSetMetadata()
          Returns the meta data for the rule execution set bound to this rule session.
 int getType()
           
protected  void initSession(boolean keepReference)
          Initialize this RuleSession with a new WorkingMemory.
 void release()
          Releases all resources used by this rule session.
 void removeObject(javax.rules.Handle handleObject)
          Removes a given object from the rule session state of this rule session.
 void reset()
          Resets this rule session.
protected  void setProperties(Map properties)
          Sets additional properties used to create this RuleSession.
protected  void setRuleExecutionSet(RuleExecutionSetImpl ruleExecutionSet)
          Sets the Drools RuleExecutionSet associated with this RuleSession.
 void updateObject(javax.rules.Handle objectHandle, Object newObject)
          Notifies the rules engine that a given object in the rule session state has changed.
 
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

initSession

protected void initSession(boolean keepReference)
Initialize this RuleSession with a new WorkingMemory.


containsObject

public boolean containsObject(javax.rules.Handle objectHandle)
Returns true if the given object is contained within rulesession state of this rule session.

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.

addObject

public javax.rules.Handle addObject(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 env. 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:
javax.rules.InvalidRuleSessionException - on illegal rule session state.

addObjects

public List addObjects(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,
                         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 - 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 handleObject)
                  throws javax.rules.InvalidRuleSessionException,
                         javax.rules.InvalidHandleException
Removes a given object from the rule session state of this rule session.

Specified by:
removeObject in interface javax.rules.StatefulRuleSession
Parameters:
handleObject - the handle to the object to be removed from the rule session state.
Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.
javax.rules.InvalidHandleException - if the input Handle is no longer valid

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.

getObject

public Object getObject(javax.rules.Handle handle)
                 throws javax.rules.InvalidRuleSessionException,
                        javax.rules.InvalidHandleException
Specified by:
getObject in interface javax.rules.StatefulRuleSession
Throws:
javax.rules.InvalidRuleSessionException
javax.rules.InvalidHandleException
See Also:
StatefulRuleSessionImpl

getHandles

public List getHandles()
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 currect state of the rule session.

getObjects

public 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.

getObjects

public 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.

reset

public void reset()
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

getType

public int getType()
            throws javax.rules.InvalidRuleSessionException
Specified by:
getType in interface javax.rules.RuleSession
Throws:
javax.rules.InvalidRuleSessionException

release

public void release()
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

checkRuleSessionValidity

protected void checkRuleSessionValidity()
                                 throws javax.rules.InvalidRuleSessionException
Ensures this RuleSession is not in an illegal rule session state.

Throws:
javax.rules.InvalidRuleSessionException - on illegal rule session state.

setProperties

protected void setProperties(Map properties)
Sets additional properties used to create this RuleSession.

Parameters:
properties - additional properties used to create the RuleSession implementation.

getProperties

protected Map getProperties()
Returns the additional properties used to create this RuleSession.

Returns:
the additional properties used to create this RuleSession.

setRuleExecutionSet

protected void setRuleExecutionSet(RuleExecutionSetImpl ruleExecutionSet)
Sets the Drools RuleExecutionSet associated with this RuleSession.

Parameters:
ruleExecutionSet - the Drools RuleExecutionSet to associate with this RuleSession.

getRuleExecutionSet

protected RuleExecutionSetImpl getRuleExecutionSet()
Returns the Drools RuleExecutionSet associated with this RuleSession.

Returns:
the Drools RuleExecutionSet associated with this RuleSession.

getRuleExecutionSetMetadata

public javax.rules.RuleExecutionSetMetadata getRuleExecutionSetMetadata()
Returns the meta data for the rule execution set bound to this rule session.

Specified by:
getRuleExecutionSetMetadata in interface javax.rules.RuleSession
Returns:
the RuleExecutionSetMetaData bound to this rule session.


Copyright © 2001-2007 JBoss Inc.. All Rights Reserved.