Fix timeout.
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / WebOfTrustConnector.java
index 8dc8840..7127e8f 100644 (file)
@@ -315,10 +315,15 @@ public class WebOfTrustConnector implements ConnectorListener {
                synchronized (reply) {
                        pluginConnector.sendRequest(WOT_PLUGIN_NAME, PLUGIN_CONNECTION_IDENTIFIER, fields, data);
                        try {
-                               reply.wait(60000);
-                               throw new PluginException("Timeout waiting for " + targetMessages[0] + "!");
+                               long now = System.currentTimeMillis();
+                               while ((reply.getFields() == null) && ((System.currentTimeMillis() - now) < 60000)) {
+                                       reply.wait(60000 - (System.currentTimeMillis() - now));
+                               }
+                               if (reply.getFields() == null) {
+                                       throw new PluginException("Timeout waiting for " + targetMessages[0] + "!");
+                               }
                        } catch (InterruptedException ie1) {
-                               logger.log(Level.WARNING, "Got interrupted while waiting for reply on GetOwnIdentities.", ie1);
+                               logger.log(Level.WARNING, "Got interrupted while waiting for reply on " + targetMessages[0] + ".", ie1);
                        }
                }
                for (String targetMessage : targetMessages) {
@@ -341,6 +346,7 @@ public class WebOfTrustConnector implements ConnectorListener {
        @Override
        public void receivedReply(PluginConnector pluginConnector, SimpleFieldSet fields, Bucket data) {
                String messageName = fields.get("Message");
+               logger.log(Level.FINEST, "Received Reply from Plugin: " + messageName);
                Reply reply = replies.remove(messageName);
                if (reply == null) {
                        logger.log(Level.FINE, "Not waiting for a ā€œ%sā€ message.", messageName);