stepchain框架有什么作用

本篇內(nèi)容主要講解“stepchain框架有什么作用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“stepchain框架有什么作用”吧!

網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)過程中,需要針對(duì)客戶的行業(yè)特點(diǎn)、產(chǎn)品特性、目標(biāo)受眾和市場情況進(jìn)行定位分析,以確定網(wǎng)站的風(fēng)格、色彩、版式、交互等方面的設(shè)計(jì)方向。創(chuàng)新互聯(lián)還需要根據(jù)客戶的需求進(jìn)行功能模塊的開發(fā)和設(shè)計(jì),包括內(nèi)容管理、前臺(tái)展示、用戶權(quán)限管理、數(shù)據(jù)統(tǒng)計(jì)和安全保護(hù)等功能。

stepchain 通用業(yè)務(wù)流程流水線處理框架。

類似于Commons Chain和Commons Pipeline這樣的Java Pipeline Step Chain用于組織復(fù)雜處理流程執(zhí)行的流行技術(shù)。

Feature:
1、支持通用業(yè)務(wù)job、services子流程無限制拆分。
2、支持業(yè)務(wù)子流程串行化、業(yè)務(wù)子流程并行化,可配置化。
3、支持Config業(yè)務(wù)子流程開啟或禁用、配置串行或并行以及并行數(shù)的統(tǒng)一配置。
4、支持業(yè)務(wù)流程以及子流程任意無限嵌套。
5、支持配置中心、緩存、統(tǒng)一數(shù)據(jù)接口、redis、Es、日志Trace等。
6、支持并行分支,支持條件分支if/else、switch、loop子流程.
7、支持Processor定時(shí)調(diào)度FixedRate、FixedDelay。
備注:只開源了通用部分(不影響使用),去除了有關(guān)框架組件包括:配置中心、緩存中心、數(shù)據(jù)接口以及業(yè)務(wù)相關(guān)DataMiddle等部分API。
Maven Dependency:
Maven(Not Use Spring Boot):
<dependency>
 <groupId>com.github.zengfr.project</groupId>
 <artifactId>stepchain</artifactId>
 <version>0.0.7</version>
<dependency>
Maven(Use Spring Boot):
<dependency>
 <groupId>com.github.zengfr.project</groupId>
 <artifactId>stepchain-spring-boot-starter</artifactId>
 <version>0.0.7</version>
<dependency>
Gradle:
compile group: 'com.github.zengfr.project', name: 'stepchain', version: '0.0.7'
compile group: 'com.github.zengfr.project', name: 'stepchain-spring-boot-starter', version: '0.0.7'

stepchain框架有什么作用

1、StepChain 的中心思想是什么?如何做到通用的?
答: 
1.1、任何業(yè)務(wù)邏輯處理抽象成1\input輸入 2\ processor處理器 3\output輸出.中間過程結(jié)果產(chǎn)生和組合成dataMiddle。
1.2、任何業(yè)務(wù)邏輯處理使用多個(gè)processor組合執(zhí)行。

2、StepChain 如何并行和串行執(zhí)行多個(gè)processor?
答: 
串行step=pipeline.createStep();step.put(processors);//processors串行執(zhí)行.
并行step=pipeline.createStep(4);step.put(processors);//processors同時(shí)4個(gè)并行執(zhí)行.

3、Stepchain 如何創(chuàng)建processor?
  3.1、實(shí)現(xiàn) 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 如何復(fù)用和組合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 如何按條件復(fù)用和組合processor?
答: 
case1、已有trueProcessor\falseProcessor2個(gè) 創(chuàng)建 validator 則按條件執(zhí)行2則之1.
IConditionSelectorProcessor<String, Boolean, String> p3 = pipeline.createConditionValidatorProcessor(validator, trueProcessor, falseProcessor);

case2、已有processor 創(chuàng)建 validator 創(chuàng)建循環(huán)執(zhí)行體,validator 返回false時(shí)終止執(zhí)行。
IConditionLoopProcessor<String, String> p2 = pipeline.createConditionLoopProcessor(validator, processor);

case3、已有processor創(chuàng)建 switch 邏輯,根據(jù)selector返回的key執(zhí)行某1分支branchProcessor如果返回的key不在分支中 則執(zhí)行默認(rèn)key對(duì)應(yīng)的分支branchProcessor。
IConditionSelectorProcessor<String, String, String> p1 = pipeline.createConditionSelectorProcessor(selector);
p1.setBranch(S key, IProcessor<I, O> processor);
p1setDefaultBranch(S key);

case4、已有processor創(chuàng)建 if/else if/else  邏輯,根據(jù)validator返回的結(jié)果與result對(duì)比一致則執(zhí)行分支branchProcessor,如果沒有返回一致的 則執(zhí)行默認(rèn)分支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);
}
public interface IStep<I> extends IStepProcessor<I> {
	void put(IStepProcessor<I> processor);

	void put(IStepProcessor<I>... processorArray);

	void put(Collection<StepProcessor<I>> processors);

	void put(IProcessor<I, Boolean> processor);

	void put(IProcessor<I, Boolean>... processorArray);

	void put(IChain<I, Boolean> chain);

	void put(IChain<I, Boolean>... processorArray);

	void put(Function<I, Boolean> func);

	void put(Function<I, Boolean>... processorArray);
}
public interface IChain<A, B> extends IProcessor<A, B> {
	<C> IChain<A, C> next(IProcessor<B, C> process);

	<C> IChain<A, C> next(Function<B, C> func);
}
public interface IChainBuilder {
	<A, B> IChain<A, B> createChain(Function<A, B> func);

	<A, B> IChain<A, B> createChain(IProcessor<A, B> processor);

	<A, B, C> IChain<A, C> createChain(IProcessor<A, B> processor1, IProcessor<B, C> processor2);
}
public interface IStepBuilder {
	<T> IStep<T> createStep();

	<T> IStep<T> createStep(int parallelCount);

	<T> IStep<T> createStep(String parallelCountConfigName);
}

StepChainSpringBootTest.java

PipelineTest.java 
Demo&Test you can use AbstractProcessor AbstractStepProcessor

import com.github.zengfr.project.stepchain
abstract class AbstractProcessor<I, O> implements Processor<I, O>{}
abstract class AbstractStepProcessor<A> extends AbstractProcessor<A, Boolean> implements StepProcessor<A>{}
import com.github.zengfr.project.stepchain.Chain;
import com.github.zengfr.project.stepchain.Pipeline;
import com.github.zengfr.project.stepchain.Step;
import com.github.zengfr.project.stepchain.context.ContextBuilder;
import com.github.zengfr.project.stepchain.context.UnaryContext;
import com.github.zengfr.project.stepchain.test.context.SetProductContext;
import com.github.zengfr.project.stepchain.test.context.SetProductDataMiddle;
import com.github.zengfr.project.stepchain.test.processor.DiscountProcessor;
import com.github.zengfr.project.stepchain.test.processor.FeeProcessor;
import com.github.zengfr.project.stepchain.test.processor.IncreaseProcessor;
import com.github.zengfr.project.stepchain.test.processor.InitProcessor;
import com.github.zengfr.project.stepchain.test.processor.TaxProcessor;

public class PipelineTest {
public static void testPipeline(IPipeline pipeline) throws Exception {
    //Demo精簡版 只開源了通用部分(不影響使用)
	SetProductRequest req = new SetProductRequest();
	SetProductResponse resp = new SetProductResponse();
	SetProductDataMiddle middle = new SetProductDataMiddle();

	SetProductContext context = new SetProductContext(req, middle, resp);
	IStep<SetProductContext> step = pipeline.createStep();
	step.put(new InitProcessor());
	step.put(new TaxProcessor());
	step.put(new FeeProcessor());
	step.put(new IncreaseProcessor());
	step.put(new DiscountProcessor());
	step.put((c) -> {
		c.middle.Price += 10;
		return true;
	});
	step.process(context);
	System.out.println(context.middle.Price);
	}

	public static void testPipeline2(IPipeline pipeline) throws Exception {
	Function<UnaryContext<Integer>, Boolean> func = (context) -> {
			if (context.context == null)
				context.context = 1;
			context.context += 1;
			return true;

		};
		Function<UnaryContext<Integer>, String> func3 = (context) -> {
			if (context.context == null)
				context.context = 1;
			context.context += 1;
			return JSON.toJSONString(context.context);

		};
		UnaryContext<Integer> context = pipeline.createContext(12345678);
		IStep<UnaryContext<Integer>> step = pipeline.createStep();
		IStep<UnaryContext<Integer>> step2 = pipeline.createStep();
		IChain<UnaryContext<Integer>, Boolean> c2 = pipeline.createChain(func);
		 
		IChain<UnaryContext<Integer>, String> c3 = pipeline.createChain(func3);
		Function<String, Integer> func4 = null;
		Function<Integer, String> func5 = null;
		Function<String, Boolean> func6 = null;
		IChain<String,Integer > c4 = pipeline.createChain(func4);
		IChain<Integer, String> c5 = pipeline.createChain(func5);
		IChain<String, Boolean> c6 = pipeline.createChain(func6);
		IChain<UnaryContext<Integer>, Boolean> c7 = c3.next(c4).next(c5).next(c6);
		
		step2.put(c2);
		step2.put(step);
		step2.put(func);
		//step2.put(c7);
		
		step2.process(context);
		System.out.println(context.context);
	}
	public static void testPipeline3(IPipeline pipeline) throws Exception {
		IProcessor<String, String> selector = null;
		IProcessor<String, Boolean> validator = null;

		IProcessor<String, String> processor = null;
		IProcessor<String, String> first = null;
		IProcessor<String, String> second = null;

		IConditionSelectorProcessor<String, Boolean, String> p3 = pipeline.createConditionValidatorProcessor(validator, first, second);
		IConditionLoopProcessor<String, String> p2 = pipeline.createConditionLoopProcessor(validator, processor);

		IConditionSelectorProcessor<String, String, String> p1 = pipeline.createConditionSelectorProcessor(selector);
	}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = StepChainTestApplication.class)
public class StepChainSpringBootTest {
	@Autowired
	protected IPipeline pipeline;
	@Test
	public void testPipeline() throws Exception {
	PipelineTest.testPipeline(pipeline);
	}
	@Test
	public void testPipeline2() throws Exception {
	PipelineTest.testPipeline2(pipeline);
	}

stepchain框架有什么作用stepchain框架有什么作用  stepchain框架有什么作用

到此,相信大家對(duì)“stepchain框架有什么作用”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

文章標(biāo)題:stepchain框架有什么作用
當(dāng)前路徑:http://muchs.cn/article14/johcge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、服務(wù)器托管、面包屑導(dǎo)航、網(wǎng)頁設(shè)計(jì)公司、Google網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)