Only allow a single trust update for any given identity pair.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 5 Sep 2012 10:27:01 +0000 (12:27 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 5 Sep 2012 10:27:01 +0000 (12:27 +0200)
src/main/java/net/pterodactylus/sone/core/TrustUpdater.java

index 91e1783..be6f39c 100644 (file)
@@ -105,7 +105,16 @@ public class TrustUpdater extends AbstractService {
         *            The comment of the trust relation
         */
        public void setTrust(OwnIdentity truster, Identity trustee, Integer score, String comment) {
-               updateJobs.add(new SetTrustJob(truster, trustee, score, 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. */
+               }
        }
 
        //