[jboss-cvs] JBossAS SVN: r101076 - in projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata: spi/scope and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 17 10:29:55 EST 2010


Author: kabir.khan at jboss.com
Date: 2010-02-17 10:29:55 -0500 (Wed, 17 Feb 2010)
New Revision: 101076

Modified:
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/ScopeKey.java
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java
Log:
[JBMDR-66] Make AnnotatedElementMetaDataLoader use UnmodifiableScopeKey for the component metadata, and lazily initialize the parent ScopeKey.scopes map so it is not created unnecessarily for UnmodifiableScopeKey

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2010-02-17 14:59:00 UTC (rev 101075)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2010-02-17 15:29:55 UTC (rev 101076)
@@ -46,6 +46,7 @@
 import org.jboss.metadata.spi.scope.Scope;
 import org.jboss.metadata.spi.scope.ScopeKey;
 import org.jboss.metadata.spi.scope.ScopeLevel;
+import org.jboss.metadata.spi.scope.UnmodifiableScopeKey;
 import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
 import org.jboss.metadata.spi.signature.ConstructorSignature;
 import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
@@ -87,7 +88,7 @@
       {
          return ScopeKey.DEFAULT_SCOPE;
       }
-      return new ScopeKey(scope);
+      return new UnmodifiableScopeKey(scope);
    }
    
    /**

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/ScopeKey.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/ScopeKey.java	2010-02-17 14:59:00 UTC (rev 101075)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/ScopeKey.java	2010-02-17 15:29:55 UTC (rev 101076)
@@ -26,6 +26,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.Map;
 
 import org.jboss.util.collection.ConcurrentSkipListMap;
 
@@ -59,6 +60,8 @@
  */
 public class ScopeKey implements Serializable, Cloneable
 {
+   private final static ConcurrentSkipListMap<ScopeLevel, Scope> EMPTY_SCOPES = new UnmodifiableConcurrentSkipListMap<ScopeLevel, Scope>(); 
+   
    /** The serialVersionUID */
    private static final long serialVersionUID = -496238095349593371L + 1L;
 
@@ -66,8 +69,8 @@
    public static final ScopeKey DEFAULT_SCOPE = new ScopeKey(new Scope(CommonLevels.JVM, "THIS"));
    
    /** The scopes () */
-   private ConcurrentSkipListMap<ScopeLevel, Scope> scopes = new ConcurrentSkipListMap<ScopeLevel, Scope>();
-
+   private volatile ConcurrentSkipListMap<ScopeLevel, Scope> scopes = EMPTY_SCOPES;
+   
    /** The scope level for this key */
    private ScopeLevel maxScopeLevel;
    
@@ -271,6 +274,14 @@
          throw new IllegalArgumentException("Null scope");
       if (frozen)
          throw new IllegalStateException("The scope key is frozen");
+      if (scopes == EMPTY_SCOPES)
+      {
+         synchronized (this)
+         {
+            if (scopes == EMPTY_SCOPES)
+               scopes = new ConcurrentSkipListMap<ScopeLevel, Scope>();
+         }
+      }
 
       ScopeLevel level = scope.getScopeLevel();
       Scope result = scopes.put(level, scope);
@@ -317,7 +328,7 @@
    {
       if (scopeLevel == null)
          throw new IllegalArgumentException("Null scope level");
-
+      
       return scopes.get(scopeLevel);
    }
    
@@ -334,6 +345,9 @@
       if (frozen)
          throw new IllegalStateException("The scope key is frozen");
 
+      if (scopes == EMPTY_SCOPES)
+         return null;
+      
       Scope result = scopes.remove(scopeLevel);
       if (scopeLevel.equals(maxScopeLevel))
       {
@@ -410,4 +424,57 @@
          hashCode += scope.hashCode();
       return hashCode;
    }
+   
+   private final static class UnmodifiableConcurrentSkipListMap<K, V> extends ConcurrentSkipListMap<K, V>
+   {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public void clear()
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public V put(K key, V value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public V putIfAbsent(K key, V value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public boolean remove(Object key, Object value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public V remove(Object key)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public boolean replace(K key, V oldValue, V newValue)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public V replace(K key, V value)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      @Override
+      public void putAll(Map<? extends K, ? extends V> m)
+      {
+         throw new UnsupportedOperationException();
+      }
+   }
 }

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java	2010-02-17 14:59:00 UTC (rev 101075)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/scope/UnmodifiableScopeKey.java	2010-02-17 15:29:55 UTC (rev 101076)
@@ -348,7 +348,8 @@
       Scope createdScopes[] = new Scope[max];
       for (int looper = 0; looper < max; looper++)
          createdScopes[looper] = scopes[looper];
-      sort(createdScopes);
+      if (max > 1)
+         sort(createdScopes);
       return createdScopes;
    }
 




More information about the jboss-cvs-commits mailing list