You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/10/30 10:56:26 UTC
svn commit: r709127 -
/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
Author: etnu
Date: Thu Oct 30 02:56:26 2008
New Revision: 709127
URL: http://svn.apache.org/viewvc?rev=709127&view=rev
Log:
Fixed a synchronization problem in feature dependency chain caching logic.
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java?rev=709127&r1=709126&r2=709127&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java Thu Oct 30 02:56:26 2008
@@ -30,6 +30,8 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
/**
@@ -48,6 +50,7 @@
// Caches the transitive dependencies to enable faster lookups.
private final Map<Collection<String>, Collection<GadgetFeature>> cache
= Maps.newHashMap();
+ private final ReadWriteLock cacheLock = new ReentrantReadWriteLock();
private boolean graphComplete = false;
@@ -130,7 +133,9 @@
}
// We use the cache only for situations where all needed are available.
// if any are missing, the result won't be cached.
+ cacheLock.readLock().lock();
Collection<GadgetFeature> libCache = cache.get(needed);
+ cacheLock.readLock().unlock();
if (libCache != null) {
return libCache;
}
@@ -145,7 +150,9 @@
}
}
if (unsupported == null || unsupported.isEmpty()) {
+ cacheLock.writeLock().lock();
cache.put(needed, Collections.unmodifiableList(ret));
+ cacheLock.writeLock().unlock();
}
return ret;
}