X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FHighLevelClient.java;h=5e1348729835f1b3eb26ad62fcb339f0b775ac05;hb=2ec849beb21de582bf5525e6a610d3896d5e7b2d;hp=14be335a68d4b60b4af98c4d72d3408df80cb524;hpb=60144e6607f54352fdd28869e4af8b567c4e69da;p=jFCPlib.git
diff --git a/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java b/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java
index 14be335..5e13487 100644
--- a/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java
+++ b/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java
@@ -25,6 +25,7 @@ import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import net.pterodactylus.fcp.AllData;
import net.pterodactylus.fcp.ClientHello;
@@ -253,10 +254,69 @@ public class HighLevelClient {
HighLevelClientFcpListener() {
}
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Searches all callback collections for a callback with the given
+ * identifier and cancels it.
+ *
+ * @param identifier
+ * The identifier to search for, or null
to
+ * cancel all pending requests
+ */
+ @SuppressWarnings("synthetic-access")
+ private void cancelIdentifier(String identifier) {
+ synchronized (syncObject) {
+ if (connectCallback != null) {
+ connectCallback.getIntermediaryResult().setFailed(true);
+ connectCallback.setDone();
+ connectCallback = null;
+ }
+ }
+ if (identifier == null) {
+ /* key generation callbacks */
+ for (Entry> keyGenerationEntry: keyGenerationCallbacks.entrySet()) {
+ keyGenerationEntry.getValue().getIntermediaryResult().setFailed(true);
+ keyGenerationEntry.getValue().setDone();
+ }
+ keyGenerationCallbacks.clear();
+ /* peer list callbacks. */
+ for (Entry> peerListEntry: peerListCallbacks.entrySet()) {
+ peerListEntry.getValue().getIntermediaryResult().setFailed(true);
+ peerListEntry.getValue().setDone();
+ }
+ peerListCallbacks.clear();
+ } else {
+ HighLevelCallback keyGenerationCallback = keyGenerationCallbacks.remove(identifier);
+ if (keyGenerationCallback != null) {
+ keyGenerationCallback.getIntermediaryResult().setFailed(true);
+ keyGenerationCallback.setDone();
+ return;
+ }
+ HighLevelCallback peerListCallback = peerListCallbacks.remove(identifier);
+ if (peerListCallback != null) {
+ peerListCallback.getIntermediaryResult().setFailed(true);
+ peerListCallback.setDone();
+ return;
+ }
+ }
+ }
+
+ //
+ // INTERFACE FcpListener
+ //
+
/**
* @see net.pterodactylus.fcp.FcpListener#connectionClosed(net.pterodactylus.fcp.FcpConnection)
*/
+ @SuppressWarnings("synthetic-access")
public void connectionClosed(FcpConnection fcpConnection) {
+ if (fcpConnection != HighLevelClient.this.fcpConnection) {
+ return;
+ }
+ cancelIdentifier(null);
}
/**
@@ -455,19 +515,7 @@ public class HighLevelClient {
if (identifier == null) {
return;
}
- /* now check all callbacks. */
- synchronized (syncObject) {
- if (connectCallback != null) {
- connectCallback.getIntermediaryResult().setFailed(true);
- connectCallback.setDone();
- connectCallback = null;
- }
- }
- HighLevelCallback keyGenerationCallback = keyGenerationCallbacks.remove(identifier);
- if (keyGenerationCallback != null) {
- keyGenerationCallback.getIntermediaryResult().setFailed(true);
- keyGenerationCallback.setDone();
- }
+ cancelIdentifier(identifier);
}
/**