|
Rule Execution Server API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ilog.rules.engine.IlrContext
public class IlrContext
IlrContext
is the base class of all the execution contexts.
Rules can be executed only within an execution context.
In IBM Decision server, the rule engine is an instance of IlrContext
,
the rule engine is simply a Java object.
An IlrContext
instance is always attached to an
IlrRuleset
. If the context is created without a ruleset passed
as an argument, it creates its own ruleset.
An IlrContext
instance contains all the methods required to
control the rule engine. IlrRuleset
is responsible for rule
management, IlrContext
is responsible for rule execution.
Since version 5.0, the derivation of IlrContext
has been
deprecated. You should use ruleset variables to add new fields to the
execution context.
An execution context is serializable.
Warning: Serialized objects of this class will not be compatible with future releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of IBM Decision Server.
IlrRuleset
,
Serialized Form
Field Summary | |
---|---|
static String |
firedRulesCountConstant
Deprecated. use instead IlrPropertyNames.FIRED_RULES_COUNT |
PrintWriter |
out
Deprecated. As of ODM 8.0.1, the method note(String) should be used |
Constructor Summary | |
---|---|
IlrContext()
Deprecated. As of JRules 7.1, this way of constructing a context with an empty ruleset is deprecated. See other constructors for replacement. |
|
IlrContext(IlrRuleset ruleset)
Constructs an IlrContext with an IlrRuleset
object. |
|
IlrContext(IlrRuleset ruleset,
com.ibm.rules.engine.connector.DataConnectorFactory dcf)
|
Method Summary | |
---|---|
void |
activatePacket(String packet)
Deprecated. |
void |
activateRule(IlrRule rule)
Deprecated. |
void |
activateRules(IlrRule[] rules)
Deprecated. |
void |
addNoteHandler(IlrNoteHandler handler)
Adds a note handler to the context. |
Object |
assertLogical(Object object)
Deprecated. As of IBM Decision Server 8.0.1, truth maintenance system is deprecated. |
void |
cleanRulesetVariables()
Resets the values of the ruleset variables: either the 'in' parameters, or the 'out' or the local variables. |
int |
connectTool(IlrTool tool)
Connects an IlrTool to the context. |
int |
connectTool(IlrToolFactory toolFactory)
Connects an IlrTool created by an IlrToolFactory
to the context. |
int |
connectTool(IlrToolFactory toolFactory,
String name)
Connects an IlrTool created by an IlrToolFactory
to the context. |
void |
deactivatePacket(String packet)
Deprecated. |
void |
deactivateRule(IlrRule rule)
Deprecated. |
void |
deactivateRules(IlrRule[] rules)
Deprecated. |
void |
disconnectTool(int toolID)
Disconnects a connected IlrTool . |
void |
disconnectTools()
Disconnects all connected IlrTool . |
void |
end()
Prepares this context for garbage collection. |
void |
endCurrentTask()
Ends the context's current task by executing its potential final actions and declaring it as Completed. |
Enumeration |
enumerateInstances()
Enumerates all the rule instances currently in the agenda of the context, without changing the contents of the agenda. |
Enumeration |
enumerateObjects()
Enumerates all the objects in working memory of the context without any discrimination on their types. |
IlrParameterMap |
execute()
Executes the ruleflow defined in the context's ruleset. |
IlrParameterMap |
execute(String name)
Executes the task passed as the argument. |
void |
executeInitialRule()
Deprecated. |
Object |
executeMain(Object arg)
Invokes the ilrmain function with an argument. |
Object |
executeMain(String pkgName,
Object arg)
Invokes the ilrmain function of the specified package with
an argument. |
IlrParameterMap |
executeTask()
Provides a step-by-step execution of the ruleflow. |
int |
fireAllRules()
Fires all the rules in the agenda. |
int |
fireAllRules(IlrAgendaFilter filter)
Fires all the rules in the agenda using an agenda filter. |
IlrRuleInstance |
fireRule()
Fires the rule in the agenda that has the highest priority. |
IlrRuleInstance |
fireRule(IlrAgendaFilter filter)
Fires the next rule instance in the agenda that passes the filter. |
int |
fireRules(IlrRule[] rules)
Adds the rules passed as its argument to the context, fires all the rules in the agenda, and removes the rules that were passed as its argument. |
IlrRule[] |
getActivatedRules()
Deprecated. |
int |
getConnectedToolNumber()
Gives the number of connected IlrTool (s) to the context. |
IlrTask |
getCurrentTask()
Returns the task that is currently executing or the task that is in a suspended state in the ruleflow. |
static IlrNoteHandler |
getDefaultNoteHandler()
Returns the default note handler. |
IlrEvent |
getEvent(Object object)
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
IlrExceptionHandler |
getExceptionHandler()
Gets the exception handler of this execution context. |
IlrRuleInstance |
getFirstInstance()
Gets the first rule instance of the agenda. |
IlrTask |
getMainTask()
Returns the task defined as the main task in the context's ruleset ruleflow. |
Object[] |
getObjects(IlrClass clazz)
Gets all the objects in working memory that are instances of the passed XOM class. |
Object |
getParameterValue(String name)
Gets the value of the ruleset parameter. |
IlrParameterMap |
getReturnValues()
Returns the values of the "out" ruleset variables (those defined either with the "inout" or "out" modifier). |
IlrRuleset |
getRuleset()
Gets the ruleset to which the context is attached. |
IlrTask |
getTask(String name)
Returns the task defined in the ruleflow and whose name is the one passed as the parameter. |
boolean |
hasInstances(IlrRule rule)
Tests whether the agenda contains instances of a rule. |
void |
insert(Object object)
Inserts the object passed as the argument. |
IlrEvent |
insertEvent(long timestamp,
Object object)
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
IlrEvent |
insertEvent(Object object)
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
Object |
insertLogical(Object object)
Deprecated. As of IBM Decision Server 8.0.1, truth maintenance system is deprecated. |
Object |
invokeFunction(String name,
Object[] arguments)
Invokes a function of the context giving its name and the argument values. |
boolean |
isAgendaNotEmpty()
Tests whether the agenda contains at least one fireable rule instance. |
boolean |
isCacheRuleflowData()
Tests whether or not the ruleflow data is cached when resetRuleflow() is called. |
boolean |
isRuleActivated(IlrRule rule)
Deprecated. |
boolean |
isRuleflowCompleted()
Tests whether the ruleflow execution is completed, which means that the ruleflow execution is not interrupted because of either a suspended task or a task by task execution. |
boolean |
isRuleSelected(IlrRule rule)
Tests whether the rule is selected to be part of the executable rules. |
boolean |
isTaskCompleted(String name)
Tests whether the specified task is completed. |
boolean |
isUsingFlow()
Returns a boolean to indicate whether a ruleflow has been defined in the context's ruleset. |
long |
nextTime()
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
long |
nextTime(long increment)
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
void |
note(String note)
Sends a note to the context's note handlers. |
void |
refreshAgenda()
Adds in the agenda all the rule instances that have been refracted. |
void |
removeAllInstances()
Removes all the instances currently in the agenda without firing them. |
void |
removeAllNoteHandlers()
Removes all note handlers from the context. |
void |
removeInstance(IlrRuleInstance instance)
Removes a particular rule instance from the agenda. |
void |
removeInstances(IlrRule rule)
Removes all the instances of a rule currently in the agenda without firing them. |
void |
removeNoteHandler(IlrNoteHandler handler)
Removes a note handler from the context. |
void |
reset()
Called by Rule Studio to prepare a context for another execution. |
void |
resetRuleflow()
Resets ruleflow execution in the context. |
void |
retract(Object object)
Retracts an object from working memory, if the object has been asserted. |
void |
retractAll()
Retracts all the objects from working memory. |
void |
retractEvent(Object object)
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
void |
send(Object object)
Throws an IlrUserActionException exception. |
void |
send(String message,
Object object)
Throws an IlrUserActionException exception using a message and an
object. |
void |
setCacheRuleflowData(boolean cache)
Sets whether or not to keep the cached ruleflow data when resetRuleflow() is called. |
void |
setExceptionHandler(IlrExceptionHandler handler)
Sets the exception handler of this execution context. |
void |
setMainTask(String name)
Sets the ruleflow main task by giving its name. |
void |
setParameters(IlrParameterMap parameters)
Sets the values of the declared ruleset variables contained in the
passed |
void |
setParameterValue(String name,
Object value)
Sets the value of the ruleset parameter. |
void |
setRuleflowExceptionHandler(IlrExceptionHandler handler)
Sets the exception handler responsible for catching runtime exceptions thrown during the execution of a ruleflow. |
void |
setTime(long time)
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
long |
time()
Deprecated. As of IBM Decision Server 7.5, event processing is deprecated. |
void |
update(Object object)
Updates an object in working memory, if the object has been asserted. |
void |
update(Object object,
boolean refresh)
Updates an object in working memory if the object has been asserted. |
void |
updateContext()
Updates the references to the context object. |
void |
updateContext(boolean refresh)
Updates references to the context object to ensure that the agenda is in a consistent state with the objects referenced by this context. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public transient PrintWriter out
note(String)
should be usedPrintWriter
which prints to
System.out
. The destination, of course, can be changed.
This field provides an easy way to redirect the printing of
messages.
public static String firedRulesCountConstant
IlrPropertyNames.FIRED_RULES_COUNT
execute
and getReturnValues
methods to
store the number of rules fired during this execution. Its value is
ilog.rules.firedRulesCount
.
Constructor Detail |
---|
@Deprecated public IlrContext()
IlrContext
with no argument. This method
creates an empty IlrRuleset
attached to the context. The ruleset
can then be obtained using the getRuleset()
method. The creation of a context, ordinarily fires the Initial Actions. Since this constructor creates its own ruleset, and the ruleset has no rules initially, then there is no Initial Actions to fire.
getRuleset()
public IlrContext(IlrRuleset ruleset)
IlrContext
with an IlrRuleset
object. The ruleset must have the same context class as the created
context. If not, an IlrBadContextException
is thrown. If the
ruleset has an Initial Action, and if the instance being constructed is a
direct instance of IlrContext
, the action is executed. In
the case that the context is derived, the user must call
executeInitialRule()
explicitly in the body of the derived class
constructor, after all the fields have been initialized.
ruleset
- The ruleset to which the context is attached.IlrBadContextException
public IlrContext(IlrRuleset ruleset, com.ibm.rules.engine.connector.DataConnectorFactory dcf)
Method Detail |
---|
public int connectTool(IlrTool tool) throws IlrToolConnectionException
IlrTool
to the context. An
IlrToolConnectionException
is thrown if the connection
fails.
IlrToolConnectionException
tool
- The IlrTool
to connect.
IlrTool
's identifier.IlrTool
,
IlrToolConnectionException
public int connectTool(IlrToolFactory toolFactory) throws IlrToolConnectionException
IlrTool
created by an IlrToolFactory
to the context. An IlrToolConnectionException
is thrown if
the connection fails.
IlrToolConnectionException
toolFactory
- The IlrToolFactory
used to create a new
IlrTool
.
IlrTool
's identifier.IlrTool
,
IlrToolConnectionException
,
IlrLocalTracerToolFactory
,
ilog.rules.debug.IlrBuilderToolFactory
public int connectTool(IlrToolFactory toolFactory, String name) throws IlrToolConnectionException
IlrTool
created by an IlrToolFactory
to the context. An IlrToolConnectionException
is thrown if
the connection fails.
IlrToolConnectionException
toolFactory
- The IlrToolFactory
used to create a new
IlrTool
.name
- A user context name. This name can be used by each created
IlrTool
to identify the context.
IlrTool
's identifier.IlrTool
,
IlrToolConnectionException
,
IlrLocalTracerToolFactory
,
ilog.rules.debug.IlrBuilderToolFactory
public int getConnectedToolNumber()
IlrTool
(s) to the context.
IlrTool
(s).public void disconnectTool(int toolID)
IlrTool
.
toolID
- The IlrTool
's identifier.public void disconnectTools()
IlrTool
.
public void note(String note)
When a context is created, a default note handler is set (see
getDefaultNoteHandler()
.
This default note handler may be removed by a call to
removeAllNoteHandlers()
.
Other note handlers may be added by calling
addNoteHandler(IlrNoteHandler)
.
This method is multi-thread safe at the context level, yet the note handlers that are called may not be multi-thread safe themselves.
note
- The note.public void addNoteHandler(IlrNoteHandler handler)
handler
- The note handler.note(String)
,
removeNoteHandler(IlrNoteHandler)
,
removeAllNoteHandlers()
public void removeNoteHandler(IlrNoteHandler handler)
handler
- The note handler.note(String)
,
addNoteHandler(IlrNoteHandler)
,
removeAllNoteHandlers()
public void removeAllNoteHandlers()
note(String)
has no effect.
note(String)
,
addNoteHandler(IlrNoteHandler)
,
removeNoteHandler(IlrNoteHandler)
,
removeAllNoteHandlers()
public static IlrNoteHandler getDefaultNoteHandler()
out
.
note(String)
public final IlrRuleset getRuleset()
public final void end()
public void reset()
reset
, Rule Studio calls this method to make the context
ready for another run. By default, this method is defined as:
public synchronized void reset() { retractAll(); cleanRulesetVariables(); resetRuleflow(); executeInitialRule(); }
A derived context class may override this method to perform additional preparations for the execution of the context.
public void send(Object object) throws IlrUserActionException
IlrUserActionException
exception. This method is
intended to be used in a rule action to exit from the firing loop. The
method can catch the exception and process the result. An object is
passed along with the exception. It may contain a result or the cause.
IlrUserActionException
object
- The object used to construct the exception.send(java.lang.String,java.lang.Object)
public void send(String message, Object object) throws IlrUserActionException
IlrUserActionException
exception using a message and an
object.
IlrUserActionException
message
- The message used to construct the exception.object
- The object used to construct the exception.send(Object)
public final IlrExceptionHandler getExceptionHandler()
null
if no exception
handler has been set.public void setExceptionHandler(IlrExceptionHandler handler)
java.io.Serializable
.
Note that the exception handler mechanism is restricted to the tasks
running the Rete+ algorithm. Even if set, the exception handler will not
be called from a task running the Sequential algorithm or the Fastpath
algorithm.
handler
- The new exception handler for this context. If this parameter
is null
, the context will be set without an
exception handler.@Deprecated public void executeInitialRule()
IlrContext
, the action(s) is/are automatically executed.
public Object invokeFunction(String name, Object[] arguments) throws IlrNoSuchFunctionException
IlrNoSuchFunctionException
- in case the function is not known.name
- The function name.arguments
- The argument array.
null
.public Object executeMain(Object arg) throws IlrNoSuchFunctionException
ilrmain
function with an argument.
IlrNoSuchFunctionException
- if the ilrmain
is not defined.arg
- The argument of the function.
null
.public Object executeMain(String pkgName, Object arg) throws IlrNoSuchFunctionException
ilrmain
function of the specified package with
an argument.
IlrNoSuchFunctionException
- if the ilrmain
is not defined in this package.arg
- The argument of the function.
null
.@Deprecated public final long time()
nextTime()
,
nextTime(long)
,
setTime(long)
@Deprecated public final long nextTime()
time()
,
nextTime(long)
,
setTime(long)
@Deprecated public final long nextTime(long increment)
increment
- A positive time increment.
time()
,
nextTime()
,
setTime(long)
@Deprecated public final void setTime(long time)
time
- The new time of the engine.time()
,
nextTime()
,
nextTime(long)
public void insert(Object object)
IlrEvent
interface, it is inserted as an event; its timestamp is
obtained by calling the time
method specified by this
interface. If the object is already in working memory, a normal update is
performed.
object
- The object to insert.public Object insertLogical(Object object)
equals
method. If such an object is
found, the passed object is not inserted and the object in working memory
is returned. If no such object is found, the provided object is inserted
and returned. In both cases, the object in working memory is stated: it
is not maintained by any rule.
object
- The logical object to be inserted.
public Object assertLogical(Object object)
insertLogical(Object)
method.
object
- The logical object to be inserted.
@Deprecated public IlrEvent insertEvent(Object object)
If the object implements the
IlrEvent
interface, its timestamp is obtained by calling the
time
method specified by this interface. The method then
returns the inserted object itself.
If the object does not implement
the IlrEvent
interface, the current value of the context internal
clock is taken for the object timestamp. This method builds an instance
of the IlrDefaultEvent
class encapsulating the inserted object,
and returns it.
In all cases, if the event is already in working memory, a normal update is performed instead of the insert operation. Otherwise, the returned object is added to working memory.
object
- The object to be inserted as an event.
time()
@Deprecated public IlrEvent insertEvent(long timestamp, Object object)
IlrEvent
interface. (If it does, the method throws an
IllegalArgumentException
.) This method builds an instance
of the IlrDefaultEvent
encapsulating the asserted object, taking
the provided date for the object timestamp, adds the created instance to
working memory, and returns it. If the event is already in working
memory, a normal update is performed instead of the assert operation.
IllegalArgumentException
- If object
implements the IlrEvent
interface.timestamp
- The timestamp of the object to be asserted as an event.object
- The object to be asserted as an event.
public void retract(Object object)
IlrEvent
interface, then this method must be provided with the
instance of IlrDefaultEvent
that has been created and returned
upon assertion, and that can also be retrieved using the
getEvent(java.lang.Object)
method.
object
- The object to retract.retractEvent(Object)
@Deprecated public void retractEvent(Object object)
IlrEvent
interface.
object
- The object to retract.retract(Object)
,
getEvent(Object)
public final void update(Object object)
Updates an object in working memory, if the object has been asserted.
This method is equivalent to calling update(Object,boolean)
with
the second argument set to false
.
object
- The object to update.public void update(Object object, boolean refresh)
Updates an object in working memory if the object has been asserted. If
the Boolean argument is false
, this method does the same
thing as the previous method. If the Boolean argument is
true
, the update will cause the agenda to be refreshed:
if a rule that uses this object is true
, a rule instance
is inserted into the agenda. In this case, the rule applies as long as it
can be fired.
object
- The object to update.refresh
- The update flag. It is false
for a normal
update and true
for a looping rule behavior.public final void updateContext()
Updates the references to the context object. Calling this method is
equivalent to calling updateContext(boolean)
with
false
as argument.
public void updateContext(boolean refresh)
?context
variable in the rules.
refresh
- Set to true
if a rule instance must be created
for each combination of objects that satisfies a rule. This
flag has the same interpretation as
update(Object,boolean)
.public void retractAll()
Retracts all the objects from working memory. The context becomes empty as if it had just been created (without the execution of the Initial Actions). The agenda is also emptied. The rules are not affected by this method.
public final Object[] getObjects(IlrClass clazz)
Gets all the objects in working memory that are instances of the passed XOM class. The returned objects can be direct instances of the XOM class, or instances of a sub-class of the XOM class.
clazz
- The XOM class.
@Deprecated public final IlrEvent getEvent(Object object)
Returns the event object in working memory if the object provided has
been asserted as an event. If object
implements the
IlrEvent
interface, the returned object will be the object
itself. Otherwise, the returned object will be the instance of
IlrDefaultEvent
which was created on assertion. If the object has
not been asserted as an event, the method returns null
.
object
- The object to look for in working memory as an event.
null
if the
object has not been asserted as an event.public final Enumeration enumerateObjects()
Enumerates all the objects in working memory of the context without any discrimination on their types.
public final boolean isAgendaNotEmpty()
Tests whether the agenda contains at least one fireable rule instance.
Note: This method can be used in the following cases:
true
if the agenda is not empty,
false
if the agenda is empty.public final IlrRuleInstance getFirstInstance()
Gets the first rule instance of the agenda. This rule instance is the one placed at the top of the agenda and is the next to be fired. The agenda is not modified.
Note: This method can be used in the following cases:
null
if
the agenda is empty.public final boolean hasInstances(IlrRule rule)
Tests whether the agenda contains instances of a rule.
Note: This method can be used in the following cases:
rule
- The rule for which existence of instances is to be checked.
true
if the agenda contains at least one instance
of the rule, otherwise it returns false
.public final void removeInstances(IlrRule rule)
Removes all the instances of a rule currently in the agenda without firing them.
Note: This method can be used in the following cases:
rule
- The rule for which instances are to be removed.public final void removeAllInstances()
Removes all the instances currently in the agenda without firing them. The agenda will become empty.
Note: This method can be used in the following cases:
public final void removeInstance(IlrRuleInstance instance)
Removes a particular rule instance from the agenda.
Note: This method can be used in the following cases:
instance
- The rule instance to remove from the agenda.public final Enumeration enumerateInstances()
Enumerates all the rule instances currently in the agenda of the context, without changing the contents of the agenda.
Note: This method can be used in the following cases:
public final void refreshAgenda()
Adds in the agenda all the rule instances that have been refracted. A refracted rule instance is one which has been fired or filtered, and which still evaluates to true.
Note: This method can be used in the following cases:
public IlrRuleInstance fireRule()
Fires the rule in the agenda that has the highest priority.
Note: This method can be used in the following cases:
null
if the
agenda is empty.public IlrRuleInstance fireRule(IlrAgendaFilter filter)
Fires the next rule instance in the agenda that passes the filter. If the
filter is null
, then the next instance is fired.
Otherwise, a rule instance is popped from the agenda, if it passes the
filter, it is fired. If it does not pass the filter, it is discarded.
This process loops until a rule instance is found that passes the filter
or the agenda is empty.
Note: This method can be used in the following cases:
null
if
the agenda is empty or no rule instance in the agenda passes the
filter.public int fireAllRules()
Fires all the rules in the agenda.
Note: This method can be used in the following cases:
public int fireAllRules(IlrAgendaFilter filter)
Fires all the rules in the agenda using an agenda filter. If the passed
filter is null
, then all the rule instances are fired.
Otherwise, a rule instance is popped from the agenda, if it passes the
filter, it is fired. If it does not pass the filter, it is discarded.
This process loops until no rule instance is left in the agenda.
Note: This method can be used in the following cases:
filter
- The agenda filter.
public void activateRule(IlrRule rule)
Adds a rule to the context. The rule must belong to the ruleset to which this context is attached. Otherwise, this method does nothing.
If the rule is added, only the current context is affected. The contents of this context is updated accordingly.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
rule
- The rule to be added.public void activateRules(IlrRule[] rules)
Adds rules to the context. If the context class of the added rules does not match this context or if the context already contains the specified rules, the rule are not added. If rules are added, only the current context is affected. The content of the context is updated.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
rules
- The rules to be added.public void activatePacket(String packet)
Activates a rule packet.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
packet
- The packet to be activated.public void deactivatePacket(String packet)
Deactivates a rule packet.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
packet
- The packet to be deactivated.public void deactivateRule(IlrRule rule)
Removes a rule from the context. The rule must belong to the ruleset to which this context is attached. Otherwise, this method does nothing.
If the rule is removed, the contents of this context is updated.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
rule
- The rule to be removed.public void deactivateRules(IlrRule[] rules)
Removes rules from the context. If the context class of the rules to be removed does not match this context or if the context does not contain the specified rules, the rule are not removed. If rules are removed, only the current context is affected. The content of the context is updated.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
rules
- The rules to be removed.public final boolean isRuleActivated(IlrRule rule)
Tests whether this context contains a rule.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
rule
- A rule.
true
if the context contains the rule, otherwise
it returns false
.public final boolean isRuleSelected(IlrRule rule)
Tests whether the rule is selected to be part of the executable rules. In
case there is no ruleflow, this method returns the same value as
isRuleActivated
. If there is a ruleflow, this method
returns true
if the rule is part of the current task, else
it returns false
.
rule
- A rule.
true
if the the rule is selected as executable
rule, otherwise it returns false
.public final IlrRule[] getActivatedRules()
Returns all the rules in the context.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
IlrRule
. The length of the array can
be 0.public int fireRules(IlrRule[] rules)
Adds the rules passed as its argument to the context, fires all the rules in the agenda, and removes the rules that were passed as its argument. It returns the number of fired rules. This method is particularly useful if you know the agenda is empty and you only want specific rules to be fired.
Note: This method may not work within a ruleflow, as the rules in a ruleflow are controlled by their tasks.
rules
- The rules to be fired.
public IlrParameterMap execute()
Executes the ruleflow defined in the context's ruleset. If the ruleflow is in a suspended state (its execution has been started but is hanging because one task has not completed), execution will resume from the uncompleted task, that is, "the current task".
This method calls fireAllRules
if no ruleflow is defined
in the context's ruleset.
The number of fired rules is returned in the returned
IlrParameterMap
(when a ruleflow is executed, the number
of rules corresponds to the total number of rules fired during the entire
ruleflow execution). The value can be get in the result with the name
IlrContext.firedRulesCountConstant
. The method also
returns the values of the ruleset variables whose modifier is either
"out" or "inout".
IlrParameterMap
containing the "out"
and "inout" ruleset variable values and the number of
rules fired.IlrParameterMap
public void setMainTask(String name)
Sets the ruleflow main task by giving its name. If no task with this
name is defined in the context's ruleset, an
IlrUserRuntimeException
, encapsulating an
IlrUndefinedTaskException
is thrown. This exception can be
caught if a ruleflow exception handler has been set on the context. The
task set with this method takes precedence over any task named
"main" in the ruleflow.
If there is no ruleflow defined in the context's ruleset, this method will be ignored.
setRuleflowExceptionHandler(IlrExceptionHandler)
public IlrTask getMainTask()
Returns the task defined as the main task in the context's ruleset
ruleflow. The ruleflow's main task is defined as follows: - the task
whose property "mainflowtask" is set to true
,
or - the task named "main", or - the task set as main by the
API call setMainTask
.
public void setParameters(IlrParameterMap parameters)
Sets the values of the declared ruleset variables contained in the
passed IlrParameterMap
(defined either with the
"in" or "inout" modifier). If one of the values does
not correspond to an "in" or "inout" variable in the
ruleset, an IllegalArgumentException
exception is thrown.
parameters
- The structure containing "in" and "inout"
ruleset variables with a given value.public void setParameterValue(String name, Object value)
IllegalArgumentException
is
thrown.
name
- The name of the parameter whose value is set.value
- The value of the ruleset parameter.public Object getParameterValue(String name)
IllegalArgumentException
is
thrown.
name
- The name of the parameter whose value is requestedpublic void cleanRulesetVariables()
public IlrParameterMap getReturnValues()
Returns the values of the "out" ruleset variables (those
defined either with the "inout" or "out" modifier).
The returned value contains the number of fired rules stored in the
variable IlrContext.firedRulesCountConstant
.
IlrParameterMap
that contains all the
"out" ruleset variables with their values.IlrParameterMap
public final boolean isUsingFlow()
Returns a boolean to indicate whether a ruleflow has been defined in the context's ruleset.
true
if a ruleflow is defined in the context's
ruleset, else returns false
.public void endCurrentTask()
Ends the context's current task by executing its potential final actions and declaring it as Completed. This task has been suspended during the flow execution because its completion flag returned false.
public IlrParameterMap execute(String name)
Executes the task passed as the argument. This call is equivalent to call
setMainTask
with the passed task and then
execute
.
name
- The task's name.
IlrParameterMap
public IlrParameterMap executeTask()
Provides a step-by-step execution of the ruleflow. If the context's
ruleset does not contain a ruleflow, it calls fireRule
.
Otherwise it executes one task and exits. The ruleflow retains the
current task, and the next call to execute
or
executeTask
starts from the current task.
IlrParameterMap
containing the "out"
and "inout" ruleset variable values and the number of
rules fired.IlrParameterMap
public void setRuleflowExceptionHandler(IlrExceptionHandler handler)
Sets the exception handler responsible for catching runtime
exceptions thrown during the execution of a ruleflow. Note that setting
an exception handler is not mandatory. The handler will not only be called,
when the exception occurs within ruleflow statement execution. For exception that occurs during
rule execution of the ruleflow you must use @link setExceptionHandler(IlrExceptionHandler)
handler
- The exception handler in charge of catching ruleflow execution
exceptions.public IlrTask getTask(String name)
Returns the task defined in the ruleflow and whose name is the one
passed as the parameter. It returns null
if no such task
exists.
name
- The name of a task to return.
name
.public IlrTask getCurrentTask()
Returns the task that is currently executing or the task that is in
a suspended state in the ruleflow. If the ruleset linked to
the context contains no ruleflow, the returned value is null
.
If there is a ruleflow that is neither executing nor suspended, the
returned value is null
. When the ruleflow is suspended
because of a suspended task (a task is suspended because its completion
flag returned a value of false) the current task is this task. If this
suspended task has been completed by the endCurrentTask
method, it is no longer the current task. The ruleflow's current task is
the one that is suspended, that is, the task that models the ruleflow
itself. If the ruleflow is suspended because of a task by task execution,
the current task is the one that models the ruleflow itself.
public void resetRuleflow()
public final boolean isCacheRuleflowData()
Tests whether or not the ruleflow data is cached when
resetRuleflow()
is called.
setCacheRuleflowData(boolean)
,
resetRuleflow()
public final void setCacheRuleflowData(boolean cache)
Sets whether or not to keep the cached ruleflow data when
resetRuleflow()
is called.
When the ruleflow data is cached, some internal ruleflow execution
objects are reused from one call to execute()
to another.
Otherwise, all the ruleflow internal objects are re-created at each call
to execute()
. You should try keeping the ruleflow data cached
when the ruleflow has few application objects to process at one time
during each individual call to execute()
. Note that the
internal ruleflow objects related to purely dynamic tasks cannot be
reused even if the ruleflow data is cached, because they depend on
runtime values and have to be recomputed when required.
By default, the ruleflow data is not cached.
cache
- The control flag.isCacheRuleflowData()
,
resetRuleflow()
,
execute()
public boolean isTaskCompleted(String name)
Tests whether the specified task is completed. A task is said to be
Completed if it has ended (or not started) its execution. This
state is different from a Suspended state, which means that
the task execution did not finish: the final actions of the task have not
been executed, and if we execute the flow again we start at the suspended
task. If the task is not defined in the ruleset, this method throws an
IlrUndefinedTaskException
exception encapsulated into an
IlrUserRuntimeException
exception.
name
- The task's fully qualified name.
true
if the specified task is not executing, else
returns false
.public boolean isRuleflowCompleted()
Tests whether the ruleflow execution is completed, which means that the ruleflow execution is not interrupted because of either a suspended task or a task by task execution.
true
if the ruleflow execution is completed, else
returns false
.
|
Rule Execution Server API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |