Este conteúdo não está disponível no idioma selecionado.
BRMS Rule Flow Component Guide
for Business Rules Developers
Edition 5.3.0
Abstract
Chapter 1. Introduction Copiar o linkLink copiado para a área de transferência!
Chapter 2. Using Rule Flow for the First Time Copiar o linkLink copiado para a área de transferência!
2.1. Creating Your First Process Copiar o linkLink copiado para a área de transferência!
Note
Note
ruleflow.rf: this is the process definition file. In this case, you have a very simple process containing a Start node (the entry point), an Action node (that prints out "Hello World") and an End node (the end of the process).RuleFlowTest.java: this is the Java class that executes the process.- the libraries you require. These are automatically added to the project class-path in the form of a single JBoss Rules library.
ruleflow.rf file. The process will open in the Rule Flow Editor. (The Rule Flow Editor contains a graphical representation of your process definition. It consists of nodes that are connected to each other.) The Editor shows the overall control flow, while the details of each of the elements can be viewed (and edited) in the Properties View at the bottom.
Note
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow"
name="ruleflow"
id="com.sample.ruleflow"
package-name="com.sample" >
<header>
</header>
<nodes>
<start id="1" name="Start" x="16" y="16" />
<actionNode id="2" name="Hello" x="128" y="16" >
<action type="expression"
dialect="mvel">System.out.println("Hello World");</action>
</actionNode>
<end id="3" name="End" x="240" y="16" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="3" />
</connections>
</process>
2.2. Executing Your First Process Copiar o linkLink copiado para a área de transferência!
RuleFlowTest.java and select , followed by .
Hello World
RuleFlowTest class:
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
/**
* This is a sample file to launch a process.
*/
public class ProcessTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// start a new process instance
ksession.startProcess("com.sample.ruleflow");
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF);
return kbuilder.newKnowledgeBase();
}
}
- Firstly, a knowledge base is created. A knowledge base contains all the knowledge (such as words, processes, rules, and so forth) that are needed by your application. This knowledge base is usually created once, and then reused multiple times. In this case, the knowledge base consists of the sample process only.
- Next, a session for interaction with the engine is generated.A logger is then added to the session. This records all execution events and make it easier for you to visualize what is happening.
- Finally, you can start a new instance of the process by invoking the
startProcess(String processId)method on the session. When you do this, your process instance begins to run, resulting in the executions of the Start node, the Action node, and the End node in order. When they finish the process instance will conclude.
test.log file (in your project directory.)
Note
project directory is located, right-click on it and you will find the location listed in the Resource section
Chapter 3. Rule Flows Copiar o linkLink copiado para a área de transferência!
Figure 3.1. A Rule Flow
3.1. Creating a Rule Flow Process Copiar o linkLink copiado para a área de transferência!
- By using the graphical Rule Flow Editor (part of the JBDS' JBoss Rules plug-in.)
- By writing an XML file, according to the XML process format as defined in the XML Schema definition for JBoss Rules processes.
- By directly creating a process using the
ProcessAPI.
3.1.1. Using the Graphical Rule Flow Editor Copiar o linkLink copiado para a área de transferência!
.rf file is created.
General directory, select the Properties View.
3.1.2. Defining Processes Using XML Copiar o linkLink copiado para a área de transferência!
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="ruleflow" id="com.sample.ruleflow" package-name="com.sample" >
<header>
</header>
<nodes>
<start id="1" name="Start" x="16" y="16" />
<actionNode id="2" name="Hello" x="128" y="16" >
<action type="expression" dialect="mvel" >System.out.println("Hello World");</action>
</actionNode>
<end id="3" name="End" x="240" y="16" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="3" />
</connections>
</process>
<process> element. This element contains parameters related to the process (its type, name, ID. and package name), and consists of three subsections: a <header> (where process-level information like variables, globals, imports and swimlanes are defined), a <nodes> section that defines each of the nodes in the process, and a <connections> section that contains the connections between all the nodes in the process.
nodes section, there is a specific element for each node. Use these to define the various parameters and sub-elements for that node type.
3.1.3. Defining Processes Using the Process API Copiar o linkLink copiado para a área de transferência!
Warning
org.drools.workflow.core and org.drools.workflow.core.node packages.
fluent API allows you to construct processes in a readable manner using factories. At the end, you can validate the process that you were constructing manually.
3.1.3.1. Example One Copiar o linkLink copiado para a área de transferência!
RuleFlowProcessFactory factory =
RuleFlowProcessFactory.createProcess("org.drools.HelloWorldRuleSet");
factory
// Header
.name("HelloWorldRuleSet")
.version("1.0")
.packageName("org.drools")
// Nodes
.startNode(1).name("Start").done()
.ruleSetNode(2)
.name("RuleSet")
.ruleFlowGroup("someGroup").done()
.endNode(3).name("End").done()
// Connections
.connection(1, 2)
.connection(2, 3);
RuleFlowProcess process = factory.validate().getProcess();
createProcess() method from the RuleFlowProcessFactory class. This method creates a new process with the given ID.
startNode(), ruleSetNode() and endNode() methods.
NodeFactory, that allows you to set their properties.
done() method to return to the current RuleFlowProcessFactory so you can add more nodes if necessary.
connection method.
validate() method to check your work. This will also retrieve the RuleFlowProcess object you created.
3.1.3.2. Example Two Copiar o linkLink copiado para a área de transferência!
RuleFlowProcessFactory factory =
RuleFlowProcessFactory.createProcess("org.drools.HelloWorldJoinSplit");
factory
// Header
.name("HelloWorldJoinSplit")
.version("1.0")
.packageName("org.drools")
// Nodes
.startNode(1).name("Start").done()
.splitNode(2).name("Split").type(Split.TYPE_AND).done()
.actionNode(3).name("Action 1")
.action("mvel", "System.out.println(\"Inside Action 1\")").done()
.actionNode(4).name("Action 2")
.action("mvel", "System.out.println(\"Inside Action 2\")").done()
.joinNode(5).type(Join.TYPE_AND).done()
.endNode(6).name("End").done()
// Connections
.connection(1, 2)
.connection(2, 3)
.connection(2, 4)
.connection(3, 5)
.connection(4, 5)
.connection(5, 6);
RuleFlowProcess process = factory.validate().getProcess();
3.1.3.3. Example Three Copiar o linkLink copiado para a área de transferência!
RuleFlowProcessFactory factory =
RuleFlowProcessFactory.createProcess("org.drools.HelloWorldForeach");
factory
// Header
.name("HelloWorldForeach")
.version("1.0")
.packageName("org.drools")
// Nodes
.startNode(1).name("Start").done()
.forEachNode(2)
// Properties
.linkIncomingConnections(3)
.linkOutgoingConnections(4)
.collectionExpression("persons")
.variable("child", new ObjectDataType("org.drools.Person"))
// Nodes
.actionNode(3)
.action("mvel", "System.out.println(\"inside action1\")").done()
.actionNode(4)
.action("mvel", "System.out.println(\"inside action2\")").done()
// Connections
.connection(3, 4)
.done()
.endNode(5).name("End").done()
// Connections
.connection(1, 2)
.connection(2, 5);
RuleFlowProcess process = factory.validate().getProcess();
linkIncomingConnections() and linkOutgoingConnections() methods that are called to link the ForEach node with the internal action node. These methods are used to specify the first and last nodes inside the ForEach composite node.
3.2. Using a Process in Your Application Copiar o linkLink copiado para a área de transferência!
- Creating a knowledge base: once you have a valid process, you can add it to your knowledge base. Note that this process is almost identical to that for adding rules to the knowledge base: only the type of knowledge that is added is changed:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newClassPathResource("MyProcess.rf"), ResourceType.DRF );After adding all your knowledge to the builder (you can add more than one process, and even rules), create a new knowledge base:KnowledgeBase kbase = kbuilder.newKnowledgeBase();Warning
This will throw an exception if the knowledge base contains errors (because it will not be able to parse your processes correctly). - Starting a process: processes are only executed if you explicitly state that they should be. This is because you could potentially define a lot of processes in your knowledge base and the engine has no way to know when you would like to start each of them. To activate a particular process, call the
startProcessmethod:StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); ksession.startProcess("com.sample.MyProcess");ThestartProcessmethod's parameter represents the ID. of the process to be started. This process ID. needs to be specified as a property of the process, shown in the Properties View when you click the background canvas.Important
If your process also needs to execute rules, you must also call theksession.fireAllRules()method.Note
You can specify additional parameters to pass input data to the process. To do so, use thestartProcess(String processId, Map parameters)method. This method takes an additional set of parameters as name-value pairs and copies to the newly-created process instance as top-level variables.Note
To start a process from within a rule consequence, or from inside a process action, use the predefinedkcontextparameter:kcontext.getKnowledgeRuntime().startProcess("com.sample.MyProcess");
3.3. Available Node Types Copiar o linkLink copiado para a área de transferência!
- ID: this is the process' unique ID.
- Name: this is the process' unique display name.
- Version: this is the process' version number.
- Package: this is the package (or name-space) in which the process is stored.
- Variables: you can define variables to store data during the execution of your process.
- Exception Handlers: use these specify what is expected to happen when a fault occurs in the process.
- Connection Layouts: use these to specify what your connections are to look like on the canvas:
- Manual always draws your connections as lines going straight from their start points to their end points (with the option to use intermediate break points).
- Shortest path is similar, but it tries to go around any obstacles it might encounter between the start and end point, to avoid lines crossing nodes.
- The Manhattan option draws connections using horizontal and vertical lines only.
3.3.1. Start Event Copiar o linkLink copiado para a área de transferência!
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- Triggers: you can specify triggers that, when activated, will automatically start the process. Examples are a constraint trigger that automatically launches the process if a given rule or constraint is satisfied, and an event trigger that automatically starts the process if a specific event is signalled.
Note
You cannot yet specify these triggers in the Graphical Editor. Edit the XML file instead to add them. - MetaData: this is meta-data related to this node.
3.3.2. End Event Copiar o linkLink copiado para a área de transferência!
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- Terminate: an End node can be terminate the entire process (this is the default) or just one path. If the process is terminated, every active node (even those on parallel paths) in this rule flow is cancelled.Non-terminating End nodes end terminate the current path, while other parallel paths remain.
- MetaData: this is meta-data related to this node.
3.3.3. Rule Task (or RuleFlowGroup) Copiar o linkLink copiado para a área de transferência!
ruleflow-group. Execution will automatically continue to the next node once there are no more active rules in that group.
Note
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- RuleFlowGroup: this is the name of the rule flow group that represents the set of rules for this node.
- Timers: these are any timers that are linked to this node.
- MetaData: this is meta-data related to this node.
3.3.4. Diverging Gateway (or Split) Copiar o linkLink copiado para a área de transferência!
ANDmeans that the control flow will continue in all outgoing connections simultaneously.XORmeans that no more or less than one of the outgoing connections will be chosen. The decision is made by evaluating the constraints that are linked to each of the outgoing connections. Constraints are specified using the same syntax as the left-hand side of a rule. The constraint with the lowest priority number that evaluates to true is selected.Warning
Make sure that at least one of the outgoing connections will evaluate totrueat run time (the rule flow will throw an exception if there are none). For example, you could use a connection which is always true (default) with a high priority number to specify what should happen if none of the other connections can be taken.ORmeans that all outgoing connections whose condition evaluates totrueare selected. Conditions are similar to theXORsplit, except that no priorities are taken into account.Warning
Make sure that at least one of the outgoing connections will evaluate totrueat run time (the rule flow will throw an exception if there are none). For example, you could use a connection which is always true (default) with a high priority number to specify what should happen if none of the other connections can be taken.
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- Type: this is the node type (
AND,XORorOR.) - Constraints: these are the constraints linked to each of the outgoing connections (in case of an
(X)ORsplit). - MetaData: this is meta-data related to this node.
3.3.5. Converging Gateway (or Join) Copiar o linkLink copiado para a área de transferência!
ANDmeans that it will wait until all incoming branches are completed before continuing.XORmeans that it continues as soon as one of its incoming branches has been completed. (If it is triggered from more than one incoming connection, it will activate the next node for each of those triggers.)Discriminatormeans that it will continue if one of its incoming branches has been completed. Other incoming branches are registered as they complete until all connections have finished At that point, the node will be reset, so that it can be triggered again when one of its incoming branches has been completed once more.n-of-mmeans that it continues ifnof itsmincoming branches have been completed. The variablencould either be hard-coded to a fixed value, or refer to a process variable that will contain the number of incoming branches for which it must wait.
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- Type: this is the node type (
AND,XORorOR.) - n: this is the number of incoming connections for which it must wait (in case of a
n-of-mjoin). - MetaData: this is meta-data related to this node.
3.3.6. State Copiar o linkLink copiado para a área de transferência!
true directly, the flow will continue immediately. Otherwise, the flow will continue if one of the constraints is satisfied later on, for example when a fact is inserted, updated or removed from the working memory.
Note
ksession.signalEvent("signal", "name") where name should either be the name of the constraint for the connection that should be selected, or the name of the node to which you wish to move.
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- Constraints: use these to define when the process can leave this state and continue for each of the outgoing connections.
- Timers: these are any timers that are linked to this node.
- On-entry and on-exit actions: these are actions that are executed upon entry or exit of this node, respectively.
- MetaData: this is meta-data related to this node.
3.3.7. Reusable Sub-Process (or SubFlow) Copiar o linkLink copiado para a área de transferência!
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- ProcessId: this is the ID. of the process that is to be executed.
- Wait for completion: if you set this property to
true, the SubFlow node will only continue if it has terminated its execution (by other completing or aborting it); otherwise it will continue immediately after having started the sub-process. - Independent: if you set this property to
true, the sub-process will start as an independent process. This means that the SubFlow process will not terminate if this it reaches an end node; otherwise the active sub-process will be cancelled on termination (or abortion) of the process. - On-entry and on-exit actions: these are actions that are executed upon entry or exit of this node, respectively.
- Parameter in/out mapping: you can also define sub-flow nodes by using in- and out-mappings for variables. The value of variables in this process will be used as parameters when starting the process. The value of the variables in the sub-process will be copied to the variables of this process when the sub-process has been completed.
Note
You can only use out mappings when Wait for completion is set totrue. - Timers: these are any timers that are linked to this node.
- MetaData: this is meta-data related to this node.
3.3.8. Action (or Script Task) Copiar o linkLink copiado para a área de transferência!
drools referring to a KnowledgeHelper object (which can, for example, be used to retrieve the Working Memory by calling drools.getWorkingMemory()), and the variable kcontext that references the ProcessContext object. (This latter object can, for example, be used to access the current ProcessInstance or NodeInstance, and to obtain and set variables).
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- Action: this is the action associated with the node.
- MetaData: this is meta-data related to this node.
3.3.9. Timer Event Copiar o linkLink copiado para a área de transferência!
0 means that the timer should only be triggered once. When the rule flow reaches a Timer node, it starts the associated timer.
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- Timer delay: this is the delay (in milliseconds) that the node should wait before triggering the first time.
- Timer period: this is the period (in milliseconds) between two subsequent triggers. If the period is
0, the timer should only be triggered once. - MetaData: this is meta-data related to this node.
3.3.10. Error Event (or Fault) Copiar o linkLink copiado para a área de transferência!
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- FaultName: this is the name of the fault. This name is used to search for appropriate exception handlers that are capable of handling this kind of fault.
- FaultVariable: this is the name of the variable that contains the data associated with this fault. This data is also passed on to the exception handler (if one is found).
- MetaData: this is meta-data related to this node.
3.3.11. (Message) Event Copiar o linkLink copiado para a área de transferência!
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- EventType: this is the type of event that is expected.
- VariableName: this is the name of the variable that will contain the data (if any) associated with this event.
- Scope: you can use this node to listen to internal events only (that is, events that are signalled to this process instance directly, by using
processInstance.signalEvent(String type, Object data).)You can define it as external, by usingworkingMemory.signalEvent(String type, Object event). In this case, it will also be listening to external events that are signalled to the process engine directly . - MetaData: this is meta-data related to this node.
3.3.12. Sub-Process (or Composite) Copiar o linkLink copiado para a área de transferência!
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- StartNodeId: this is the ID. of the node container node that should be triggered.
- EndNodeId: this is the ID. of the node container node that that represents the end of the flow. When this node is completed, the composite node will also complete and move to the outgoing connection. Every other node executing within this composite node will be cancelled.
- Variables: you can add additional data storage variables.
- Exception Handlers: use these to specify the behavior to occur when a fault is encountered.
3.3.13. Multiple Instance (or ForEach) Copiar o linkLink copiado para a área de transferência!
- ID: this is the ID. of the node (and is unique within one node container).
- Name: this is the node's display name.
- StartNodeId: this is the ID. of the node container node that should be triggered.
- EndNodeId: this is the ID. of the node container node that that represents the end of the flow. When this node is completed, the composite node will also complete and move to the outgoing connection. Every other node executing within this composite node will be cancelled.
- CollectionExpression: this is the name of a variable that represents the collection of elements over which you will iterate. Set the collection variable to
java.util.Collection. - VariableName: this is the name of the variable which contains the current element from the collection. This gives sub-nodes contained in the composite node access to the selected element.
3.4. Data Copiar o linkLink copiado para a área de transferência!
- you can set process-level variables when starting a process by providing a map of parameters to the invocation of the
startProcessmethod. These parameters are then set as variables on the process scope. - actions can access variables directly. They do so by using the name of the variable as a parameter name:
// call method on the process variable "person" person.setAge(10);You can change the value of a variable via the knowledge context:kcontext.setVariable(variableName, value); - you can make WorkItem and SubFlow nodes pass the value of parameters to the "outside world" by mapping the variable to one of the work item parameters. To do so, either use a parameter mapping or interpolate it into a String parameter, using
#{expression}. You can also copy a WorkItem's output to a variable via a result mapping. - various other nodes can also access data. Event nodes, for example, can store the data associated with an event in a variable. Exception handlers can read error data from a specific variable. Check the properties of the different node types for more information.
kcontext.getKnowledgeRuntime().insert( new Person(...) );
3.5. Constraints Copiar o linkLink copiado para a área de transferência!
OR or XOR decisions, or as a constraint for a State node. The Rules Flow Engine supports two types of constraints:
- Code constraints are Boolean expressions, evaluated directly immediately upon arrival. You can write them in either of these two dialects: Java and MVEL. Both have direct access to the globals and variables defined in the process.Here is an example of a constraint written in Java,
personbeing a variable in the process:return person.getAge() > 20;Here is the same constraint written in MVEL:return person.age > 20; - Rule constraints are the same as normal JBoss Rules conditions. They use the JBoss Rules Rule Language's syntax to express what are potentially very complex constraints. These rules can, (like any other rule), refer to data in the working memory. You can also refer to globals directly.Here is an example of a valid rule constraint:
Person( age > 20 )This searches the working memory for people older than twenty.
processInstance : WorkflowProcessInstance()
Person( name == ( processInstance.getVariable("name") ) )
# add more constraints here ...
3.6. Actions Copiar o linkLink copiado para a área de transferência!
- within an Action node,
- as entries or exits, (with a number of nodes),
- to specify the the behavior of exception handlers.
context variable. This latter is of the type org.drools.runtime.process.ProcessContext and can be used for the following tasks:
- obtaining the current node instance. The node instance can be queried for such information as its name and type. You can also cancel it:
NodeInstance node = context.getNodeInstance(); String name = node.getNodeName(); - obtaining the current process instance. A process instance can be queried for such information as its name and processId. It can also be aborted or signalled via an internal event:
WorkflowProcessInstance proc = context.getProcessInstance(); proc.signalEvent( type, eventObject ); - obtaining or setting the value of variables.
- accessing the knowledge run-time, in order to do things like start a process, signal external events or insert data.
person.name instead of person.getName()), and various other advantages. Thus, MVEL expressions are normally more convenient for the business user. For example, an action that prints out the name of the person in the rule flow's requester variable will: look like this:
// Java dialect
System.out.println( person.getName() );
// MVEL dialect
System.out.println( person.name );
3.7. Events Copiar o linkLink copiado para a área de transferência!
Figure 3.2. A sample process using events
- via internal events: to make an action inside a rule flow signal the occurrence of an internal event, using code like this:
context.getProcessInstance().signalEvent(type, eventData); - via external event: to notify a process instance of an external event use code like this:
processInstance.signalEvent(type, eventData); - via external event using event correlation: instead of notifying a process instance directly, you can make the Rule Flow Engine automatically determine which process instances might be interested in an event using event correlation. This is based on the event type. Use this code to make a process instance that contains an event node listening for a particular external event will be notified whenever such an event occurs:
workingMemory.signalEvent(type, eventData);
3.8. Exceptions Copiar o linkLink copiado para a área de transferência!
Figure 3.3. A sample process using exception handlers
context.getProcessInstance().signalEvent("FaultType", context.getVariable("FaultVariable");
3.9. Timers Copiar o linkLink copiado para a área de transferência!
0, the timer will only run once.
- you can add a Timer node to the rule flow. When the node is activated, it starts the timer, and its triggers (once or repeatedly) activate the Timer node's successor. This means that the timer's outgoing connection is triggered multiple times if you set the period. Cancelling a Timer node also cancels the associated timer, after which nothing will be triggered anymore.
- you can associate timers with event-based nodes like WorkItem, SubFlow and so forth. A timer associated with a node is activated whenever the node becomes active. The associated action is executed whenever the timer triggers. You may use this, for instance, to send out regular notifications to alert that the execution of tasks is taking too long to perform, or to signal a fault if a supervision period expires.When the node owning the timer completes, the timer is automatically cancelled.
3.10. Updating Rule Flows Copiar o linkLink copiado para a área de transferência!
- Proceed: you allow the running process instance to proceed as normal, using the definition as it was defined when the instance was started. In other words, the already-running instance will proceed as if the rule flow has not been updated. Only when you start new instances, will the updated version be used.
- Abort (and restart): you abort the running instance. If necessary, restart it so that it will use the new version of the rule flow.
- Transfer: you migrate the process instance to the new process definition, meaning that it will continue executing based on the updated rule flow logic.
3.10.1. Rule Flow Instance Migration Copiar o linkLink copiado para a área de transferência!
WorkflowProcessInstanceUpgrader to upgrade a rule flow process instance to a newer one. To use this tool, you will need to provide the process instance and the new process' ID. By default, the Rules Flow Engine will automatically map old node instances to new ones with the same ID but you can provide a mapping of the old (unique) node ID. to the new node ID. (The unique node ID is the node ID., preceded by the node IDs of its parents, separated by a colon). These IDs allow you to uniquely identify a node when composites are used (as a node ID. is only unique within its node container.)
// create the session and start the process "com.sample.ruleflow"
KnowledgeBuilder kbuilder = ...
StatefulKnowledgeSession ksession = ...
ProcessInstance processInstance = ksession.startProcess("com.sample.ruleflow");
// add a new version of the process "com.sample.ruleflow2"
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(..., ResourceType.DRF);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
// migrate process instance to new version
Map<String, Long> mapping = new HashMap<String, Long>();
// top level node 2 is mapped to a new node with ID 3
mapping.put("2", 3L);
// node 2, which is part of composite node 5, is mapped to a new node with ID 4
mapping.put("5.2", 4L);
WorkflowProcessInstanceUpgrader.upgradeProcessInstance(
ksession, processInstance.getId(),
"com.sample.ruleflow2", mapping);
3.11. Assigning Rules to a Rule Flow Group Copiar o linkLink copiado para a área de transferência!
rule 'YourRule'
ruleflow-group 'group1'
when
...
then
...
end
group1.
drools.getContext(ProcessContext.class).getProcessInstance()
3.12. Example Rule Flows Copiar o linkLink copiado para a área de transferência!
Figure 3.4. A Simple Rule Flow
Check Order group must be executed before the rules in the Process Order group. You could achieve similar results using salience, but this is harder to maintain and makes a time relationship implicit in the rules (or Agenda groups.) By contrast, using a rule-flow makes the processing order explicit, in its own layer on top of the rule structure, allowing you to manage complex business processes more easily.
Figure 3.5. A Complex Rule Flow
Note
AND, OR or XOR. If you choose OR, then any of the split's potential outputs will be allowed to occur, meaning that processing can proceed in parallel along two or more different paths. If you chose XOR, then only one path will be taken.
OR or XOR, there will be a square button on the right-hand side of the Constraints row.
Note
Chapter 4. The API Copiar o linkLink copiado para a área de transferência!
4.1. Knowledge Base Copiar o linkLink copiado para a área de transferência!
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("MyProcess.rf"), ResourceType.DRF);
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
Note
4.2. Session Copiar o linkLink copiado para a área de transferência!
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ProcessInstance processInstance = ksession.startProcess("com.sample.MyProcess");
ProcessRuntime interface defines all of the session methods:
ProcessInstance startProcess(String processId);
ProcessInstance startProcess(String processId, Map<String, Object> parameters);
void signalEvent(String type, Object event);
void signalEvent(String type, Object event, long processInstanceId);
Collection<ProcessInstance> getProcessInstances();
ProcessInstance getProcessInstance(long id);
void abortProcessInstance(long id);
WorkItemManager getWorkItemManager();
4.3. Events Copiar o linkLink copiado para a área de transferência!
ProcessEventListener objects to listen to process-related events (like starting or completing a process or entering or leaving a node.) Here are the different methods for it:
public interface ProcessEventListener {
void beforeProcessStarted( ProcessStartedEvent event );
void afterProcessStarted( ProcessStartedEvent event );
void beforeProcessCompleted( ProcessCompletedEvent event );
void afterProcessCompleted( ProcessCompletedEvent event );
void beforeNodeTriggered( ProcessNodeTriggeredEvent event );
void afterNodeTriggered( ProcessNodeTriggeredEvent event );
void beforeNodeLeft( ProcessNodeLeftEvent event );
void afterNodeLeft( ProcessNodeLeftEvent event );
}
- Console logger: this outputs every event to the console.
- File logger: this outputs every event to an XML file. This log file might then be used in the IDE to generate a tree-based visualization of the events that occurred during execution.
- Threaded file logger: Because a file logger writes the events to disk only when closing the logger or when the number of events in the logger reaches a pre-defined threshold, it cannot be used when debugging processes at run-time. The threaded file logger writes the events to a file after a specified time interval, making it possible to use the logger to visualize progress in real-time, making it useful for debugging.
KnowledgeRuntimeLoggerFactory to add a logger to your session:
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger( ksession, "test" );
// add invocations to the process engine here,
// e.g. ksession.startProcess(processId);
...
logger.close();
Note
before and after events is shown as a child of that event.)
Chapter 5. JBoss Rules IDE Features Copiar o linkLink copiado para a área de transferência!
5.1. JBoss Rules Run-times Copiar o linkLink copiado para a área de transferência!
JAR files that represent one specific release of the JBoss Rules project JARs. To create a run-time, you must point the IDE to the release of your choice.
Note
Note
5.1.1. Defining a JBoss Rules Run-time Copiar o linkLink copiado para a área de transferência!
- if you simply want to use the default JAR files as included with the JBoss Rules plug-in, just click the button.A file browser will appear, asking you to select the directory in which you want this run-time to be created. The plug-in will then automatically copy every required dependency into this directory.
- if you want to use one specific release of the JBoss Rules project, you should create a directory on your file system that contains all of the required libraries and dependencies. Instead of creating a new JBoss Rules run-time as explained above, give your run-time a name and then select the directory that you just created, containing all of the required JARs.
Note
Important
5.1.2. Selecting a Run-time for Your JBoss Rules project Copiar o linkLink copiado para a área de transferência!
JARs it needs to your project's class-path.
Note
Note
5.2. Process Skins Copiar o linkLink copiado para a área de transferência!
Note
SkinProvider.
Appendix A. © 2011 Copiar o linkLink copiado para a área de transferência!
Appendix B. Revision History Copiar o linkLink copiado para a área de transferência!
| Revision History | |||
|---|---|---|---|
| Revision 5.3.0-15.402 | Fri Oct 25 2013 | ||
| |||
| Revision 5.3.0-15.33 | 2012-07-22 | ||
| |||
| Revision 5.2.0-3 | Thur Jan 12 2012 | ||
| |||
| Revision 5.2.0-2 | Mon Nov 21 2011 | ||
| |||
| Revision 5.2.0-1 | Thu Sept 30 2011 | ||
| |||
| Revision 5.2.0-0 | Thu Jul 14 2011 | ||
| |||