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=3ac38de5dd44953c602efb9a06bbcecd9a13b4a4;hpb=5469796ed10ab0ddb8f7bf1cb7ba663676b7d73d;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 3ac38de5d..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() { + 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,22 +53,36 @@ public abstract class AsynchronousTreeTestResultListener implements thread = null; partStructs.notifyAll(); } + 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); } } /** Called when a result part has been added. */ protected abstract void resultPartAdded(PartStruct partStruct); + /** + * Called at the end of close. Default implementation is empty. To be + * overridden. + */ + protected void postClose(TreeTestResult testResult) { + + } + public void run() { while (thread != null) { synchronized (partStructs) { @@ -98,4 +126,12 @@ public abstract class AsynchronousTreeTestResultListener implements } + public Boolean getSynchronous() { + return synchronous; + } + + public void setSynchronous(Boolean synchronous) { + this.synchronous = synchronous; + } + }