X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FDefaultIdentity.java;h=6a16cc5dc4e2a94d12104ee25b55e0ad3da5c03f;hp=f00fa4ed40535c64f3f30184b06abd8fba6e6679;hb=c9e306ac8e3ada846e87a0cc256a20fc148f381c;hpb=c7d7acf5f7325f4b8ffa8c564275782601a79059 diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java index f00fa4e..6a16cc5 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import net.pterodactylus.sone.freenet.plugin.PluginException; import net.pterodactylus.util.cache.CacheException; @@ -31,6 +33,7 @@ import net.pterodactylus.util.cache.MemoryCache; import net.pterodactylus.util.cache.ValueRetriever; import net.pterodactylus.util.cache.WritableCache; import net.pterodactylus.util.collection.TimedMap; +import net.pterodactylus.util.logging.Logging; /** * A Web of Trust identity. @@ -39,6 +42,9 @@ import net.pterodactylus.util.collection.TimedMap; */ public class DefaultIdentity implements Identity { + /** The logger. */ + private static final Logger logger = Logging.getLogger(DefaultIdentity.class); + /** The web of trust connector. */ private final WebOfTrustConnector webOfTrustConnector; @@ -58,6 +64,7 @@ public class DefaultIdentity implements Identity { private final Map properties = Collections.synchronizedMap(new HashMap()); /** Cached trust. */ + /* synchronize on itself. */ private final WritableCache trustCache = new MemoryCache(new ValueRetriever() { @Override @@ -70,7 +77,7 @@ public class DefaultIdentity implements Identity { } } - }, new TimedMap>(60000)); + }, new TimedMap>(60 * 60 * 1000)); /** * Creates a new identity. @@ -241,11 +248,14 @@ public class DefaultIdentity implements Identity { * {@inheritDoc} */ @Override - public Trust getTrust(OwnIdentity ownIdentity) throws WebOfTrustException { + public Trust getTrust(OwnIdentity ownIdentity) { try { - return trustCache.get(ownIdentity); + synchronized (trustCache) { + return trustCache.get(ownIdentity); + } } catch (CacheException ce1) { - throw new WebOfTrustException("Could not get trust for OwnIdentity: " + ownIdentity, ce1); + logger.log(Level.WARNING, String.format("Could not get trust for OwnIdentity: %s", ownIdentity), ce1); + return null; } } @@ -258,7 +268,9 @@ public class DefaultIdentity implements Identity { * The trust received for this identity */ void setTrustPrivate(OwnIdentity ownIdentity, Trust trust) { - trustCache.put(ownIdentity, trust); + synchronized (trustCache) { + trustCache.put(ownIdentity, trust); + } } //