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=f200022b78b4f11895cb7e36e509230a1a90fa24;hp=3c048231b8febe0a04148e2e58768f63f88fcd09;hb=f47e98a599c18debf83ef98be469e3ae7c30e2f7;hpb=d996ee1179852f97d9fdccba87e7b4ee97df7040 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 3c04823..f200022 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,17 +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; -import net.pterodactylus.util.cache.CacheItem; -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; /** @@ -64,19 +55,8 @@ public class DefaultIdentity implements Identity { private final Map properties = Collections.synchronizedMap(new HashMap()); /** Cached trust. */ - private final WritableCache trustCache = new MemoryCache(new ValueRetriever() { - - @Override - @SuppressWarnings("synthetic-access") - public CacheItem retrieve(OwnIdentity ownIdentity) throws CacheException { - try { - return new DefaultCacheItem(webOfTrustConnector.getTrust(ownIdentity, DefaultIdentity.this)); - } catch (PluginException pe1) { - throw new CacheException("Could not retrieve trust for OwnIdentity: " + ownIdentity, pe1); - } - } - - }, new TimedMap>(60 * 60 * 1000)); + /* synchronize on itself. */ + private final Map trustCache = new HashMap(); /** * Creates a new identity. @@ -248,11 +228,8 @@ public class DefaultIdentity implements Identity { */ @Override public Trust getTrust(OwnIdentity ownIdentity) { - try { + synchronized (trustCache) { return trustCache.get(ownIdentity); - } catch (CacheException ce1) { - logger.log(Level.WARNING, "Could not get trust for OwnIdentity: " + ownIdentity, ce1); - return null; } } @@ -264,8 +241,10 @@ public class DefaultIdentity implements Identity { * @param trust * The trust received for this identity */ - void setTrustPrivate(OwnIdentity ownIdentity, Trust trust) { - trustCache.put(ownIdentity, trust); + public void setTrust(OwnIdentity ownIdentity, Trust trust) { + synchronized (trustCache) { + trustCache.put(ownIdentity, trust); + } } //