tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject svn commit: r409298 - /tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/modeler/Registry.java
Date Thu, 25 May 2006 04:07:26 GMT
Author: billbarker
Date: Wed May 24 21:07:25 2006
New Revision: 409298

URL: http://svn.apache.org/viewvc?rev=409298&view=rev
Log:
Port the fix for MODELER-3 from [modeler] (minus some of the fluff :).

It's mostly non-critical path stuff, so it shouldn't be that much of a performance hit.

Also throw in some Generics cleanups.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/modeler/Registry.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/modeler/Registry.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/modeler/Registry.java?rev=409298&r1=409297&r2=409298&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/modeler/Registry.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/modeler/Registry.java Wed May 24 21:07:25
2006
@@ -106,14 +106,14 @@
      * The set of ManagedBean instances for the beans this registry
      * knows about, keyed by name.
      */
-    private HashMap descriptors = new HashMap();
+    private HashMap<String, ManagedBean> descriptors = new HashMap<String, ManagedBean>();
 
     /** List of managed byeans, keyed by class name
      */
-    private HashMap descriptorsByClass = new HashMap();
+    private HashMap<String, ManagedBean> descriptorsByClass = new HashMap<String,
ManagedBean>();
 
     // map to avoid duplicated searching or loading descriptors 
-    private HashMap searchedPaths=new HashMap();
+    private Hashtable<String, URL> searchedPaths=new Hashtable<String, URL>();
     
     private Object key;
     private Object guard;
@@ -218,9 +218,9 @@
      * @since 1.1
      */ 
     public void stop() {
-        descriptorsByClass = new HashMap();
-        descriptors = new HashMap();
-        searchedPaths=new HashMap();
+        descriptorsByClass = new HashMap<String, ManagedBean>();
+        descriptors = new HashMap<String, ManagedBean>();
+        searchedPaths=new Hashtable<String, URL>();
     }
     
     /** 
@@ -411,9 +411,11 @@
      */
     public void addManagedBean(ManagedBean bean) {
         // XXX Use group + name
-        descriptors.put(bean.getName(), bean);
-        if( bean.getType() != null ) {
-            descriptorsByClass.put( bean.getType(), bean );
+        synchronized(descriptors) {
+            descriptors.put(bean.getName(), bean);
+            if( bean.getType() != null ) {
+                descriptorsByClass.put( bean.getType(), bean );
+            }
         }
     }
 
@@ -428,10 +430,12 @@
      */
     public ManagedBean findManagedBean(String name) {
         // XXX Group ?? Use Group + Type
-        ManagedBean mb=((ManagedBean) descriptors.get(name));
-        if( mb==null )
-            mb=(ManagedBean)descriptorsByClass.get(name);
-        return mb;
+        synchronized(descriptors) {
+            ManagedBean mb= descriptors.get(name);
+            if( mb==null )
+                mb=descriptorsByClass.get(name);
+            return mb;
+        }
     }
     
     /**
@@ -441,7 +445,9 @@
      * @since 1.0
      */
     public String[] findManagedBeans() {
-        return ((String[]) descriptors.keySet().toArray(new String[0]));
+        synchronized(descriptors) {
+            return ((String[]) descriptors.keySet().toArray(new String[0]));
+        }
     }
 
 
@@ -456,13 +462,15 @@
     public String[] findManagedBeans(String group) {
 
         ArrayList results = new ArrayList();
-        Iterator items = descriptors.values().iterator();
-        while (items.hasNext()) {
-            ManagedBean item = (ManagedBean) items.next();
-            if ((group == null) && (item.getGroup() == null)) {
-                results.add(item.getName());
-            } else if (group.equals(item.getGroup())) {
-                results.add(item.getName());
+        synchronized(descriptors) {
+            Iterator<ManagedBean> items = descriptors.values().iterator();
+            while (items.hasNext()) {
+                ManagedBean item =  items.next();
+                if ((group == null) && (item.getGroup() == null)) {
+                    results.add(item.getName());
+                } else if (group.equals(item.getGroup())) {
+                    results.add(item.getName());
+                }
             }
         }
         String values[] = new String[results.size()];
@@ -479,8 +487,10 @@
      */
     public void removeManagedBean(ManagedBean bean) {
        // TODO: change this to use group/name
-        descriptors.remove(bean.getName());
-        descriptorsByClass.remove( bean.getType());
+        synchronized(descriptors) {
+            descriptors.remove(bean.getName());
+            descriptorsByClass.remove( bean.getType());
+        }
     }
 
     // -------------------- Deprecated 1.0 methods  --------------------
@@ -840,7 +850,7 @@
      *
      * @param packageName
      */
-    public void loadDescriptors( String packageName, ClassLoader classLoader  ) {
+    public synchronized void loadDescriptors( String packageName, ClassLoader classLoader
 ) {
         String res=packageName.replace( '.', '/');
 
         if( log.isTraceEnabled() ) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message