X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Ftest%2Ftree%2FAsynchronousTreeTestResultListener.java;h=c22c1102972cc02be8edd9aa684a90fa783c1345;hb=b5c4e0c9c2fcf788a56d6ce72989fe15182e057d;hp=c3bc793ef5f357d03a16b821c1dd067f5163f83b;hpb=875f97b054c6e996fa2d03c299c83cc80d336b54;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/AsynchronousTreeTestResultListener.java b/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/AsynchronousTreeTestResultListener.java index c3bc793ef..c22c11029 100644 --- a/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/AsynchronousTreeTestResultListener.java +++ b/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/AsynchronousTreeTestResultListener.java @@ -19,14 +19,28 @@ public abstract class AsynchronousTreeTestResultListener implements private Vector partStructs = new Vector(); private Thread thread; + private Boolean synchronous = false; + + protected AsynchronousTreeTestResultListener(){ + this(false); + } + + protected AsynchronousTreeTestResultListener(Boolean synchronousByDefault){ + synchronous = synchronousByDefault; + } + /** Starts the underlying thread. */ public void init() { - thread = new Thread(this); - thread.start(); + if (!synchronous) { + thread = new Thread(this); + thread.start(); + } } /** Finish the remaining and destroy */ public void close(TestResult testResult) { + // FIXME: make behavior more robust when multiple results are + // registering this listener. synchronized (partStructs) { // TODO: put a timeout while (partStructs.size() != 0) { @@ -39,17 +53,22 @@ public abstract class AsynchronousTreeTestResultListener implements thread = null; partStructs.notifyAll(); } - postClose((TreeTestResult)testResult); + postClose((TreeTestResult) testResult); } public final void resultPartAdded(TestResult testResult, TestResultPart testResultPart) { TreeTestResult result = (TreeTestResult) testResult; - synchronized (partStructs) { - partStructs.add(new PartStruct(result.getCurrentPath(), - (NumericTRId) result.getTestResultId(), testResultPart, - result)); - partStructs.notifyAll(); + PartStruct partStruct = new PartStruct(result.getCurrentPath(), + (NumericTRId) result.getTestResultId(), testResultPart, result); + + if (!synchronous) { + synchronized (partStructs) { + partStructs.add(partStruct); + partStructs.notifyAll(); + } + } else { + resultPartAdded(partStruct); } } @@ -107,4 +126,12 @@ public abstract class AsynchronousTreeTestResultListener implements } + public Boolean getSynchronous() { + return synchronous; + } + + public void setSynchronous(Boolean synchronous) { + this.synchronous = synchronous; + } + }