/*
- * Sone - WebOfTrustUpdater.java - Copyright © 2012 David Roden
+ * Sone - WebOfTrustUpdater.java - Copyright © 2013 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
package net.pterodactylus.sone.core;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import net.pterodactylus.sone.freenet.wot.WebOfTrustException;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.service.AbstractService;
-import net.pterodactylus.util.validation.Validation;
+
+import com.google.inject.Inject;
/**
* Updates WebOfTrust identity data in a background thread because communicating
* @param webOfTrustConnector
* The web of trust connector
*/
+ @Inject
public WebOfTrustUpdater(WebOfTrustConnector webOfTrustConnector) {
super("Trust Updater");
this.webOfTrustConnector = webOfTrustConnector;
//
/**
- * Retrieves 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
- */
- public void getTrust(OwnIdentity truster, Identity trustee) {
- GetTrustJob getTrustJob = new GetTrustJob(truster, trustee);
- if (!updateJobs.contains(getTrustJob)) {
- logger.log(Level.FINER, "Adding Trust Update Job: " + getTrustJob);
- try {
- updateJobs.put(getTrustJob);
- } catch (InterruptedException ie1) {
- /* the queue is unbounded so it should never block. */
- }
- }
- }
-
- /**
* Updates the trust relation between the truster and the trustee. This
* method will return immediately and perform a trust update in the
* background.
*
* @return {@code true} if this job finished successfully, {@code false}
* otherwise
- *
* @see WebOfTrustUpdater#stop()
*/
@SuppressWarnings("synthetic-access")
}
/**
- * Update job that retrieves the trust relation between two identities.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
- private class GetTrustJob extends WebOfTrustTrustUpdateJob {
-
- /**
- * Creates a new trust update job.
- *
- * @param truster
- * The identity giving the trust
- * @param trustee
- * The identity receiving the trust
- */
- public GetTrustJob(OwnIdentity truster, Identity trustee) {
- super(truster, trustee);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- @SuppressWarnings("synthetic-access")
- public void run() {
- try {
- Trust trust = webOfTrustConnector.getTrust(truster, trustee);
- if (trustee instanceof DefaultIdentity) {
- ((DefaultIdentity) trustee).setTrust(truster, trust);
- }
- finish(true);
- } catch (PluginException pe1) {
- logger.log(Level.WARNING, "Could not get Trust value for " + truster + " -> " + trustee + "!", pe1);
- finish(false);
- }
- }
-
- }
-
- /**
* Base class for context updates of an {@link OwnIdentity}.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
@SuppressWarnings("synthetic-access")
public WebOfTrustContextUpdateJob(OwnIdentity ownIdentity, String context) {
- Validation.begin().isNotNull("OwnIdentity", ownIdentity).isNotNull("Context", context).check();
- this.ownIdentity = ownIdentity;
- this.context = context;
+ this.ownIdentity = checkNotNull(ownIdentity, "ownIdentity must not be null");
+ this.context = checkNotNull(context, "context must not be null");
}
//