Fix ALL the logging!
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / DefaultIdentity.java
index 3f4e66a..6a16cc5 100644 (file)
@@ -64,6 +64,7 @@ public class DefaultIdentity implements Identity {
        private final Map<String, String> properties = Collections.synchronizedMap(new HashMap<String, String>());
 
        /** Cached trust. */
+       /* synchronize on itself. */
        private final WritableCache<OwnIdentity, Trust> trustCache = new MemoryCache<OwnIdentity, Trust>(new ValueRetriever<OwnIdentity, Trust>() {
 
                @Override
@@ -76,7 +77,7 @@ public class DefaultIdentity implements Identity {
                        }
                }
 
-       }, new TimedMap<OwnIdentity, CacheItem<Trust>>(60000));
+       }, new TimedMap<OwnIdentity, CacheItem<Trust>>(60 * 60 * 1000));
 
        /**
         * Creates a new identity.
@@ -249,9 +250,11 @@ public class DefaultIdentity implements Identity {
        @Override
        public Trust getTrust(OwnIdentity ownIdentity) {
                try {
-                       return trustCache.get(ownIdentity);
+                       synchronized (trustCache) {
+                               return trustCache.get(ownIdentity);
+                       }
                } catch (CacheException ce1) {
-                       logger.log(Level.WARNING, "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;
                }
        }
@@ -265,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);
+               }
        }
 
        //