|
@@ -0,0 +1,63 @@
|
|
|
+package cn.nosum.chain.handler;
|
|
|
+
|
|
|
+import cn.nosum.chain.constants.ChainConstants;
|
|
|
+import cn.nosum.chain.context.ChainContext;
|
|
|
+import cn.nosum.support.annotation.ResponsibilityChainMethod;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Young
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ChainHandler {
|
|
|
+
|
|
|
+ @ResponsibilityChainMethod(groupName = ChainConstants.CHAIN_GROUP_NAME, order = 1, isReturn = true)
|
|
|
+ public boolean test1(ChainContext context) {
|
|
|
+ System.out.println("test1" + context.getName());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponsibilityChainMethod(groupName = ChainConstants.CHAIN_GROUP_NAME, order = 2, isReturn = true)
|
|
|
+ public boolean test2(ChainContext context) {
|
|
|
+ context.setExecuteNextNode(false);
|
|
|
+ System.out.println("test2" + context.getName());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试返回false的情况,中断执行链
|
|
|
+ */
|
|
|
+ @ResponsibilityChainMethod(groupName = ChainConstants.CHAIN_GROUP_NAME, order = 3, isReturn = true)
|
|
|
+ public boolean test3(ChainContext context) {
|
|
|
+ System.out.println("test3" + context.getName());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponsibilityChainMethod(groupName = ChainConstants.CHAIN_GROUP_NAME, order = 4, isReturn = true)
|
|
|
+ public boolean test4(ChainContext context) {
|
|
|
+ System.out.println("test4" + context.getName());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 没有放值的情况,默认返回true
|
|
|
+ */
|
|
|
+ @ResponsibilityChainMethod(groupName = ChainConstants.CHAIN_GROUP_NAME, order = 5)
|
|
|
+ public void test5(ChainContext context) {
|
|
|
+ System.out.println("test5" + context.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试是否执行下一个节点
|
|
|
+ */
|
|
|
+ @ResponsibilityChainMethod(groupName = ChainConstants.CHAIN_GROUP_NAME, order = 6)
|
|
|
+ public void test6(ChainContext context) {
|
|
|
+ context.setExecuteNextNode(false);
|
|
|
+ System.out.println("test6" + context.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponsibilityChainMethod(groupName = ChainConstants.CHAIN_GROUP_NAME, order = 7)
|
|
|
+ public void test7(ChainContext context) {
|
|
|
+ System.out.println("test7" + context.getName());
|
|
|
+ }
|
|
|
+}
|