6.9. カスタムノードの動作

すべてのビジネスロジックを実行でき、 グラフ実行を渡す役目を果たす ActionHandler の特別な実装を使用してカスタムノードを作成します。 以下は、 ERP システムより値を読み取り、 プロセス変数より数値を追加し、 結果を ERPシ ステムに保存する例になります。 数値の大きさを基に、 small amounts 遷移または large amounts 遷移を使用して終了します。
ERP サンプルを更新するためのプロセススニペット

図6.3 ERP サンプルを更新するためのプロセススニペット

public class AmountUpdate implements ActionHandler {
  public void execute(ExecutionContext ctx) throws Exception {
    // business logic
    Float erpAmount = ...get amount from erp-system...;
    Float processAmount = (Float) ctx.getContextInstance().getVariable("amount");
    float result = erpAmount.floatValue() + processAmount.floatValue();
    ...update erp-system with the result...;
    
    // graph execution propagation
    if (result > 5000) {
      ctx.leaveNode(ctx, "big amounts");
    } else {
      ctx.leaveNode(ctx, "small amounts");
    }
  }
}

注記

カスタムノード実装でトークンの作成や結合も可能です この方法について学ぶため、JBPM ソースコードにある Fork と Join のノードの実装を見てみましょう。