[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jboss-cvs-commits
Subject:    [jboss-cvs] jmx/src/main/org/jboss/mx/loading ClassLoaderUtils.java UnifiedLoaderRepository3.java
From:       Bill Burke <patriot1burke () users ! sourceforge ! net>
Date:       2004-01-30 22:33:38
Message-ID: E1AmhCk-0007JR-Kp () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

  User: patriot1burke
  Date: 04/01/30 14:33:38

  Modified:    src/main/org/jboss/mx/loading ClassLoaderUtils.java
                        UnifiedLoaderRepository3.java
  Log:
  changed to threadsafe conncurent collections so that the copying before iteration
  isn't everywhere in the codebase.  This was effecting AOP at load time because
  getResource was very very very slow because of all the allocations.
  
  Revision  Changes    Path
  1.15      +14 -12    jmx/src/main/org/jboss/mx/loading/ClassLoaderUtils.java
  
  Index: ClassLoaderUtils.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/loading/ClassLoaderUtils.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ClassLoaderUtils.java	10 Nov 2003 02:53:48 -0000	1.14
  +++ ClassLoaderUtils.java	30 Jan 2004 22:33:37 -0000	1.15
  @@ -21,7 +21,9 @@
   import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.HashMap;
  +import java.util.Map;
   import java.util.HashSet;
  +import java.util.Set;
   import java.util.LinkedList;
   import java.util.zip.ZipEntry;
   import java.util.zip.ZipInputStream;
  @@ -31,7 +33,7 @@
   /** Utility methods for class loader to package names, etc.
    *
    * @author Scott.Stark@jboss.org
  - * @version $Revision: 1.14 $
  + * @version $Revision: 1.15 $
    */
   public class ClassLoaderUtils
   {
  @@ -190,7 +192,7 @@
       * @return the updated unique set of package names
       * @throws Exception
       */
  -   public static String[] updatePackageMap(UnifiedClassLoader cl, HashMap \
packagesMap)  +   public static String[] updatePackageMap(UnifiedClassLoader cl, Map \
packagesMap)  throws Exception
      {
         URL url = cl.getURL();
  @@ -206,7 +208,7 @@
       * @return the updated unique set of package names
       * @throws Exception
       */
  -   public static String[] updatePackageMap(UnifiedClassLoader cl, HashMap \
packagesMap,  +   public static String[] updatePackageMap(UnifiedClassLoader cl, Map \
packagesMap,  URL url, String[] prevPkgNames)
         throws Exception
      {
  @@ -222,12 +224,12 @@
      /** Given a UCL this method determine what classes it contains
       and create a mapping from the class names to the cl.
       * @param cl the UCL that loads from url
  -    * @param classNamesMap the HashMap<cl, String[]> to update
  +    * @param classNamesMap the Map<cl, String[]> to update
       * @return the class names directly visible to the cl
       * @throws Exception
       */
      public static String[] updateClassNamesMap(UnifiedClassLoader cl,
  -      HashMap classNamesMap)
  +      Map classNamesMap)
         throws Exception
      {
         URL url = cl.getURL();
  @@ -237,14 +239,14 @@
      }
      /** Augment the class names associated with a UCL.
       * @param cl the UCL that loads from url
  -    * @param classNamesMap the HashMap<cl, String[]> to update
  +    * @param classNamesMap the Map<cl, String[]> to update
       * @param url the URL to parse for class names
       * @param prevClassNames the set of pckage names already associated with cl
       * @return the updated list of class names
       * @throws Exception
       */
      public static String[] updateClassNamesMap(UnifiedClassLoader cl,
  -      HashMap classNamesMap, URL url, String[] prevClassNames)
  +      Map classNamesMap, URL url, String[] prevClassNames)
         throws Exception
      {
         ClassPathIterator cpi = new ClassPathIterator(url);
  @@ -256,7 +258,7 @@
         return updateClassNamesMap(cl, classNamesMap, cpi, classNameSet);
      }
   
  -   static String[] updatePackageMap(UnifiedClassLoader cl, HashMap packagesMap,
  +   static String[] updatePackageMap(UnifiedClassLoader cl, Map packagesMap,
         ClassPathIterator cpi, HashSet pkgNameSet)
         throws Exception
      {
  @@ -288,7 +290,7 @@
         return pkgNames;
      }
   
  -   static String[] updateClassNamesMap(UnifiedClassLoader cl, HashMap \
classNamesMap,  +   static String[] updateClassNamesMap(UnifiedClassLoader cl, Map \
classNamesMap,  ClassPathIterator cpi, HashSet classNameSet)
         throws Exception
      {
  @@ -319,7 +321,7 @@
       names without having to iterate through all entries in the jar.
       */
      private static void readJarIndex(UnifiedClassLoader cl, ClassPathIterator cpi,
  -      HashMap packagesMap, HashSet pkgNameSet)
  +      Map packagesMap, HashSet pkgNameSet)
         throws Exception
      {
         boolean trace = log.isTraceEnabled();
  @@ -347,7 +349,7 @@
         br.close();
      }
   
  -   private static void addPackage(String pkgName, HashMap packagesMap,
  +   private static void addPackage(String pkgName, Map packagesMap,
         HashSet pkgNameSet, UnifiedClassLoader cl, boolean trace)
      {
         // Skip the standard J2EE archive directories
  @@ -380,7 +382,7 @@
       * @param cl the UCL
       * @param trace the logging trace level flag
       */
  -   private static void addClass(String jarClassName, HashMap classNamesMap,
  +   private static void addClass(String jarClassName, Map classNamesMap,
         UnifiedClassLoader cl, boolean trace)
      {
         LinkedList ucls = (LinkedList) classNamesMap.get(jarClassName);
  
  
  
  1.21      +122 -147  \
jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java  
  Index: UnifiedLoaderRepository3.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- UnifiedLoaderRepository3.java	27 Jan 2004 14:22:42 -0000	1.20
  +++ UnifiedLoaderRepository3.java	30 Jan 2004 22:33:37 -0000	1.21
  @@ -16,6 +16,7 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Enumeration;
  +import java.util.Set;
   import java.io.IOException;
   
   import javax.management.ListenerNotFoundException;
  @@ -29,6 +30,8 @@
   import org.jboss.logging.Logger;
   
   import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
  +import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
  +import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet;
   
   /** A repository of class loaders that form a flat namespace of classes
    * and resources. This version uses UnifiedClassLoader3 instances. Class
  @@ -38,12 +41,12 @@
    *
    * @author  <a href="mailto:scott.stark@jboss.org">Scott Stark</a>.
    * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
  - * @version $Revision: 1.20 $
  + * @version $Revision: 1.21 $
    * just a hint... xdoclet not really used
    * @jmx.name="JMImplementation:service=UnifiedLoaderRepository,name=Default"
    */
   public class UnifiedLoaderRepository3 extends LoaderRepository
  -   implements NotificationBroadcaster, UnifiedLoaderRepository3MBean
  +        implements NotificationBroadcaster, UnifiedLoaderRepository3MBean
   {
      // Static --------------------------------------------------------
      private static final Logger log = \
Logger.getLogger(UnifiedLoaderRepository3.class);  @@ -56,17 +59,17 @@
      /** HashSet<UCL> of classloaders in the repository.
       * Access synchronized via this.classLoaders monitor.
       */
  -   private HashSet classLoaders = new HashSet();
  +   private CopyOnWriteArraySet classLoaders = new CopyOnWriteArraySet();
      /** HashSet<UCL> of class loaders in the repository that have a dynamic
       * URL associated with them. Such a class loader is added to every package
  -    * class loader set in #getPackageClassLoaders(String). 
  -    */ 
  +    * class loader set in #getPackageClassLoaders(String).
  +    */
      private HashSet dynamicClassLoaders = new HashSet();
      /** A HashMap<ClassLoader, UCL> of foreign (non-UCL) classloaders that
       * have been added to the repository as the key and the value the UCL
       * actually used by the ULR.
       * Access synchronized via this.classLoaders monitor.
  -    */ 
  +    */
      private HashMap nonUCLClassLoader = new HashMap();
   
      /** A HashSet<URL> used to check for duplicate URLs. Previously this was \
handled  @@ -103,7 +106,7 @@
       * ClassLoaders which have classes in the package.
       * Access synchronized via this.packagesMap monitor.
       */
  -   private HashMap packagesMap = new HashMap();
  +   private ConcurrentHashMap packagesMap = new ConcurrentHashMap();
   
      /** A HashMap<UCL, String[]> of class loaders to the array of pckages names
       * they serve
  @@ -130,20 +133,21 @@
      // Public --------------------------------------------------------
   
      public UnifiedClassLoader newClassLoader(final URL url, boolean \
                addToRepository)
  -      throws Exception
  +           throws Exception
      {
         UnifiedClassLoader3 ucl = new UnifiedClassLoader3(url, null, this);
  -      if( addToRepository )
  +      if (addToRepository)
         {
            this.registerClassLoader(ucl);
         }
         return ucl;
      }
  +
      public UnifiedClassLoader newClassLoader(final URL url, final URL origURL, \
                boolean addToRepository)
  -      throws Exception
  +           throws Exception
      {
         UnifiedClassLoader3 ucl = new UnifiedClassLoader3(url, origURL, this);
  -      if( addToRepository )
  +      if (addToRepository)
         {
            this.registerClassLoader(ucl);
         }
  @@ -154,13 +158,15 @@
      {
         return classes.size();
      }
  +
      public int getClassLoadersSize()
      {
         return classLoaders.size();
      }
  +
      public void flush()
      {
  -      synchronized( classes )
  +      synchronized (classes)
         {
            classes.clear();
         }
  @@ -168,7 +174,7 @@
   
      public Class getCachedClass(String classname)
      {
  -      return (Class)classes.get(classname);
  +      return (Class) classes.get(classname);
      }
   
      /** Unlike other implementations of LoaderRepository, this method does
  @@ -176,7 +182,7 @@
       * do not use this method.
       */
      public Class loadClass(String name, boolean resolve, ClassLoader cl)
  -      throws ClassNotFoundException
  +           throws ClassNotFoundException
      {
         UnifiedClassLoader3 ucl = (UnifiedClassLoader3) cl;
         return ucl.loadClass(name, resolve);
  @@ -189,13 +195,10 @@
      {
         String pkgName = ClassLoaderUtils.getPackageName(className);
         HashSet pkgSet = null;
  -      synchronized( packagesMap )
  -      {
  -         pkgSet = (HashSet) this.packagesMap.get(pkgName);
  -      }
  -      if( dynamicClassLoaders.size() > 0 )
  +      pkgSet = (HashSet) this.packagesMap.get(pkgName);
  +      if (dynamicClassLoaders.size() > 0)
         {
  -         if( pkgSet == null )
  +         if (pkgSet == null)
               pkgSet = new HashSet();
            pkgSet.addAll(dynamicClassLoaders);
         }
  @@ -206,7 +209,7 @@
      {
         int index = rsrcName.lastIndexOf('/');
         String pkgName = rsrcName;
  -      if( index > 0 )
  +      if (index > 0)
            pkgName = rsrcName.substring(0, index);
         return pkgName.replace('/', '.');
      }
  @@ -218,7 +221,7 @@
      public Class loadClassFromCache(String name)
      {
         Class cls = null;
  -      synchronized( classes )
  +      synchronized (classes)
         {
            cls = (Class) classes.get(name);
         }
  @@ -232,14 +235,14 @@
       */
      public void cacheLoadedClass(String name, Class cls, ClassLoader cl)
      {
  -      synchronized( classes )
  +      synchronized (classes)
         {
            // Update the global cache
            Object prevClass = classes.put(name, cls);
  -         if( log.isTraceEnabled() )
  +         if (log.isTraceEnabled())
            {
  -            log.trace("cacheLoadedClass, classname: "+name+", class: "+cls
  -               +", ucl: "+cl+", prevClass: "+prevClass);
  +            log.trace("cacheLoadedClass, classname: " + name + ", class: " + cls
  +                    + ", ucl: " + cl + ", prevClass: " + prevClass);
            }
   
            // Update the cache for this classloader
  @@ -320,13 +323,8 @@
      public void getResources(String name, ClassLoader cl, List urls)
      {
         // Go through all class loaders
  -      HashSet tmpClassLoaders;
  -      synchronized( classLoaders )
  -      {
  -         tmpClassLoaders = new HashSet(classLoaders);
  -      }
  -      Iterator iter = tmpClassLoaders.iterator();
  -      while( iter.hasNext() == true )
  +      Iterator iter = classLoaders.iterator();
  +      while (iter.hasNext() == true)
         {
            ClassLoader nextCL = (ClassLoader) iter.next();
            if (nextCL instanceof UnifiedClassLoader)
  @@ -335,13 +333,13 @@
               try
               {
                  Enumeration resURLs = ucl.findResourcesLocally(name);
  -               while( resURLs.hasMoreElements() )
  +               while (resURLs.hasMoreElements())
                  {
                     Object res = resURLs.nextElement();
                     urls.add(res);
                  }
               }
  -            catch(IOException ignore)
  +            catch (IOException ignore)
               {
               }
            }
  @@ -359,11 +357,11 @@
      private URL getResourceFromCache(String name, ClassLoader cl)
      {
         URL resource = null;
  -      synchronized( loaderToResourcesMap )
  +      synchronized (loaderToResourcesMap)
         {
            if (loaderToResourcesMap.containsKey(cl))
            {
  -            HashMap resources = (HashMap)loaderToResourcesMap.get(cl);
  +            HashMap resources = (HashMap) loaderToResourcesMap.get(cl);
               resource = (URL) resources.get(name);
            }
         }
  @@ -390,7 +388,7 @@
      private URL getResourceFromGlobalCache(String name)
      {
         ResourceInfo ri = null;
  -      synchronized( loaderToResourcesMap )
  +      synchronized (loaderToResourcesMap)
         {
            ri = (ResourceInfo) globalResources.get(name);
         }
  @@ -405,29 +403,22 @@
         // Get the set of class loaders from the packages map
         String pkgName = getResourcePackageName(name);
         Iterator i = null;
  -      synchronized( packagesMap )
  +      HashSet pkgSet = (HashSet) this.packagesMap.get(pkgName);
  +      if (pkgSet != null)
         {
  -         HashSet pkgSet = (HashSet) this.packagesMap.get(pkgName);
  -         if( pkgSet != null )
  -         {
  -            pkgSet = new HashSet(pkgSet);
  -            i = pkgSet.iterator();
  -         }
  +         //pkgSet = new HashSet(pkgSet); // todo should this be copied for safe \
iteration?  +         i = pkgSet.iterator();
         }
  -      if( i == null )
  +      if (i == null)
         {
            // If no pkg match was found just go through all class loaders
  -         synchronized( classLoaders )
  -         {
  -            HashSet tmpClassLoaders = new HashSet(classLoaders);
  -            i = tmpClassLoaders.iterator();
  -         }
  +         i = classLoaders.iterator();
         }
   
         URL url = null;
  -      while( i.hasNext() == true )
  +      while (i.hasNext() == true)
         {
  -         ClassLoader classloader = (ClassLoader)i.next();
  +         ClassLoader classloader = (ClassLoader) i.next();
            if (classloader.equals(cl))
            {
               continue;
  @@ -435,7 +426,7 @@
   
            if (classloader instanceof UnifiedClassLoader)
            {
  -            url = ((UnifiedClassLoader)classloader).getResourceLocally(name);
  +            url = ((UnifiedClassLoader) classloader).getResourceLocally(name);
               if (url != null)
               {
                  cacheLoadedResource(name, url, classloader);
  @@ -460,7 +451,7 @@
      {
         // Update the cache for this classloader only
         // This is used for cycling classloaders
  -      synchronized( loaderToResourcesMap )
  +      synchronized (loaderToResourcesMap)
         {
            HashMap resources = (HashMap) loaderToResourcesMap.get(cl);
            if (resources == null)
  @@ -479,7 +470,7 @@
       */
      private void cacheGlobalResource(String name, URL url, ClassLoader cl)
      {
  -      synchronized( loaderToResourcesMap )
  +      synchronized (loaderToResourcesMap)
         {
            globalResources.put(name, new ResourceInfo(url, cl));
         }
  @@ -492,17 +483,13 @@
      public URL[] getURLs()
      {
         HashSet classpath = new HashSet();
  -      HashSet tmp = null;
  -      synchronized( classLoaders )
  -      {
  -         tmp = (HashSet) classLoaders.clone();
  -      }
  +      Set tmp = classLoaders;
         for (Iterator iter = tmp.iterator(); iter.hasNext();)
         {
            Object obj = iter.next();
            if (obj instanceof UnifiedClassLoader)
            {
  -            UnifiedClassLoader cl = (UnifiedClassLoader)obj;
  +            UnifiedClassLoader cl = (UnifiedClassLoader) obj;
               URL[] urls = cl.getClasspath();
               int length = urls != null ? urls.length : 0;
               for (int u = 0; u < length; u++)
  @@ -531,8 +518,8 @@
   
         int count = 0;
         Class loadedClass = this.loadClassFromCache(className);
  -      StringBuffer results = new StringBuffer(className+" Information\n");
  -      if( loadedClass != null )
  +      StringBuffer results = new StringBuffer(className + " Information\n");
  +      if (loadedClass != null)
         {
            results.append("Repository cache version:");
            ClassLoaderUtils.displayClassInfo(loadedClass, results);
  @@ -541,33 +528,29 @@
         {
            results.append("Not loaded in repository cache\n");
         }
  -      HashSet tmp = null;
  -      synchronized( classLoaders )
  -      {
  -         tmp = (HashSet) classLoaders.clone();
  -      }
  +      Set tmp = classLoaders;
         for (Iterator iter = tmp.iterator(); iter.hasNext();)
         {
            URLClassLoader cl = (URLClassLoader) iter.next();
            URL classURL = cl.findResource(classRsrcName);
            if (classURL != null)
            {
  -            results.append("\n\n### Instance"+count+" found in UCL: "+cl+"\n");
  -            count ++;
  +            results.append("\n\n### Instance" + count + " found in UCL: " + cl + \
"\n");  +            count++;
            }
         }
   
         // Also look to the parent class loaders of the TCL
         ClassLoader tcl = Thread.currentThread().getContextClassLoader();
  -      URLClassLoader[] stack =  ClassLoaderUtils.getClassLoaderStack(tcl);
  -      for (int s = 0; s < stack.length; s ++)
  +      URLClassLoader[] stack = ClassLoaderUtils.getClassLoaderStack(tcl);
  +      for (int s = 0; s < stack.length; s++)
         {
            URLClassLoader cl = stack[s];
            URL classURL = cl.findResource(classRsrcName);
            if (classURL != null)
            {
  -            results.append("\n\n### Instance"+count+" via UCL: "+cl+"\n");
  -            count ++;
  +            results.append("\n\n### Instance" + count + " via UCL: " + cl + "\n");
  +            count++;
            }
         }
   
  @@ -587,26 +570,26 @@
         ClassLoader scl = Thread.currentThread().getContextClassLoader();
         ClassLoader ucl = null;
         Class clazz = null;
  -      if( classLoaders.size() > 0 )
  +      if (classLoaders.size() > 0)
            ucl = (ClassLoader) this.classLoaders.iterator().next();
         try
         {
  -         if( ucl != null )
  +         if (ucl != null)
               clazz = loadClass(className, false, ucl);
         }
  -      catch(ClassNotFoundException ignore)
  +      catch (ClassNotFoundException ignore)
         {
         }
   
         // If there is no class try the TCL
  -      if( clazz == null )
  +      if (clazz == null)
            clazz = scl.loadClass(className);
   
         return clazz;
      }
   
      public Class loadClassWithout(ClassLoader loader, String className)
  -      throws ClassNotFoundException
  +           throws ClassNotFoundException
      {
         throw new ClassNotFoundException("NYI");
      }
  @@ -617,20 +600,20 @@
      {
         // if you come to us as UCL we send you straight to the orbit
         if (loader instanceof UnifiedClassLoader)
  -         addUnifiedClassLoader((UnifiedClassLoader3)loader);
  +         addUnifiedClassLoader((UnifiedClassLoader3) loader);
         else if (loader instanceof URLClassLoader)
         {
  -         URLClassLoader ucl = (URLClassLoader)loader;
  +         URLClassLoader ucl = (URLClassLoader) loader;
            URL[] urls = ucl.getURLs();
            int count = urls != null && urls.length > 0 ? urls.length : 0;
            URL origURL = count > 0 ? urls[0] : null;
            UnifiedClassLoader3 ucl3 = new UnifiedClassLoader3(origURL, origURL, \
                this);
  -            addUnifiedClassLoader(ucl3);
  -         synchronized( classLoaders )
  +         addUnifiedClassLoader(ucl3);
  +         synchronized (classLoaders)
            {
               nonUCLClassLoader.put(loader, ucl3);
            }
  -         for (int i = 1; i < count; i ++)
  +         for (int i = 1; i < count; i++)
            {
               this.addClassLoaderURL(ucl3, urls[i]);
            }
  @@ -645,32 +628,32 @@
      {
         UnifiedClassLoader ucl = (UnifiedClassLoader) cl;
         boolean added = false;
  -      synchronized( classLoaders )
  +      synchronized (classLoaders)
         {
            // Strip any query parameter
            String query = url.getQuery();
  -         if( query != null )
  +         if (query != null)
            {
               String ext = url.toExternalForm();
               String ext2 = ext.substring(0, ext.length() - query.length() - 1);
               try
               {
  -               url = new URL (ext2);
  +               url = new URL(ext2);
               }
  -            catch(MalformedURLException e)
  +            catch (MalformedURLException e)
               {
  -               log.warn("Failed to strip query from: "+url, e);
  +               log.warn("Failed to strip query from: " + url, e);
               }
            }
   
            // See if the URL is associated with a class loader
  -         if( classLoaderURLs.contains(url) == false )
  +         if (classLoaderURLs.contains(url) == false)
            {
               updatePackageMap(ucl, url);
               classLoaderURLs.add(url);
               added = true;
               // Check for a dynamic URL
  -            if( query != null && query.indexOf("dynamic=true") >= 0 )
  +            if (query != null && query.indexOf("dynamic=true") >= 0)
                  dynamicClassLoaders.add(ucl);
            }
         }
  @@ -687,25 +670,25 @@
         // See if this URL already exists
         URL url = cl.getURL();
         boolean added = false;
  -      synchronized( classLoaders )
  +      synchronized (classLoaders)
         {
            boolean exists = classLoaderURLs.contains(url);
            // If already present will not be added
  -         if(!exists)
  +         if (!exists)
            {
               classLoaderURLs.add(url);
               added = classLoaders.add(cl);
            }
            if (added)
            {
  -            log.debug("Adding "+cl);
  -            addedCount ++;
  +            log.debug("Adding " + cl);
  +            addedCount++;
               cl.setAddedOrder(addedCount);
               updatePackageMap(cl);
            }
            else
            {
  -            log.debug("Skipping duplicate "+cl);
  +            log.debug("Skipping duplicate " + cl);
            }
         }
      }
  @@ -717,20 +700,18 @@
      {
         try
         {
  -         synchronized( packagesMap )
  -         {
  -            String[] pkgNames = ClassLoaderUtils.updatePackageMap(cl, \
                packagesMap);
  -            loaderToPackagesMap.put(cl, pkgNames);
  -         }
  +         String[] pkgNames = ClassLoaderUtils.updatePackageMap(cl, packagesMap);
  +         loaderToPackagesMap.put(cl, pkgNames);
         }
  -      catch(Exception e)
  +      catch (Exception e)
         {
  -         if( log.isTraceEnabled() )
  -            log.trace("Failed to update pkgs for cl="+cl, e);
  +         if (log.isTraceEnabled())
  +            log.trace("Failed to update pkgs for cl=" + cl, e);
            else
  -            log.debug("Failed to update pkgs for cl="+cl, e);
  +            log.debug("Failed to update pkgs for cl=" + cl, e);
         }
      }
  +
      /** Walk through the new URL to update the packages the ClassLoader is
       * capable of handling
       */
  @@ -738,19 +719,16 @@
      {
         try
         {
  -         synchronized( packagesMap )
  -         {
  -            String[] prevPkgNames = (String[]) loaderToPackagesMap.get(cl);
  -            String[] pkgNames = ClassLoaderUtils.updatePackageMap(cl, packagesMap, \
                url, prevPkgNames);
  -            loaderToPackagesMap.put(cl, pkgNames);
  -         }
  +         String[] prevPkgNames = (String[]) loaderToPackagesMap.get(cl);
  +         String[] pkgNames = ClassLoaderUtils.updatePackageMap(cl, packagesMap, \
url, prevPkgNames);  +         loaderToPackagesMap.put(cl, pkgNames);
         }
  -      catch(Exception e)
  +      catch (Exception e)
         {
  -         if( log.isTraceEnabled() )
  -            log.trace("Failed to update pkgs for cl="+cl, e);
  +         if (log.isTraceEnabled())
  +            log.trace("Failed to update pkgs for cl=" + cl, e);
            else
  -            log.debug("Failed to update pkgs for cl="+cl, e);
  +            log.debug("Failed to update pkgs for cl=" + cl, e);
         }
      }
   
  @@ -761,31 +739,31 @@
      {
         ArrayList removeNotifications = new ArrayList();
         ClassLoader cl = loader;
  -      synchronized( classLoaders )
  +      synchronized (classLoaders)
         {
  -         if( (loader instanceof UnifiedClassLoader) == false )
  +         if ((loader instanceof UnifiedClassLoader) == false)
            {
               cl = (ClassLoader) nonUCLClassLoader.remove(loader);
            }
  -         if( cl instanceof UnifiedClassLoader )
  +         if (cl instanceof UnifiedClassLoader)
            {
               UnifiedClassLoader ucl = (UnifiedClassLoader) cl;
               if (getTranslator() != null)
                  getTranslator().unregisterClassLoader(ucl);
               URL[] urls = ucl.getClasspath();
  -            for(int u = 0; u < urls.length; u ++)
  +            for (int u = 0; u < urls.length; u++)
                  classLoaderURLs.remove(urls[u]);
            }
            boolean removed = classLoaders.remove(cl);
  -         log.debug("UnifiedLoaderRepository removed("+removed+") " + cl);
  +         log.debug("UnifiedLoaderRepository removed(" + removed + ") " + cl);
   
            // Take care also of the cycling mapping for classes
            HashSet loadedClasses = null;
            boolean hasLoadedClasses = false;
  -         synchronized( classes )
  +         synchronized (classes)
            {
               hasLoadedClasses = loaderToClassesMap.containsKey(cl);
  -            if( hasLoadedClasses )
  +            if (hasLoadedClasses)
                  loadedClasses = (HashSet) loaderToClassesMap.remove(cl);
               // This classloader has loaded at least one class
               if (loadedClasses != null)
  @@ -793,27 +771,27 @@
                  // Notify that classes are about to be removed
                  for (Iterator iter = loadedClasses.iterator(); iter.hasNext();)
                  {
  -                  String className = (String)iter.next();
  +                  String className = (String) iter.next();
                     Notification n = new Notification(CLASS_REMOVED, this,
  -                        getNextSequenceNumber(), className);
  +                          getNextSequenceNumber(), className);
                     removeNotifications.add(n);
                  }
   
                  // Remove the classes from the global cache
                  for (Iterator i = loadedClasses.iterator(); i.hasNext();)
                  {
  -                  String cls = (String)i.next();
  +                  String cls = (String) i.next();
                     this.classes.remove(cls);
                  }
               }
            }
   
            // Take care also of the cycling mapping for resources
  -         synchronized( loaderToResourcesMap )
  +         synchronized (loaderToResourcesMap)
            {
               if (loaderToResourcesMap.containsKey(cl))
               {
  -               HashMap resources = (HashMap)loaderToResourcesMap.remove(cl);
  +               HashMap resources = (HashMap) loaderToResourcesMap.remove(cl);
   
                  // Remove the resources from the global cache that are from this \
classloader  if (resources != null)
  @@ -830,26 +808,23 @@
            }
   
            // Clean up the package name to class loader mapping
  -         synchronized( packagesMap )
  -         {
  -            String[] pkgNames = (String[]) loaderToPackagesMap.remove(cl);
  -            int length = pkgNames != null ? pkgNames.length : 0;
  -            for(int p = 0; p < length; p ++)
  +         String[] pkgNames = (String[]) loaderToPackagesMap.remove(cl);
  +         int length = pkgNames != null ? pkgNames.length : 0;
  +         for (int p = 0; p < length; p++)
  +         {
  +            String pkgName = pkgNames[p];
  +            HashSet pkgSet = (HashSet) packagesMap.get(pkgName);
  +            if (pkgSet != null)
               {
  -               String pkgName = pkgNames[p];
  -               HashSet pkgSet = (HashSet) packagesMap.get(pkgName);
  -               if( pkgSet != null )
  -               {
  -                  pkgSet.remove(cl);
  -                  if( pkgSet.isEmpty() )
  -                     packagesMap.remove(pkgName);
  -               }
  +               pkgSet.remove(cl);
  +               if (pkgSet.isEmpty())
  +                  packagesMap.remove(pkgName);
               }
            }
         }
   
         // Send the class removal notfications outside of the synchronized block
  -      for(int n = 0; n < removeNotifications.size(); n ++)
  +      for (int n = 0; n < removeNotifications.size(); n++)
         {
            Notification msg = (Notification) removeNotifications.get(n);
            broadcaster.sendNotification(msg);
  @@ -898,7 +873,7 @@
       * @exception IllegalArgumentException if an error occurs
       */
      public void addNotificationListener(NotificationListener listener,
  -      NotificationFilter filter, Object handback) throws IllegalArgumentException
  +                                       NotificationFilter filter, Object handback) \
throws IllegalArgumentException  {
         broadcaster.addNotificationListener(listener, filter, handback);
      }
  @@ -913,11 +888,11 @@
         {
            info = new MBeanNotificationInfo[]{
               new MBeanNotificationInfo(new String[]{"CLASSLOADER_ADDED"},
  -                                      "javax.management.Notification",
  -                                      "Notification that a classloader has been \
added to the extensible classloader"),  +                    \
"javax.management.Notification",  +                    "Notification that a \
classloader has been added to the extensible classloader"),  new \
                MBeanNotificationInfo(new String[]{"CLASS_REMOVED"},
  -                                      "javax.management.Notification",
  -                                      "Notification that a class has been removed \
from the extensible classloader")  +                    \
"javax.management.Notification",  +                    "Notification that a class has \
been removed from the extensible classloader")  
            };
         }
  
  
  


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
jboss-cvs-commits mailing list
jboss-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-cvs-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic