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=e155d7cad2660518f13055ca96f8d0674f39427f;hp=dcafb188becf9a5083d3fafc45c63c74e712e2d5;hb=a47643aed43d118ca68044f95451bb5374cdb332;hpb=0bfd860518040f5d55d06f740f20e5d2ba44439a 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 dcafb18..e155d7c 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java @@ -1,5 +1,5 @@ /* - * Sone - DefaultIdentity.java - Copyright © 2010 David Roden + * Sone - DefaultIdentity.java - Copyright © 2010–2012 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 @@ -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; @@ -30,6 +32,8 @@ import net.pterodactylus.util.cache.DefaultCacheItem; 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. @@ -38,6 +42,9 @@ import net.pterodactylus.util.cache.WritableCache; */ 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; @@ -57,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 @@ -69,7 +77,7 @@ public class DefaultIdentity implements Identity { } } - }); + }, new TimedMap>(60 * 60 * 1000)); /** * Creates a new identity. @@ -240,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, "Could not get trust for OwnIdentity: " + ownIdentity, ce1); + return null; } } @@ -257,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); + } } //