Whitespace and formatting fixes.
[jFCPlib.git] / src / net / pterodactylus / fcp / highlevel / HighLevelCallback.java
index ac448a6..7dc55df 100644 (file)
@@ -30,7 +30,6 @@ import java.util.List;
  * @param <R>
  *            The type of the high-level operation result
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
- * @version $Id$
  */
 public class HighLevelCallback<R extends HighLevelResult> {
 
@@ -84,15 +83,17 @@ public class HighLevelCallback<R extends HighLevelResult> {
        }
 
        /**
-        * Notifies all listeners that the result of the operation is now known.
+        * Notifies all listeners that the result of the operation is now known. As
+        * soon as a listener was notified it will be removed from the list of
+        * listeners!
         * 
         * @see HighLevelCallbackListener#gotResult(HighLevelCallback)
         */
        private synchronized void fireGotResult() {
                for (HighLevelCallbackListener<R> highLevelCallbackListener: highLevelCallbackListeners) {
-                       highLevelCallbackListeners.remove(highLevelCallbackListener);
                        highLevelCallbackListener.gotResult(this);
                }
+               highLevelCallbackListeners.clear();
        }
 
        /**
@@ -133,7 +134,7 @@ public class HighLevelCallback<R extends HighLevelResult> {
         */
        public R getResult(long waitTime) throws InterruptedException {
                synchronized (syncObject) {
-                       if (!resultComplete) {
+                       while (!resultComplete) {
                                syncObject.wait(waitTime);
                        }
                        return result;
@@ -161,7 +162,7 @@ public class HighLevelCallback<R extends HighLevelResult> {
                                return;
                        }
                        resultComplete = true;
-                       syncObject.notify();
+                       syncObject.notifyAll();
                }
                fireGotResult();
        }