- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.9k
 
expression decoupling design
        wt_better edited this page Dec 21, 2023 
        ·
        1 revision
      
    当前的表达式结构(如下所示)实际上相当分散,主要是由于表达式结构处理逻辑目前分散在调用中,没有集中的中间层来解析它。因此,需要对表达式结构的解析进行集中处理,在向后兼容的基础上采用了图中绿框中的表达式结构。 此外,expression 包和 evaluation 包之间的差异很小,因为两者都用于处理表达式,主要区别在于返回值。事实上,它们都可以统一在表达范畴下。将它们分成两个系统实际上增加了开发人员对代码的理解成本。
删除 evaluation 包,将 ExceptionMatchEvaluator 相关逻辑迁移到了 expression 包下。 新增 ExpressionResolver 接口:
public interface ExpressionResolver {
    Expression getExpression(String expressionStr);
    ExpressionFactoryManager getExpressionFactoryManager();
    void setExpressionFactoryManager(ExpressionFactoryManager expressionFactoryManager);
}其中比较关键的方法是 getExpression 方法,根据一个字符串直接获取对应的表达式。 对 StateMachineConfig 接口进行调整,删除 getEvaluatorFactoryManager 方法,增加了 getExpressionResolver 方法。
| 获取表达式位置 | 原方法 | 新方法 | 
|---|---|---|
| ChoiceStateHandler#process 评估选项表达式 | getEvaluatorFactory | ExpressionResolver | 
| ScriptTaskHandlerInterceptor#preProcess 创建输入输出参数 | ParameterUtils 的静态方法 | ExpressionResolver | 
| ServiceTaskHandlerInterceptor#preProcess创建输入输出参数 | ParameterUtils 的静态方法 | ExpressionResolver | 
| ServiceTaskHandlerInterceptor#decideExecutionStatus决定执行状态 | createEvaluator | ExpressionResolver | 
| LoopTaskUtils#getLoopConfig 集合表达式 | getExpressionFactoryManager | ExpressionResolver | 
| LoopTaskUtils#isCompletionConditionSatisfied 中循环完成评估 | getEvaluator | ExpressionResolver |