-
Notifications
You must be signed in to change notification settings - Fork 29
StepChain QuickStar Andvance 高级篇
zengfr曾繁荣 edited this page Aug 11, 2019
·
5 revisions
1、StepChain 的中心思想是什么?如何做到通用的?
答:
1.1、任何业务逻辑处理抽象成1\input输入 2\ processor处理器 3\output输出.中间过程结果产生和组合成dataMiddle。
1.2、任何业务逻辑处理使用多个processor组合执行。
2、StepChain 如何并行和串行执行多个processor ?
答:
串行step=pipeline.createStep();step.put(processors);//processors串行执行.
并行step=pipeline.createStep(4);step.put(processors);//processors同时4个并行执行.
3、Stepchain 如何创建processor?
3.1、实现 IProcessor 接口。
3.2、使用IProcessorBuilder:
<I> IProcessor<I, Boolean> createProcessor(Predicate<I> predicate);
<I> IProcessor<I, Boolean> createProcessor(Consumer<I> consumer);
<I, O> IProcessor<I, O> createProcessor(Function<I, O> func);
4、StepChain 如何复用和组合processor?
4.1、使用IChainBuilder、IChain:
4.2、使用IProcessorBuilder:
<A, B, C> IProcessor<A, C> createProcessor(IProcessor<A, B> first, IProcessor<B, C> second);
<A, B, C, D> IProcessor<A, D> createProcessor(IProcessor<A, B> processor1, IProcessor<B, C> processor2, IProcessor<C, D> processor3);
5、StepChain 如何按条件复用和组合processor?
答:
case1、已有trueProcessor\falseProcessor2个 创建 validator 则按条件执行2则之1.
IConditionSelectorProcessor<String, Boolean, String> p3 = pipeline.createConditionValidatorProcessor(validator, trueProcessor, falseProcessor);
case2、已有processor 创建 validator 创建循环执行体,validator 返回false时终止执行。
IConditionLoopProcessor<String, String> p2 = pipeline.createConditionLoopProcessor(validator, processor);
case3、已有processor创建 switch 逻辑,根据selector返回的key执行某1分支branchProcessor如果返回的key不在分支中 则执行默认key对应的分支branchProcessor。
IConditionSelectorProcessor<String, String, String> p1 = pipeline.createConditionSelectorProcessor(selector);
p1.setBranch(S key, IProcessor<I, O> processor);
p1setDefaultBranch(S key);
case4、已有processor创建 if/else if/else 逻辑,根据validator返回的结果与result对比一致则执行分支branchProcessor,如果没有返回一致的 则执行默认分支branchProcessor。
pipeline.createConditionValidatorSelectorProcessor();
public interface IConditionValidatorSelectorProcessor<I,O> extends IProcessor<I, O> {
void setBranch(IProcessor<I, Boolean> validator,Boolean result,IProcessor<I, O> processor);
void setDefaultBranch(IProcessor<I, O> processor);
}