让我们仔细分析一下流程JPD。下面有用于调用规则引擎的Control Send节点的代码。正如我们可以看到的,该节点使用一个Rules Executor控件来评估规则集,该控件返回一个迭代器。通过其属性(没有给出),控件将过滤结果,仅返回Beans.Action类的对象。通过这些对象,代码将提取动作命令并执行所请求的动作。正如前面所提到的,如果动作是聚集该交易,则流程将使用更新后的块作为输入,对规则引擎开始第二次调用。通过执行适当的动作,对结果进行第二次迭代循环。public void rulesExecutorControlEvaluateRuleSet()
throws Exception
{
// Execute the Rules using facts as the input
//#START: CODE GENERATED - PROTECTED SECTION - you can safely
// Add code above this comment in this method. #//
// Input transform
// Return method call
this.results =
rulesExecutorControl.evaluateRuleSet(this.facts);
// Output transform
// Output assignments
//#END : CODE GENERATED - PROTECTED SECTION - you can safely
// Add code below this comment in this method. #//
/* Iterate over the results of rules execution. This assumes that
results are filtered to return only items of the Beans.Action class.
The command property from the Action is expected to be either the
string "create," in which case a Block trade can be executed from
the single discrete Trade, or it is expected to be a list of
attributes describing the Block that this Trade should be
incorporated into.
*/
while (results.hasNext())
{
String action =
((Action)results.next()).getCommand();
if (action.equals("create"))
(new Block(trade)).execute(); // single-trade
else
{
// Aggregate trade into an intermediate Block
trade.aggregate(blockStorage, action);
/* Call the rules engine a second time, this time using
the resulting Block as the only input. This is to
determine if the resulting Block now meets the criteria
to execute the order. Again, results are assumed to be
filtered by the control to return only the Actions.
*/
Block block = trade.getBlock();
Object blockFacts[] = new Object[1];
blockFacts[0] = block;
Iterator blockResults =
blockRulesCntl.evaluateRuleSet(blockFacts);
while (blockResults.hasNext())
{
action =
((Action)blockResults.next()).getCommand();
if (action.equals("create"))
block.execute();
}
}
}
}
(编辑:aniston)
|