X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FHighLevelCallback.java;h=7dc55dfc90aa753f80f5567d176fd3c82ac39227;hb=15f2240c29062e572f512e703a06e414bb3d5d37;hp=27fc6bb37a60263b4a3216a9deb08877fd57ce11;hpb=60144e6607f54352fdd28869e4af8b567c4e69da;p=jFCPlib.git diff --git a/src/net/pterodactylus/fcp/highlevel/HighLevelCallback.java b/src/net/pterodactylus/fcp/highlevel/HighLevelCallback.java index 27fc6bb..7dc55df 100644 --- a/src/net/pterodactylus/fcp/highlevel/HighLevelCallback.java +++ b/src/net/pterodactylus/fcp/highlevel/HighLevelCallback.java @@ -30,18 +30,17 @@ import java.util.List; * @param * The type of the high-level operation result * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - * @version $Id$ */ public class HighLevelCallback { /** Object used for synchronization. */ - private final Object syncObject = new Object(); + protected final Object syncObject = new Object(); /** The list of callback listeners. */ private final List> highLevelCallbackListeners = Collections.synchronizedList(new ArrayList>()); /** Whether the result is complete. */ - private boolean resultComplete = false; + protected boolean resultComplete = false; /** The result of the operation. */ private R result = null; @@ -84,15 +83,17 @@ public class HighLevelCallback { } /** - * 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 highLevelCallbackListener: highLevelCallbackListeners) { - highLevelCallbackListeners.remove(highLevelCallbackListener); highLevelCallbackListener.gotResult(this); } + highLevelCallbackListeners.clear(); } /** @@ -133,7 +134,7 @@ public class HighLevelCallback { */ 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 { return; } resultComplete = true; - syncObject.notify(); + syncObject.notifyAll(); } fireGotResult(); }