wangwei il y a 5 ans
Parent
commit
8b54881c41

+ 2 - 1
src/main/java/cn/com/qmth/examcloud/commons/helpers/pipeline/NodeExecuter.java

@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.commons.helpers.pipeline;
 import java.util.List;
 
 import cn.com.qmth.examcloud.commons.helpers.KeyValuePair;
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
 
 /**
  * 节点执行器
@@ -29,6 +30,6 @@ public interface NodeExecuter<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {
 	 * @throws Exception
 	 */
 	void execute(KEYIN key, VALUEIN value, final List<KeyValuePair<KEYOUT, VALUEOUT>> outList,
-			Boolean removable, TaskContext context) throws Exception;
+			ObjectHolder<Boolean> removable, TaskContext context) throws Exception;
 
 }

+ 3 - 2
src/main/java/cn/com/qmth/examcloud/commons/helpers/pipeline/SimpleNode.java

@@ -10,6 +10,7 @@ import org.apache.logging.log4j.ThreadContext;
 import com.google.common.collect.Lists;
 
 import cn.com.qmth.examcloud.commons.helpers.KeyValuePair;
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.commons.util.ThreadLocalUtil;
@@ -126,7 +127,7 @@ public class SimpleNode<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
 			}
 			counter.incrementTotal();
 			List<KeyValuePair<KEYOUT, VALUEOUT>> outList = Lists.newLinkedList();
-			Boolean removable = true;
+			ObjectHolder<Boolean> removable = new ObjectHolder<Boolean>(true);
 			executer.execute(key, value, outList, removable, context);
 
 			if (null != outList && null != getLowerStorer()) {
@@ -135,7 +136,7 @@ public class SimpleNode<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
 				}
 			}
 
-			if (removable) {
+			if (removable.get()) {
 				if (null != key) {
 					getStorer().remove(key);
 				}

+ 3 - 2
src/test/java/cn/com/qmth/examcloud/test/pipeline/FileReaderExecuter.java

@@ -8,6 +8,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.RandomUtils;
 
 import cn.com.qmth.examcloud.commons.helpers.KeyValuePair;
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
 import cn.com.qmth.examcloud.commons.helpers.pipeline.NodeExecuter;
 import cn.com.qmth.examcloud.commons.helpers.pipeline.TaskContext;
 
@@ -15,7 +16,7 @@ public class FileReaderExecuter implements NodeExecuter<String, String, String,
 
 	@Override
 	public void execute(String key, String value, List<KeyValuePair<String, String>> outList,
-			Boolean removable, TaskContext context) throws Exception {
+			ObjectHolder<Boolean> removable, TaskContext context) throws Exception {
 
 		String path = (String) context.get("path");
 
@@ -26,7 +27,7 @@ public class FileReaderExecuter implements NodeExecuter<String, String, String,
 					e));
 		});
 
-		removable = true;
+		removable.set(false);
 		outList.clear();
 	}
 

+ 2 - 1
src/test/java/cn/com/qmth/examcloud/test/pipeline/PrintExecuter.java

@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.test.pipeline;
 import java.util.List;
 
 import cn.com.qmth.examcloud.commons.helpers.KeyValuePair;
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
 import cn.com.qmth.examcloud.commons.helpers.pipeline.NodeExecuter;
 import cn.com.qmth.examcloud.commons.helpers.pipeline.TaskContext;
 
@@ -10,7 +11,7 @@ public class PrintExecuter implements NodeExecuter<String, String, String, Strin
 
 	@Override
 	public void execute(String key, String value, List<KeyValuePair<String, String>> outList,
-			Boolean removable, TaskContext context) throws Exception {
+			ObjectHolder<Boolean> removable, TaskContext context) throws Exception {
 		System.out.println("Print: " + key + " -> " + value);
 	}