public interface RuleSession
The programmer gets access to an initialized RuleSession
in one of the following ways:
RuleSessionManager.getCurrentRuleSession()
RuleServiceProvider.getRuleRuntime().getRuleSession(somename)
These mechanisms are very different and have different meanings.
The first one is used when coding a custom function.
Since the custom function is evaluated as a callback while evaluating/executing a rule, the session is well known,
so the programmer get access to the RuleSession
whitin which the function is operating.
The second mechanism is used when the programmer is managing the lifecycle of the RuleSession
's.
A rule evaluation cycle (RTC) is:
The rule session is always stateful, i.e. it always maintains the state of the instances asserted
across multiple RTCs.
The programmer can call assert(object, true)
multiple times with different objects.
To create an object use the the TypeManager
factory
and pass the object fact type (concept/event/scorecard) which was created in TIBCO Designer.
Set the object's property values using standard setProperty
methods.
Stateless behavior can be achieved by calling reset
on the RuleSession
after every RTC.
The RTC is evaluated on the caller's thread when an assert is invoked with execute permission. At this point, the rule session is set as a ThreadLocal on the caller's thread, so it is available to every function/custom function which is invoked as a result of an action fired or condition evaluated.
Modifier and Type | Method and Description |
---|---|
void |
assertObject(java.lang.Object object,
boolean executeRules)
Adds an object to the Rule Session and optionally executes all the triggered rules
(conflict resolve / executeRules is called).
|
void |
executeRules()
Executes rules that are triggered by previous actions (Add, Update, Remove Object).
|
RuleSessionConfig |
getConfig()
Gets the configuration parameters used for building this
RuleSession . |
java.lang.String |
getName()
Returns the name of this
RuleSession . |
java.util.List |
getObjects()
Gets all the simple events, concepts and scorecards present in this Session.
|
RuleRuntime |
getRuleRuntime()
Gets the manager (parent) who created this session.
|
RuleServiceProvider |
getRuleServiceProvider()
Returns the
RuleServiceProvider associated with this session. |
java.lang.Object |
invokeCatalog(java.lang.String functionFQName,
java.lang.Object[] args) |
java.lang.Object |
invokeFunction(java.lang.String functionURI,
java.lang.Object[] args,
boolean synchronize)
Invoke a RuleFunction on this
RuleSession . |
void |
retractObject(java.lang.Object object,
boolean executeRules)
Removes an object from the session.
|
void |
setActiveMode(boolean active)
Sets the ActiveMode of this
RuleSession . |
java.lang.String getName()
RuleSession
.
This is the same as the name of the corresponding BusinessEvents Archive Resource specified in TIBCO Designer.RuleSession
.RuleSessionConfig getConfig()
RuleSession
.RuleSession
.void executeRules()
RuleSession.assertObject(Object, boolean)
java.util.List getObjects()
SimpleEvent
or Concept
.java.lang.Exception
void assertObject(java.lang.Object object, boolean executeRules) throws DuplicateExtIdException
object
- the object to assert.executeRules
- determines if conflict resolution will happen after asserting the object.DuplicateExtIdException
- if the external ID of the object to assert already exist in the session.void retractObject(java.lang.Object object, boolean executeRules)
object
- or the handle of the object.executeRules
- determines if conflict resolution will happen after retracting the object.RuleRuntime getRuleRuntime()
RuleRuntime
object which is the manager who created this session.RuleServiceProvider getRuleServiceProvider()
RuleServiceProvider
associated with this session.RuleServiceProvider
associated with this session.void setActiveMode(boolean active)
RuleSession
.active
- activate the ruleSession or not.java.lang.Object invokeFunction(java.lang.String functionURI, java.lang.Object[] args, boolean synchronize)
RuleSession
.functionURI
- the URI of the RuleFunction to be invokedargs
- an Object array specifies the input argumentssynchronize
- tells whether to execute the RuleFunction inside the RuleSession OR execute externally
and apply newly created and deleted instance(s) to the RuleSession. Modify a Concept instance is not allow
if this parameter is set to true or the engine will throw a RuntimeException.java.lang.Object invokeCatalog(java.lang.String functionFQName, java.lang.Object[] args)
functionFQName
- the fully qualified Catalog function name to be invoked i.e. "System.debugOut"args
- a variable argument specifying the input arguments