1 package org
.argeo
.slc
.core
.test
.tree
;
3 import java
.util
.Vector
;
5 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
6 import org
.argeo
.slc
.core
.test
.TestResult
;
7 import org
.argeo
.slc
.core
.test
.TestResultListener
;
8 import org
.argeo
.slc
.core
.test
.TestResultPart
;
11 * Abstract asynchronous implementation of a listener listening to a
12 * <code>TreeTestResult</code>.
14 * @deprecated listeners should be called synchronously
17 public abstract class AsynchronousTreeTestResultListener
implements
18 TestResultListener
, Runnable
{
19 private Vector
<PartStruct
> partStructs
= new Vector
<PartStruct
>();
20 private Thread thread
;
22 private Boolean synchronous
= true;
24 protected AsynchronousTreeTestResultListener() {
28 protected AsynchronousTreeTestResultListener(Boolean synchronousByDefault
) {
29 synchronous
= synchronousByDefault
;
32 /** Starts the underlying thread. */
35 thread
= new Thread(this);
40 /** Finish the remaining and destroy */
41 public void close(TestResult testResult
) {
42 // FIXME: make behavior more robust when multiple results are
43 // registering this listener.
44 synchronized (partStructs
) {
45 // TODO: put a timeout
46 while (partStructs
.size() != 0) {
48 partStructs
.wait(500);
49 } catch (InterruptedException e
) {
54 partStructs
.notifyAll();
56 postClose((TreeTestResult
) testResult
);
59 public final void resultPartAdded(TestResult testResult
,
60 TestResultPart testResultPart
) {
61 TreeTestResult result
= (TreeTestResult
) testResult
;
62 PartStruct partStruct
= new PartStruct(result
.getCurrentPath(), result
63 .getUuid(), testResultPart
, result
);
66 synchronized (partStructs
) {
67 partStructs
.add(partStruct
);
68 partStructs
.notifyAll();
71 resultPartAdded(partStruct
);
75 /** Called when a result part has been added. */
76 protected abstract void resultPartAdded(PartStruct partStruct
);
79 * Called at the end of close. Default implementation is empty. To be
82 protected void postClose(TreeTestResult testResult
) {
87 while (thread
!= null) {
88 synchronized (partStructs
) {
89 for (PartStruct partStruct
: partStructs
) {
90 resultPartAdded(partStruct
);
94 partStructs
.notifyAll();
95 while (partStructs
.size() == 0) {
98 } catch (InterruptedException e
) {
106 /** Structure used to pass tree specific information to subclasses. */
107 protected static class PartStruct
{
108 /** The tree path of this part. */
109 public final TreeSPath path
;
110 /** The test result id of the related test result */
111 public final String uuid
;
112 /** The part itself */
113 public final TestResultPart part
;
114 /** The tree test result itself. */
115 public final TreeTestResult result
;
118 public PartStruct(TreeSPath path
, String uuid
, TestResultPart part
,
119 TreeTestResult result
) {
124 this.result
= result
;
129 public Boolean
getSynchronous() {
133 public void setSynchronous(Boolean synchronous
) {
134 this.synchronous
= synchronous
;