[jboss-cvs] JBossAS SVN: r79579 - in projects/aop/trunk: asintegration-core/src/main/org/jboss/aop/classpool and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 16 10:16:45 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-10-16 10:16:44 -0400 (Thu, 16 Oct 2008)
New Revision: 79579
Added:
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderInitializer.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderScopingPolicyWithRegistry.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/DomainRegistry.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java
projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployer.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPoolFactory.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5Integration.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedJBoss5ClassPool.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedVFSClassLoaderDomain.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderDomainRegistry.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderScopingPolicy.java
Log:
[JBAOP-667] Refactor how scoped classloaders are handled in AS5
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -218,4 +218,11 @@
}
return this.getClass().getName() + "@" + System.identityHashCode(this) + " " + super.toString() + " - dcl:" + cl;
}
+
+ public CtClass internalGet0(String classname, boolean useCache) throws NotFoundException
+ {
+ return super.get0(classname, useCache);
+ }
+
+
}
Modified: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -39,6 +39,10 @@
protected ClassPool getCreateParentClassPools(final ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
{
//Make sure that we get classpools for all the parent classloaders
+ if (cl == null)
+ {
+ return ClassPool.getDefault();
+ }
ClassLoader parent = SecurityActions.getParent(cl);
if (parent != null)
Added: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderInitializer.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderInitializer.java (rev 0)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderInitializer.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.asintegration.jboss5;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AOPClassLoaderInitializer
+{
+ public static Domain initializeForUnit(DeploymentUnit unit)
+ {
+ AOPClassLoaderScopingPolicyWithRegistry policy = (AOPClassLoaderScopingPolicyWithRegistry)AspectManager.getClassLoaderScopingPolicy();
+ registerLoaders(policy, unit);
+ Domain domain = getDomain(policy.getRegistry(), unit);
+
+ return domain;
+ }
+
+ public static void unregisterLoaders(AspectManager manager, DeploymentUnit unit)
+ {
+ AOPClassLoaderScopingPolicyWithRegistry policy = (AOPClassLoaderScopingPolicyWithRegistry)AspectManager.getClassLoaderScopingPolicy();
+ DomainRegistry registry = policy.getRegistry();
+ if (unit.isTopLevel() || unit.getParent().getClassLoader() != unit.getClassLoader())
+ {
+ registry.cleanupLoader(unit.getClassLoader());
+ manager.unregisterClassLoader(unit.getClassLoader());
+ }
+ }
+
+ private static void registerLoaders(AOPClassLoaderScopingPolicyWithRegistry policy, DeploymentUnit unit)
+ {
+ DomainRegistry registry = policy.getRegistry();
+ if (!unit.isTopLevel())
+ {
+ registerLoaders(policy, unit.getParent());
+ }
+
+ if (unit.isTopLevel() || unit.getParent().getClassLoader() != unit.getClassLoader())
+ {
+ //Only bother doing all this if we are a different loader from the parent unit
+ Module module = getModuleRecursively(unit);
+
+ ScopedVFSClassLoaderDomain domain = getDomain(registry, unit); //THis might be wrong
+ if (domain == null)
+ {
+ domain = createDomain(registry, unit.getClassLoader(), module, unit);
+ }
+
+ ClassLoader parentUnitLoader = unit.isTopLevel() ? null : unit.getParent().getClassLoader();
+ registry.initMapsForLoader(unit.getClassLoader(), module, domain, parentUnitLoader);
+
+ policy.registerClassLoader(module, unit.getClassLoader());
+ }
+ }
+
+ /**
+ * A unit that is a child will not automatically pick up the parent module
+ */
+ private static Module getModuleRecursively(DeploymentUnit unit)
+ {
+ Module module = unit.getAttachment(Module.class);
+ if (module == null)
+ {
+ return getModuleRecursively(unit.getParent());
+
+ }
+ return module;
+ }
+
+
+ private static ScopedVFSClassLoaderDomain getDomain(DomainRegistry registry, DeploymentUnit unit)
+ {
+ return (ScopedVFSClassLoaderDomain)registry.getRegisteredDomain(unit.getClassLoader());
+ }
+
+ private static ScopedVFSClassLoaderDomain createDomain(DomainRegistry registry, ClassLoader loader, Module module, DeploymentUnit unit)
+ {
+ if (!module.getDeterminedDomainName().equals(ClassLoaderSystem.DEFAULT_DOMAIN_NAME))
+ {
+ ClassLoaderSystem system = ClassLoaderSystem.getInstance();
+ String domainName = module.getDeterminedDomainName();
+ ClassLoaderDomain domain = system.getDomain(domainName);
+
+ boolean parentDelegation = module.isJ2seClassLoadingCompliance();
+ String name = String.valueOf(System.identityHashCode(loader));
+
+ ScopedVFSClassLoaderDomain parentDomain = unit.isTopLevel() ? null : getDomain(registry, unit.getParent());
+ AspectManager parent = parentDomain != null ? parentDomain : AspectManager.getTopLevelAspectManager();
+
+ return new ScopedVFSClassLoaderDomain(loader, name, parentDelegation, parent, false, domain, registry);
+ }
+ return null;
+ }
+
+}
Added: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderScopingPolicyWithRegistry.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderScopingPolicyWithRegistry.java (rev 0)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AOPClassLoaderScopingPolicyWithRegistry.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.asintegration.jboss5;
+
+import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
+import org.jboss.classloading.spi.dependency.Module;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface AOPClassLoaderScopingPolicyWithRegistry extends AOPClassLoaderScopingPolicy
+{
+ DomainRegistry getRegistry();
+
+ void registerClassLoader(Module module, ClassLoader loader);
+
+}
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployer.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployer.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployer.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -104,6 +104,7 @@
public void deploy(VFSDeploymentUnit unit) throws DeploymentException
{
AspectManager manager = getCorrectManager(unit);
+ unit.addAttachment(AspectManager.class, manager);
List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
@@ -122,7 +123,8 @@
{
try
{
- AspectManager manager = getCorrectManager(unit);
+ AspectManager manager = unit.getAttachment(AspectManager.class);
+
List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
if (isAopArchiveOrFolder(unit))
@@ -137,10 +139,7 @@
}
finally
{
- if (unit.getTopLevel() == unit)
- {
- aspectManager.unregisterClassLoader(unit.getClassLoader());
- }
+ AOPClassLoaderInitializer.unregisterLoaders(aspectManager, unit);
}
}
@@ -355,18 +354,7 @@
{
//Scoped AOP deployments are only available when deployed as part of a scoped sar, ear etc.
//It can contain an aop.xml file, or it can be part of a .aop file
- //Linking a standalone -aop.xml file onto a scoped deployment is not possible at the moment
- VFSClassLoaderScopingPolicy policy = null;
- try
- {
- policy = (VFSClassLoaderScopingPolicy)AspectManager.getClassLoaderScopingPolicy();
- }
- catch(ClassCastException e)
- {
- throw new RuntimeException("Wrong policy configured " + policy);
- }
-
- Domain domain = initializeDomain(policy, unit);
+ Domain domain = AOPClassLoaderInitializer.initializeForUnit(unit);
if (domain != null)
{
return domain;
@@ -390,55 +378,4 @@
}
}
- private Domain initializeDomain(VFSClassLoaderScopingPolicy policy, VFSDeploymentUnit unit)
- {
- Module module = unit.getTopLevel().getAttachment(Module.class);
- ClassLoader loader = unit.getClassLoader();
- ClassLoader topLoader = unit.getTopLevel().getClassLoader();
-
- VFSClassLoaderDomainRegistry registry = policy.getRegistry();
-
- boolean isWar = unit.isAttachmentPresent("org.jboss.metadata.web.jboss.JBossWebMetaData");
-
- if (isWar && loader != topLoader)
- {
- ScopedVFSClassLoaderDomain scopedDomain = (ScopedVFSClassLoaderDomain)registry.getRegisteredDomain(loader);
- if (scopedDomain == null)
- {
- scopedDomain = (ScopedVFSClassLoaderDomain)registry.getRegisteredDomain(topLoader);
- }
-
- if (scopedDomain != null)
- {
- registry.initMapsForLoader(loader, module, scopedDomain);
- }
-
- policy.registerClassLoader(module, isWar, loader);
-
- return scopedDomain;
- }
- else
- {
- ScopedVFSClassLoaderDomain scopedDomain = (ScopedVFSClassLoaderDomain)registry.getRegisteredDomain(loader);
- if (scopedDomain == null)
- {
- if (!module.getDeterminedDomainName().equals(ClassLoaderSystem.DEFAULT_DOMAIN_NAME))
- {
- ClassLoaderSystem system = ClassLoaderSystem.getInstance();
- String domainName = module.getDeterminedDomainName();
- ClassLoaderDomain domain = system.getDomain(domainName);
-
- boolean parentDelegation = module.isJ2seClassLoadingCompliance();
- String name = String.valueOf(System.identityHashCode(loader));
-
- scopedDomain = new ScopedVFSClassLoaderDomain(loader, name, parentDelegation, AspectManager.getTopLevelAspectManager(), false, domain, registry);
- }
-
- registry.initMapsForLoader(loader, module, scopedDomain);
-
- policy.registerClassLoader(module, isWar, loader);
- }
- return scopedDomain;
- }
- }
}
Added: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/DomainRegistry.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/DomainRegistry.java (rev 0)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/DomainRegistry.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.asintegration.jboss5;
+
+import org.jboss.aop.Domain;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloading.spi.dependency.Module;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface DomainRegistry
+{
+ boolean initMapsForLoader(ClassLoader loader, Module module, ScopedVFSClassLoaderDomain domain, ClassLoader parentUnitLoader);
+
+ void cleanupLoader(ClassLoader loader);
+
+ Domain getRegisteredDomain(ClassLoader cl);
+
+ ClassLoaderDomain getClassLoaderDomainForLoader(ClassLoader cl);
+
+ ClassLoader getParentUnitLoader(ClassLoader loader);
+
+ Module getModule(ClassLoader loader);
+
+}
\ No newline at end of file
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPoolFactory.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPoolFactory.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPoolFactory.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -28,6 +28,8 @@
import javassist.scopedpool.ScopedClassPool;
import javassist.scopedpool.ScopedClassPoolFactory;
import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.aop.AspectManager;
import org.jboss.aop.classpool.AOPClassPool;
import org.jboss.aop.classpool.AbstractJBossClassPoolFactory;
import org.jboss.aop.classpool.ExtraClassPoolFactoryParameters;
@@ -45,28 +47,53 @@
**/
public class JBoss5ClassPoolFactory extends AbstractJBossClassPoolFactory implements ScopedClassPoolFactory
{
+ private DomainRegistry registry;
+
+ public JBoss5ClassPoolFactory(DomainRegistry registry)
+ {
+ this.registry = registry;
+ }
+
public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
{
ClassPool parent = getCreateParentClassPools(cl, src, repository);
- Map<Object, Object> props = ExtraClassPoolFactoryParameters.peekThreadProperties();
- boolean isWebCl = props == null ? false : ((Boolean)props.get("IsWebCl")).booleanValue();
- if (!isWebCl && cl instanceof RealClassLoader)
+
+ ScopedClassPool pool = null;
+
+ if (cl instanceof RealClassLoader)
{
- Module module = props == null ? null : (Module)props.get(Module.class);
+ Module module = registry.getModule(cl);
if (module != null && module.getDeterminedParentDomainName() != null)
{
//It is scoped
ClassLoaderSystem sys = ClassLoaderSystem.getInstance();
ClassLoaderDomain domain = sys.getDomain(module.getDeterminedDomainName());
boolean parentFirst = module.isJ2seClassLoadingCompliance();
-
- return new ScopedJBoss5ClassPool(cl, parent, repository, getTempURL(module), parentFirst, domain);
+ ClassPool parentDomainPool = getParentUnitClassPool(cl);
+ pool = new ScopedJBoss5ClassPool(cl, parent, parentDomainPool, repository, getTempURL(module), parentFirst, domain);
}
- return new JBoss5ClassPool(cl, parent, repository, getTempURL(module));
+ else
+ {
+ pool = new JBoss5ClassPool(cl, parent, repository, getTempURL(module));
+ }
}
- return new AOPClassPool(cl, parent, repository);
+
+ if (pool == null)
+ {
+ pool = new AOPClassPool(cl, parent, repository);
+ }
+ log.debug("Created pool " + pool + " for loader " + cl);
+
+ return pool;
}
+
+ private ClassPool getParentUnitClassPool(ClassLoader cl)
+ {
+ ClassLoader parent = registry.getParentUnitLoader(cl);
+ return AspectManager.instance().registerClassLoader(parent);
+ }
+
private URL getTempURL(Module module)
{
if (module == null)
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5Integration.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5Integration.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5Integration.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -49,6 +49,7 @@
/** The delegate classpool factory */
private ScopedClassPoolFactory delegateClassPoolFactory;
private AOPClassLoaderScopingPolicy policy = new VFSClassLoaderScopingPolicy();
+
private static final Set<ClassLoader> bootstrapLoaders;
static
@@ -107,12 +108,18 @@
{
return policy;
}
+
+ public void setClassPoolFactory(ScopedClassPoolFactory factory)
+ {
+ this.delegateClassPoolFactory = factory;
+ }
public synchronized ScopedClassPoolFactory createScopedClassPoolFactory(File tmpDir) throws Exception
{
if (delegateClassPoolFactory == null)
{
- delegateClassPoolFactory = new JBoss5ClassPoolFactory();
+ DomainRegistry registry = ((VFSClassLoaderScopingPolicy)policy).getRegistry();
+ delegateClassPoolFactory = new JBoss5ClassPoolFactory(registry);
}
return this;
}
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedJBoss5ClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedJBoss5ClassPool.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedJBoss5ClassPool.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -50,13 +50,18 @@
ThreadLocal<ClassPool> lastPool = new ThreadLocal<ClassPool>();
WeakReference<ClassLoaderDomain> domainRef;
+ /** The classpool representing the parent domain of this one */
+ ClassPool parentDomainPool;
- public ScopedJBoss5ClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository,
+ public ScopedJBoss5ClassPool(ClassLoader cl, ClassPool src, ClassPool parentDomainPool, ScopedClassPoolRepository repository,
URL tmpURL, boolean parentFirst, ClassLoaderDomain domain)
{
super(cl, src, repository, tmpURL);
super.childFirstLookup = !parentFirst;
+ this.parentDomainPool = parentDomainPool;
this.domainRef = new WeakReference<ClassLoaderDomain>(domain);
+
+ log.debug("Created new ScopedJBoss5ClasPool for " + cl + ", with parent: " + src + ", parentDomain: " + parentDomainPool + ", parentFirst: " + parentFirst);
}
private URL getResourceUrlForClass(String resourcename)
@@ -89,6 +94,93 @@
return false;
}
+
+ @Override
+ protected synchronized CtClass get0(String classname, boolean useCache) throws NotFoundException
+ {
+ CtClass clazz = null;
+ if (useCache)
+ {
+ clazz = getCached(classname);
+ if (clazz != null)
+ return clazz;
+ }
+
+ if (!childFirstLookup)
+ {
+ if (parentDomainPool != null)
+ {
+ clazz = performGet(parentDomainPool, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ if (parent != null)
+ {
+ clazz = performGet(parent, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ }
+
+ clazz = createCtClass(classname, useCache);
+ if (clazz != null)
+ {
+ // clazz.getName() != classname if classname is "[L<name>;".
+ if (useCache)
+ cacheCtClass(clazz.getName(), clazz, false);
+
+ return clazz;
+ }
+
+ if (childFirstLookup)
+ {
+ if (parent != null)
+ {
+ clazz = clazz = performGet(parent, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ if (parentDomainPool != null)
+ {
+ clazz = clazz = performGet(parentDomainPool, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ }
+
+ return clazz;
+ }
+
+ private CtClass performGet(ClassPool pool, String classname)
+ {
+ try
+ {
+ //Want to avoid calling get() if possible since that creates NotFoundExceptions
+ //on misses which is expensive
+ if (pool instanceof AOPClassPool)
+ {
+ return ((AOPClassPool)pool).internalGet0(classname, true);
+ }
+ else
+ {
+ return pool.get(classname);
+ }
+ }
+ catch (NotFoundException e)
+ {
+ return null;
+ }
+ }
+
+
public CtClass getCached(String classname)
{
boolean trace = log.isTraceEnabled();
@@ -293,6 +385,10 @@
*/
private boolean isInstanceOfNoAnnotationURLClassLoader(ClassLoader loader)
{
+ if (loader == null)
+ {
+ return false;
+ }
Class<?> parent = loader.getClass();
while (parent != null)
{
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedVFSClassLoaderDomain.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedVFSClassLoaderDomain.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ScopedVFSClassLoaderDomain.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -40,10 +40,10 @@
public class ScopedVFSClassLoaderDomain extends ScopedClassLoaderDomain
{
WeakReference<ClassLoaderDomain> classLoaderDomainRef;
- VFSClassLoaderDomainRegistry registry;
+ DomainRegistry registry;
public ScopedVFSClassLoaderDomain(ClassLoader loader, String name, boolean parentDelegation, AspectManager manager, boolean parentFirst,
- ClassLoaderDomain classLoaderDomain, VFSClassLoaderDomainRegistry registry)
+ ClassLoaderDomain classLoaderDomain, DomainRegistry registry)
{
super(loader, name, parentDelegation, manager, parentFirst);
classLoaderDomainRef = new WeakReference<ClassLoaderDomain>(classLoaderDomain);
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderDomainRegistry.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderDomainRegistry.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderDomainRegistry.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -35,7 +35,7 @@
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
-public class VFSClassLoaderDomainRegistry
+public class VFSClassLoaderDomainRegistry implements DomainRegistry
{
final static ClassLoaderDomain domain = new ClassLoaderDomain("NOT_USED_PLACEHOLDER");
@@ -44,22 +44,73 @@
/** aopDomains by classloader domain */
private Map<ClassLoaderDomain, ScopedVFSClassLoaderDomain> aopDomainsByClassLoaderDomain = new WeakHashMap<ClassLoaderDomain, ScopedVFSClassLoaderDomain>();
+
+ /** parent deployment unit classloaders indexed by children */
+ private Map<ClassLoader, WeakReference<ClassLoader>> classLoaderUnitParents = new WeakHashMap<ClassLoader, WeakReference<ClassLoader>>();
+
+ /** Modules by classloader */
+ private Map<ClassLoader, WeakReference<Module>> classLoaderModules = new WeakHashMap<ClassLoader, WeakReference<Module>>();
+
+ private Map<ClassLoaderDomain, Integer> classLoaderDomainReferenceCounts = new WeakHashMap<ClassLoaderDomain, Integer>();
- synchronized void initMapsForLoader(ClassLoader loader, Module module, ScopedVFSClassLoaderDomain domain)
+ public synchronized boolean initMapsForLoader(ClassLoader loader, Module module, ScopedVFSClassLoaderDomain domain, ClassLoader parentUnitLoader)
{
+ if (loader == parentUnitLoader)
+ {
+ throw new IllegalArgumentException("initMapsForLoader() should only be called if parentUnitLoader is different from loader");
+ }
ClassLoaderSystem system = ClassLoaderSystem.getInstance();
String domainName = module.getDeterminedDomainName();
ClassLoaderDomain clDomain = system.getDomain(domainName);
- classLoaderDomainsByLoader.put(loader, new WeakReference<ClassLoaderDomain>(clDomain));
+ boolean ret = false;
+ if (!classLoaderDomainsByLoader.containsKey(loader))
+ {
+ Integer count = classLoaderDomainReferenceCounts.get(clDomain);
+ int cnt = count == null ? 0 : count.intValue();
+ classLoaderDomainReferenceCounts.put(clDomain, ++cnt);
+
+ classLoaderDomainsByLoader.put(loader, new WeakReference<ClassLoaderDomain>(clDomain));
+ classLoaderUnitParents.put(loader, new WeakReference<ClassLoader>(parentUnitLoader));
+ classLoaderModules.put(loader, new WeakReference<Module>(module));
+ ret = true;
+ }
if (domain != null)
{
aopDomainsByClassLoaderDomain.put(clDomain, domain);
}
+
+ return ret;
}
+
+ public synchronized void cleanupLoader(ClassLoader loader)
+ {
+ WeakReference<ClassLoaderDomain> clDomainRef = classLoaderDomainsByLoader.remove(loader);
+ ClassLoaderDomain clDomain = clDomainRef == null ? null : clDomainRef.get();
+ if (clDomain != null)
+ {
+ Integer count = classLoaderDomainReferenceCounts.get(clDomain);
+ int cnt = count == null ? 0 : count.intValue();
+ if (cnt > 0)
+ {
+ cnt--;
+ }
+ if (cnt == 0)
+ {
+ aopDomainsByClassLoaderDomain.remove(clDomain);
+ classLoaderDomainReferenceCounts.remove(clDomain);
+ }
+ else
+ {
+ classLoaderDomainReferenceCounts.put(clDomain, ++cnt);
+ }
+ classLoaderUnitParents.remove(loader);
+ classLoaderModules.remove(loader);
+ }
+ }
- synchronized Domain getRegisteredDomain(ClassLoader cl)
+ public synchronized Domain getRegisteredDomain(ClassLoader cl)
{
ClassLoaderDomain clDomain = getClassLoaderDomainForLoader(cl);
if (clDomain != null)
@@ -69,7 +120,7 @@
return null;
}
- synchronized ClassLoaderDomain getClassLoaderDomainForLoader(ClassLoader cl)
+ public synchronized ClassLoaderDomain getClassLoaderDomainForLoader(ClassLoader cl)
{
WeakReference<ClassLoaderDomain> clDomainRef = classLoaderDomainsByLoader.get(cl);
if (clDomainRef != null)
@@ -89,4 +140,24 @@
}
return null;
}
+
+ public synchronized ClassLoader getParentUnitLoader(ClassLoader loader)
+ {
+ WeakReference<ClassLoader> parentRef = classLoaderUnitParents.get(loader);
+ if (parentRef != null)
+ {
+ return parentRef.get();
+ }
+ return null;
+ }
+
+ public synchronized Module getModule(ClassLoader loader)
+ {
+ WeakReference<Module> moduleRef = classLoaderModules.get(loader);
+ if (moduleRef != null)
+ {
+ return moduleRef.get();
+ }
+ return null;
+ }
}
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderScopingPolicy.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderScopingPolicy.java 2008-10-16 14:05:29 UTC (rev 79578)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/VFSClassLoaderScopingPolicy.java 2008-10-16 14:16:44 UTC (rev 79579)
@@ -26,7 +26,6 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.Domain;
-import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
import org.jboss.aop.classpool.ExtraClassPoolFactoryParameters;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.logging.Logger;
@@ -36,23 +35,22 @@
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
-public class VFSClassLoaderScopingPolicy implements AOPClassLoaderScopingPolicy
+public class VFSClassLoaderScopingPolicy implements AOPClassLoaderScopingPolicyWithRegistry
{
static Logger log = Logger.getLogger(VFSClassLoaderScopingPolicy.class);
- VFSClassLoaderDomainRegistry registry = new VFSClassLoaderDomainRegistry();
+ DomainRegistry registry = new VFSClassLoaderDomainRegistry();
- VFSClassLoaderDomainRegistry getRegistry()
+ public DomainRegistry getRegistry()
{
return registry;
}
- void registerClassLoader(Module module, boolean isWar, ClassLoader loader)
+ public void registerClassLoader(Module module, ClassLoader loader)
{
//Need to pass some data through to the classpoolfactory here
Map<Object, Object> properties = new HashMap<Object, Object>();
//The module is needed by the JBoss5ClassPoolFactory, the legacy JBossClassPoolFactory will ignore this
properties.put(Module.class, module);
- properties.put("IsWebCl", isWar ? Boolean.TRUE : Boolean.FALSE);
ExtraClassPoolFactoryParameters.pushThreadProperties(properties);
try
{
More information about the jboss-cvs-commits
mailing list