3 Replies Latest reply on Aug 24, 2007 10:24 AM by adrian.brock

    Caching in BaseClassLoaderDomain.findLoaderInExports

    alesj

      Is this intended:

       boolean canCache = true;
       boolean canBlackList = true;
      
       String packageName = ClassLoaderUtils.getResourcePackageName(name);
       List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
       if (trace)
       log.trace(this + " trying to load " + name + " from all exports of package " + packageName + " " + list);
       if (list != null && list.isEmpty() == false)
       {
       for (ClassLoaderInformation info : list)
       {
       BaseDelegateLoader exported = info.getExported();
      
       // See whether the policies allow caching/blacklisting
       BaseClassLoaderPolicy loaderPolicy = exported.getPolicy();
       if (loaderPolicy.isCachable() == false)
       canCache = false;
       if (loaderPolicy.isBlackListable() == false)
       canBlackList = false;
      
       if (exported.getResource(name) != null)
       {
       if (canCache)
       globalClassCache.put(name, exported);
       return exported;
       }
       }
       }
       // Here is not found in the exports so can we blacklist it?
       if (canBlackList)
       globalClassBlackList.add(name);
      


      Since even if the 'exported' is _not_ the one that _has_ the resource, and is not cacheable, it sets the canCache to false, so even if the 'real' exported is cacheable, it won't get cached.

      The same for getResourceFromExports method.

        • 1. Re: Caching in BaseClassLoaderDomain.findLoaderInExports

          I don't understand what point you are trying to make?

          The idea of the code above is that if any of the classloaders looked at doesn't
          allow caching or blacklisting then you can't cache or blacklist at the global level.

          e.g.
          The classloaders could be C1 (canCache=false, canBlacklist=false), C2

          On first attempt:
          C1 == not found
          C2 == found

          But C1 says don't cache the result returned from C2 because I might be able
          to return "found" in future.

          Or alternatively
          C1 == not found
          C2 == not found

          but C1 says don't blacklist (cache misses) for the same reason.

          • 2. Re: Caching in BaseClassLoaderDomain.findLoaderInExports
            alesj

            Aha, ok - just didn't see this concept/idea.

            But then the order matters. :-)
            e.g. if C2(canCache=true, canBlacklist=true) comes before your's C1?
            and C1 would eventually be able to find it in the future

            • 3. Re: Caching in BaseClassLoaderDomain.findLoaderInExports

              For the canCache yes.
              If C2 were first and it were found, it would be cached.
              It wouldn't blacklist at the global level because C1 says not to.