]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/AsynchronousTreeTestResultListener.java
Improve error logging and reporting
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / core / test / tree / AsynchronousTreeTestResultListener.java
index 0773e409ff3f9b08759f99c9c81e92d11fc9cc78..c22c1102972cc02be8edd9aa684a90fa783c1345 100644 (file)
@@ -19,10 +19,22 @@ public abstract class AsynchronousTreeTestResultListener implements
        private Vector<PartStruct> partStructs = new Vector<PartStruct>();\r
        private Thread thread;\r
 \r
+       private Boolean synchronous = false;\r
+       \r
+       protected AsynchronousTreeTestResultListener(){\r
+               this(false);\r
+       }\r
+\r
+       protected AsynchronousTreeTestResultListener(Boolean synchronousByDefault){\r
+               synchronous = synchronousByDefault;\r
+       }\r
+\r
        /** Starts the underlying thread. */\r
        public void init() {\r
-               thread = new Thread(this);\r
-               thread.start();\r
+               if (!synchronous) {\r
+                       thread = new Thread(this);\r
+                       thread.start();\r
+               }\r
        }\r
 \r
        /** Finish the remaining and destroy */\r
@@ -47,11 +59,16 @@ public abstract class AsynchronousTreeTestResultListener implements
        public final void resultPartAdded(TestResult testResult,\r
                        TestResultPart testResultPart) {\r
                TreeTestResult result = (TreeTestResult) testResult;\r
-               synchronized (partStructs) {\r
-                       partStructs.add(new PartStruct(result.getCurrentPath(),\r
-                                       (NumericTRId) result.getTestResultId(), testResultPart,\r
-                                       result));\r
-                       partStructs.notifyAll();\r
+               PartStruct partStruct = new PartStruct(result.getCurrentPath(),\r
+                               (NumericTRId) result.getTestResultId(), testResultPart, result);\r
+\r
+               if (!synchronous) {\r
+                       synchronized (partStructs) {\r
+                               partStructs.add(partStruct);\r
+                               partStructs.notifyAll();\r
+                       }\r
+               } else {\r
+                       resultPartAdded(partStruct);\r
                }\r
        }\r
 \r
@@ -109,4 +126,12 @@ public abstract class AsynchronousTreeTestResultListener implements
 \r
        }\r
 \r
+       public Boolean getSynchronous() {\r
+               return synchronous;\r
+       }\r
+\r
+       public void setSynchronous(Boolean synchronous) {\r
+               this.synchronous = synchronous;\r
+       }\r
+\r
 }\r