X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FWebOfTrustUpdaterImpl.java;h=da27152782f655d6aa8bbeaaaa46e6a2cd885776;hp=05d940f6337d7eb1a39472330b95a62916be9a5e;hb=faf66247a34f64946990a985d2ea3003465969cb;hpb=3d6cffe82270a1faacf1f0d39c34b11ab316e0db diff --git a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java index 05d940f..da27152 100644 --- a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java @@ -1,5 +1,5 @@ /* - * Sone - WebOfTrustUpdaterImpl.java - Copyright © 2013–2016 David Roden + * Sone - WebOfTrustUpdaterImpl.java - Copyright © 2013–2020 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,11 +26,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.sone.freenet.plugin.PluginException; -import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.sone.freenet.wot.OwnIdentity; -import net.pterodactylus.sone.freenet.wot.Trust; import net.pterodactylus.sone.freenet.wot.WebOfTrustConnector; -import net.pterodactylus.sone.freenet.wot.WebOfTrustException; import net.pterodactylus.util.service.AbstractService; import com.google.common.annotations.VisibleForTesting; @@ -40,8 +37,6 @@ import com.google.inject.Singleton; /** * Updates WebOfTrust identity data in a background thread because communicating * with the WebOfTrust plugin can potentially last quite long. - * - * @author David ‘Bombe’ Roden */ @Singleton public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrustUpdater { @@ -57,7 +52,7 @@ public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrust private final WebOfTrustConnector webOfTrustConnector; /** The queue for jobs. */ - private final BlockingQueue updateJobs = new LinkedBlockingQueue(); + private final BlockingQueue updateJobs = new LinkedBlockingQueue<>(); /** * Creates a new trust updater. @@ -76,34 +71,6 @@ public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrust // /** - * Updates the trust relation between the truster and the trustee. This method - * will return immediately and perform a trust update in the background. - * - * @param truster - * The identity giving the trust - * @param trustee - * The identity receiving the trust - * @param score - * The new level of trust (from -100 to 100, may be {@code null} to remove - * the trust completely) - * @param comment - * The comment of the trust relation - */ - @Override - public void setTrust(OwnIdentity truster, Identity trustee, Integer score, String comment) { - SetTrustJob setTrustJob = new SetTrustJob(truster, trustee, score, comment); - if (updateJobs.contains(setTrustJob)) { - updateJobs.remove(setTrustJob); - } - logger.log(Level.FINER, "Adding Trust Update Job: " + setTrustJob); - try { - updateJobs.put(setTrustJob); - } catch (InterruptedException e) { - /* the queue is unbounded so it should never block. */ - } - } - - /** * Adds the given context to the given own identity, waiting for completion of * the operation. * @@ -229,8 +196,6 @@ public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrust /** * Base class for WebOfTrust update jobs. - * - * @author David ‘Bombe’ Roden */ @VisibleForTesting class WebOfTrustUpdateJob implements Runnable { @@ -301,96 +266,7 @@ public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrust } /** - * Update job that sets the trust relation between two identities. - * - * @author David ‘Bombe’ Roden - */ - @VisibleForTesting - class SetTrustJob extends WebOfTrustUpdateJob { - - /** The identity giving the trust. */ - private final OwnIdentity truster; - - /** The identity receiving the trust. */ - private final Identity trustee; - - /** The score of the relation. */ - private final Integer score; - - /** The comment of the relation. */ - private final String comment; - - /** - * Creates a new set trust job. - * - * @param truster - * The identity giving the trust - * @param trustee - * The identity receiving the trust - * @param score - * The score of the trust (from -100 to 100, may be {@code null} to remote - * the trust relation completely) - * @param comment - * The comment of the trust relation - */ - public SetTrustJob(OwnIdentity truster, Identity trustee, Integer score, String comment) { - this.truster = checkNotNull(truster, "truster must not be null"); - this.trustee = checkNotNull(trustee, "trustee must not be null"); - this.score = score; - this.comment = comment; - } - - /** {@inheritDoc} */ - @Override - @SuppressWarnings("synthetic-access") - public void run() { - try { - if (score != null) { - webOfTrustConnector.setTrust(truster, trustee, score, comment); - trustee.setTrust(truster, new Trust(score, null, 0)); - } else { - webOfTrustConnector.removeTrust(truster, trustee); - trustee.removeTrust(truster); - } - finish(true); - } catch (WebOfTrustException wote1) { - logger.log(Level.WARNING, "Could not set Trust value for " + truster + " -> " + trustee + " to " + score + " (" + comment + ")!", wote1); - finish(false); - } - } - - // - // OBJECT METHODS - // - - /** {@inheritDoc} */ - @Override - public boolean equals(Object object) { - if ((object == null) || !object.getClass().equals(getClass())) { - return false; - } - SetTrustJob updateJob = (SetTrustJob) object; - return updateJob.truster.equals(truster) && updateJob.trustee.equals(trustee); - } - - /** {@inheritDoc} */ - @Override - public int hashCode() { - return getClass().hashCode() ^ truster.hashCode() ^ trustee.hashCode(); - } - - /** {@inheritDoc} */ - @Override - public String toString() { - return String.format("%s[truster=%s,trustee=%s]", getClass().getSimpleName(), truster.getId(), trustee.getId()); - } - - } - - /** * Base class for context updates of an {@link OwnIdentity}. - * - * @author David ‘Bombe’ Roden */ @VisibleForTesting class WebOfTrustContextUpdateJob extends WebOfTrustUpdateJob { @@ -445,8 +321,6 @@ public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrust /** * Job that adds a context to an {@link OwnIdentity}. - * - * @author David ‘Bombe’ Roden */ @VisibleForTesting class AddContextJob extends WebOfTrustContextUpdateJob { @@ -481,8 +355,6 @@ public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrust /** * Job that removes a context from an {@link OwnIdentity}. - * - * @author David ‘Bombe’ Roden */ @VisibleForTesting class RemoveContextJob extends WebOfTrustContextUpdateJob { @@ -517,8 +389,6 @@ public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrust /** * WebOfTrust update job that sets a property on an {@link OwnIdentity}. - * - * @author David ‘Bombe’ Roden */ @VisibleForTesting class SetPropertyJob extends WebOfTrustUpdateJob {