[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 UnifiedLoaderRepository2.java
From:       Adrian Brock <ejort () users ! sourceforge ! net>
Date:       2002-08-31 23:13:14
[Download RAW message or body]

  User: ejort   
  Date: 02/08/31 16:13:14

  Modified:    src/main/org/jboss/mx/loading Tag: Branch_3_2
                        UnifiedLoaderRepository2.java
  Log:
  Global resources
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.5.2.3   +53 -3     jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository2.java
  
  Index: UnifiedLoaderRepository2.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository2.java,v
  retrieving revision 1.5.2.2
  retrieving revision 1.5.2.3
  diff -u -r1.5.2.2 -r1.5.2.3
  --- UnifiedLoaderRepository2.java	20 Aug 2002 22:55:47 -0000	1.5.2.2
  +++ UnifiedLoaderRepository2.java	31 Aug 2002 23:13:14 -0000	1.5.2.3
  @@ -32,7 +32,8 @@
    * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
    * @author  <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
    * @author  <a href="mailto:simone.bordet@hp.com">Simone Bordet</a>.
  - * @version $Revision: 1.5.2.2 $
  + * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
  + * @version $Revision: 1.5.2.3 $
    * just a hint... xdoclet not really used
    * @jmx.name="JMImplementation:service=UnifiedLoaderRepository,name=Default"
    *
  @@ -71,6 +72,11 @@
       */
      private HashMap loaderToResourcesMap = new HashMap();
   
  +   /**
  +    * The global resources. Map of name to ResourceInfo
  +    */
  +   private HashMap globalResources = new HashMap();
  +
      /** A map of package names to the set of ClassLoaders which
       have classes in the package.
       */
  @@ -285,7 +291,13 @@
         // The calling classloader sees the resource, we're done
         if (resource != null) {return resource;}
   
  -      // Not visible by the calling classloader, iterate on the other classloaders
  +      // Not found in classloader, ask the global cache
  +      resource = getResourceFromGlobalCache(name);
  +
  +      // The cache has it, we are done
  +      if (resource != null) {return resource;}
  +
  +      // Not visible in global cache, iterate on all classloaders 
         resource = getResourceFromRepository(name, cl);
   
         // Some other classloader sees the resource, we're done
  @@ -321,6 +333,16 @@
         return null;
      }
   
  +   private URL getResourceFromGlobalCache(String name)
  +   {
  +      // Invoked after the classloader is asked, caches the
  +      // results of global lookups
  +      ResourceInfo ri = (ResourceInfo) globalResources.get(name);
  +      if (ri != null)
  +         return ri.url;
  +      return null;
  +   }
  +
      private URL getResourceFromRepository(String name, ClassLoader cl)
      {
         // Get the set of class loaders from the packages map
  @@ -347,6 +369,7 @@
               if (url != null)
               {
                  cacheLoadedResource(name, url, classloader);
  +               cacheGlobalResource(name, url, classloader);
                  return url;
               }
               else
  @@ -373,6 +396,12 @@
         resources.put(name, url);
      }
   
  +   private void cacheGlobalResource(String name, URL url, ClassLoader cl)
  +   {
  +      // Resources looked up from one classloader, found in another.
  +      globalResources.put(name, new ResourceInfo(url, cl));
  +   }
  +
      /**
       * Obtain a listing of the URL for all UnifiedClassLoaders associated with
       * the ServiceLibraries
  @@ -591,10 +620,21 @@
         }
   
         // Take care also of the cycling mapping for resources
  -      // There is no global cache for resources
         if (loaderToResourcesMap.containsKey(cl))
         {
            HashMap resources = (HashMap)loaderToResourcesMap.remove(cl);
  +
  +         // Remove the resources from the global cache that are from this classloader
  +         if (resources != null)
  +         {
  +            for (Iterator i = resources.keySet().iterator(); i.hasNext();)
  +            {
  +               String name = (String) i.next();
  +               ResourceInfo ri = (ResourceInfo) globalResources.get(name);
  +               if (ri != null && ri.cl == cl)
  +                  globalResources.remove(name);
  +            }
  +         }
         }
   
         // Clean up the package name to class loader mapping
  @@ -693,4 +733,14 @@
         return sequenceNumber++;
      }
   
  +   private static class ResourceInfo
  +   {
  +      public URL url;
  +      public ClassLoader cl;
  +      public ResourceInfo(URL url, ClassLoader cl)
  +      {
  +         this.url = url;
  +         this.cl = cl;
  +      }
  +   }
   }
  
  
  


-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
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