X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FWebOfTrustConnector.java;h=5cacb68636dc64f239a9c7b0052998767755d921;hp=b4ea53de1094d2d3bc81cf3f05c9ce9bd1bd7e7b;hb=c9e306ac8e3ada846e87a0cc256a20fc148f381c;hpb=dbb47149d5e2c1e67ec9889587ff24dd7c622862 diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java index b4ea53d..5cacb68 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java @@ -70,6 +70,16 @@ public class WebOfTrustConnector implements ConnectorListener { // /** + * Stops the web of trust connector. + */ + public void stop() { + pluginConnector.removeConnectorListener(WOT_PLUGIN_NAME, PLUGIN_CONNECTION_IDENTIFIER, this); + synchronized (reply) { + reply.notifyAll(); + } + } + + /** * Loads all own identities from the Web of Trust plugin. * * @return All own identity @@ -77,7 +87,6 @@ public class WebOfTrustConnector implements ConnectorListener { * if the own identities can not be loaded */ public Set loadAllOwnIdentities() throws WebOfTrustException { - @SuppressWarnings("hiding") Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetOwnIdentities").get()); SimpleFieldSet fields = reply.getFields(); int ownIdentityCounter = -1; @@ -125,7 +134,6 @@ public class WebOfTrustConnector implements ConnectorListener { * if an error occured talking to the Web of Trust plugin */ public Set loadTrustedIdentities(OwnIdentity ownIdentity, String context) throws PluginException { - @SuppressWarnings("hiding") Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("TreeOwner", ownIdentity.getId()).put("Selection", "+").put("Context", (context == null) ? "" : context).get()); SimpleFieldSet fields = reply.getFields(); Set identities = new HashSet(); @@ -185,7 +193,6 @@ public class WebOfTrustConnector implements ConnectorListener { * if an error occured talking to the Web of Trust plugin */ public String getProperty(Identity identity, String name) throws PluginException { - @SuppressWarnings("hiding") Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetProperty").put("Identity", identity.getId()).put("Property", name).get()); return reply.getFields().get("Property"); } @@ -375,16 +382,16 @@ public class WebOfTrustConnector implements ConnectorListener { */ private synchronized Reply performRequest(SimpleFieldSet fields, Bucket data) throws PluginException { reply = new Reply(); - logger.log(Level.FINE, "Sending FCP Request: " + fields.get("Message")); + logger.log(Level.FINE, String.format("Sending FCP Request: %s", fields.get("Message"))); synchronized (reply) { pluginConnector.sendRequest(WOT_PLUGIN_NAME, PLUGIN_CONNECTION_IDENTIFIER, fields, data); try { reply.wait(); } catch (InterruptedException ie1) { - logger.log(Level.WARNING, "Got interrupted while waiting for reply on " + fields.get("Message") + ".", ie1); + logger.log(Level.WARNING, String.format("Got interrupted while waiting for reply on %s.", fields.get("Message")), ie1); } } - logger.log(Level.FINEST, "Received FCP Response for %s: %s", new Object[] { fields.get("Message"), (reply.getFields() != null) ? reply.getFields().get("Message") : null }); + logger.log(Level.FINEST, String.format("Received FCP Response for %s: %s", fields.get("Message"), (reply.getFields() != null) ? reply.getFields().get("Message") : null)); if ((reply.getFields() == null) || "Error".equals(reply.getFields().get("Message"))) { throw new PluginException("Could not perform request for " + fields.get("Message")); } @@ -399,9 +406,9 @@ public class WebOfTrustConnector implements ConnectorListener { * {@inheritDoc} */ @Override - public void receivedReply(@SuppressWarnings("hiding") PluginConnector pluginConnector, SimpleFieldSet fields, Bucket data) { + public void receivedReply(PluginConnector pluginConnector, SimpleFieldSet fields, Bucket data) { String messageName = fields.get("Message"); - logger.log(Level.FINEST, "Received Reply from Plugin: " + messageName); + logger.log(Level.FINEST, String.format("Received Reply from Plugin: %s", messageName)); synchronized (reply) { reply.setFields(fields); reply.setData(data);