Author: lindner
Date: Sat Jan 24 00:48:12 2009
New Revision: 737275
URL: http://svn.apache.org/viewvc?rev=737275&view=rev
Log:
SHINDIG-253 | modified patch from Henning Schmiedehausen | clarify
GadgetFeatureRegistry locking
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=737275&r1=737274&r2=737275&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
Sat Jan 24 00:48:12 2009
@@ -52,7 +52,7 @@
// Caches the transitive dependencies to enable faster lookups.
final Map<Set<String>, Collection<GadgetFeature>> cache =
Maps.newConcurrentHashMap();
- private boolean graphComplete = false;
+ private boolean locked = false;
private final static Logger logger
= Logger.getLogger("org.apache.shindig.gadgets");
@@ -78,14 +78,31 @@
}
/**
+ * Lock the registry, no longer allow the registration of new entries.
+ * A locked registry can never be unlocked.
+ */
+ private void lock() {
+ locked = true;
+ }
+
+ /**
+ * Returns the locking state of the registry.
+ * @return true if the registry is locked.
+ */
+ public boolean isLocked() {
+ return locked;
+ }
+
+ /**
* Register a {...@code GadgetFeature}.
*
* @param feature Class implementing the feature.
*/
public void register(GadgetFeature feature) {
- Preconditions.checkState(!graphComplete,
- "register should never be invoked after calling getLibraries");
+ Preconditions.checkState(!isLocked(), "registry is locked and can no
longer be changed!");
+
if (logger.isLoggable(Level.FINE)) logger.fine("Registering feature: " +
feature.getName());
+
if (isCore(feature)) {
core.put(feature.getName(), feature);
for (GadgetFeature feat : features.values()) {
@@ -128,7 +145,7 @@
*/
public Collection<GadgetFeature> getFeatures(Collection<String> needed,
Collection<String> unsupported)
{
- graphComplete = true;
+ lock();
Set<String> neededSet;
if (needed.isEmpty()) {