[jboss-cvs] JBossAS SVN: r71164 - in trunk: bootstrap and 19 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 21 17:44:39 EDT 2008
Author: adrian at jboss.org
Date: 2008-03-21 17:44:39 -0400 (Fri, 21 Mar 2008)
New Revision: 71164
Removed:
trunk/j2se/src/main/org/jboss/mx/loading/LegacyDomainClassLoader.java
trunk/j2se/src/main/org/jboss/mx/loading/LoaderRepositoryDomain.java
trunk/jmx/src/main/org/jboss/mx/loading/ClassLoadingTaskDCL.java
trunk/jmx/src/main/org/jboss/mx/loading/DomainClassLoaderUCLImpl.java
trunk/jmx/src/main/org/jboss/mx/loading/LoadMgrDCL.java
trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCL.java
trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCLMBean.java
Modified:
trunk/aspects/build.xml
trunk/bootstrap/build.xml
trunk/build/build-distr.xml
trunk/build/build-thirdparty.xml
trunk/cluster/build.xml
trunk/connector/build.xml
trunk/deployment/build.xml
trunk/ejb3/build.xml
trunk/hibernate-int/build.xml
trunk/messaging/build.xml
trunk/profileservice/build.xml
trunk/security/build.xml
trunk/server/build.xml
trunk/spring-int/build.xml
trunk/system-jmx/build.xml
trunk/system/build.xml
trunk/testsuite/build.xml
trunk/tomcat/build.xml
trunk/varia/build.xml
trunk/webservices/build.xml
Log:
[JBAS-5121] - Beta releases of split up microcontainer projects in preparation for CRs
Modified: trunk/aspects/build.xml
===================================================================
--- trunk/aspects/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/aspects/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -76,6 +76,10 @@
<path refid="jboss.remoting.classpath"/>
<path refid="apache.xerces.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.cl.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
+ <path refid="jboss.jboss.mdr.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="jboss.aop.classpath"/>
Modified: trunk/bootstrap/build.xml
===================================================================
--- trunk/bootstrap/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/bootstrap/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -69,6 +69,7 @@
<path id="library.classpath">
<path refid="apache.xerces.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.common.core.classpath"/>
<path refid="jboss.common.logging.spi.classpath"/>
Modified: trunk/build/build-distr.xml
===================================================================
--- trunk/build/build-distr.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/build/build-distr.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1744,14 +1744,22 @@
<fileset dir="${jboss.integration.lib}">
<include name="jboss-classloading-spi.jar"/>
</fileset>
- <fileset dir="${jboss.microcontainer.lib}">
- <include name="jboss-aop-mc-int.jar"/>
+ <fileset dir="${jboss.jboss.reflect.lib}">
+ <include name="jboss-reflect.jar"/>
+ </fileset>
+ <fileset dir="${jboss.jboss.mdr.lib}">
+ <include name="jboss-mdr.jar"/>
+ </fileset>
+ <fileset dir="${jboss.jboss.man.lib}">
+ <include name="jboss-metatype.jar"/>
+ <include name="jboss-managed.jar"/>
+ </fileset>
+ <fileset dir="${jboss.jboss.cl.lib}">
<include name="jboss-classloader.jar"/>
<include name="jboss-classloading.jar"/>
<include name="jboss-classloading-vfs.jar"/>
- <include name="jboss-reflect.jar"/>
- <include name="jboss-mdr.jar"/>
- <include name="jboss-dependency.jar"/>
+ </fileset>
+ <fileset dir="${jboss.jboss.deployers.lib}">
<include name="jboss-deployers-client.jar"/>
<include name="jboss-deployers-client-spi.jar"/>
<include name="jboss-deployers-core.jar"/>
@@ -1761,8 +1769,10 @@
<include name="jboss-deployers-structure-spi.jar"/>
<include name="jboss-deployers-vfs.jar"/>
<include name="jboss-deployers-vfs-spi.jar"/>
- <include name="jboss-metatype.jar"/>
- <include name="jboss-managed.jar"/>
+ </fileset>
+ <fileset dir="${jboss.microcontainer.lib}">
+ <include name="jboss-aop-mc-int.jar"/>
+ <include name="jboss-dependency.jar"/>
<include name="jboss-kernel.jar"/>
</fileset>
<fileset dir="${jboss.jboss.vfs.lib}">
Modified: trunk/build/build-thirdparty.xml
===================================================================
--- trunk/build/build-thirdparty.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/build/build-thirdparty.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -113,7 +113,12 @@
<componentref name="jboss/jnpserver" version="5.0.0.Beta4"/>
<componentref name="jboss/messaging" version="1.4.1.Beta1"/>
<componentref name="jboss/metadata" version="1.0.0-SNAPSHOT"/>
- <componentref name="jboss/microcontainer" version="snapshot-temp"/>
+ <componentref name="jboss/jboss-cl" version="2.0.0.Beta11"/>
+ <componentref name="jboss/jboss-deployers" version="2.0.0.Beta11"/>
+ <componentref name="jboss/jboss-man" version="2.0.0.Beta12"/>
+ <componentref name="jboss/jboss-mdr" version="2.0.0.Beta12"/>
+ <componentref name="jboss/microcontainer" version="2.0.0.Beta11"/>
+ <componentref name="jboss/jboss-reflect" version="2.0.0.Beta12"/>
<componentref name="jboss/profiler/jvmti" version="1.0.0.CR5"/>
<componentref name="jboss/remoting" version="2.4.0.Beta2"/>
<componentref name="jboss/serialization" version="1.0.3.GA"/>
Modified: trunk/cluster/build.xml
===================================================================
--- trunk/cluster/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/cluster/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -83,6 +83,7 @@
<path refid="oswego.concurrent.classpath"/>
<path refid="jboss.remoting.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.integration.classpath"/>
<path refid="jboss.jboss.javaee.classpath"/>
Modified: trunk/connector/build.xml
===================================================================
--- trunk/connector/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/connector/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -80,6 +80,10 @@
<path refid="sun.javamail.classpath"/>
<path refid="quartz.quartz.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
+ <path refid="jboss.jboss.mdr.classpath"/>
+ <path refid="jboss.jboss.reflect.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="sun.jaxb.classpath"/>
Modified: trunk/deployment/build.xml
===================================================================
--- trunk/deployment/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/deployment/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -69,6 +69,8 @@
<!-- The combined library classpath -->
<path id="library.classpath">
<path refid="dom4j.dom4j.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
</path>
Modified: trunk/ejb3/build.xml
===================================================================
--- trunk/ejb3/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/ejb3/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -102,6 +102,8 @@
<path refid="jboss.security.int.classpath"/>
<path refid="jboss.serialization.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="quartz.quartz.classpath"/>
Modified: trunk/hibernate-int/build.xml
===================================================================
--- trunk/hibernate-int/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/hibernate-int/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -76,6 +76,7 @@
<path refid="hibernate3.classpath"/>
<path refid="odmg.classpath"/>
<path refid="cglib.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.integration.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
Deleted: trunk/j2se/src/main/org/jboss/mx/loading/LegacyDomainClassLoader.java
===================================================================
--- trunk/j2se/src/main/org/jboss/mx/loading/LegacyDomainClassLoader.java 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/j2se/src/main/org/jboss/mx/loading/LegacyDomainClassLoader.java 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1,842 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.mx.loading;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.CodeSource;
-import java.security.PermissionCollection;
-import java.security.Policy;
-import java.security.ProtectionDomain;
-import java.security.cert.Certificate;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Vector;
-import java.util.Collections;
-import java.util.Set;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.jboss.classloading.spi.ClassLoadingDomain;
-import org.jboss.classloading.spi.DomainClassLoader;
-import org.jboss.classloading.spi.Translator;
-import org.jboss.logging.Logger;
-import org.jboss.util.collection.SoftSet;
-
-import EDU.oswego.cs.dl.util.concurrent.ReentrantLock;
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-
-/**
- * A DomainClassLoader based on the legacy RepositoryClassLoader. This is for
- * portability of the legacy UCL/ULR.
- *
- * @see LoaderRepositoryDomain
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public abstract class LegacyDomainClassLoader extends URLClassLoader
- implements DomainClassLoader
-{
- // Constants -----------------------------------------------------
-
- /** The log */
- private static final Logger log = Logger.getLogger(LegacyDomainClassLoader.class);
-
- /** The value returned by {@link #getURLs}. */
- private static final URL[] EMPTY_URL_ARRAY = {};
-
- // Attributes -----------------------------------------------------
-
- /** Reference to the jboss5 ClassLoadingDomain */
- protected LoaderRepositoryDomain domain = null;
- /** The location where unregister is called from */
- protected Exception unregisterTrace;
-
- /** The relative order in which this class loader was added to the respository */
- private int addedOrder;
-
- /** The parent classloader */
- protected ClassLoader parent = null;
-
- /** Names of classes which have resulted in CNFEs in loadClassLocally */
- private Set classBlackList = Collections.synchronizedSet(new SoftSet());
- /** Names of resources that were not found in loadResourceLocally */
- private Set resourceBlackList = Collections.synchronizedSet(new HashSet());
- /** A HashMap<String, URL> for resource found in loadResourceLocally */
- private ConcurrentReaderHashMap resourceCache = new ConcurrentReaderHashMap();
-
- /** Lock */
- protected ReentrantLock loadLock = new ReentrantLock();
-
- /** A debugging variable used to track the recursive depth of loadClass() */
- protected int loadClassDepth;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- /**
- * Create a new LoaderDomainClassLoaderImpl
- *
- * @param urls the urls
- * @param parent the parent classloader
- */
- protected LegacyDomainClassLoader(URL[] urls, ClassLoader parent)
- {
- super(urls, parent);
- this.parent = parent;
- // Check the blacklist mode
- String mode = ClassToStringAction.getProperty("org.jboss.mx.loading.blacklistMode", null);
- if( mode == null || mode.equalsIgnoreCase("HashSet") )
- {
- classBlackList = Collections.synchronizedSet(new HashSet());
- resourceBlackList = Collections.synchronizedSet(new HashSet());
- }
- else if( mode.equalsIgnoreCase("SoftSet") )
- {
- classBlackList = Collections.synchronizedSet(new SoftSet());
- resourceBlackList = Collections.synchronizedSet(new SoftSet());
- }
- }
-
- // Public --------------------------------------------------------
-
- /**
- * Get the ObjectName
- *
- * @return the object name
- */
- public abstract ObjectName getObjectName() throws MalformedObjectNameException;
-
- public ClassLoadingDomain getDomain()
- {
- return domain;
- }
- public void setDomain(ClassLoadingDomain domain)
- {
- log.debug("setDomain, domain="+domain+", cl=" + this);
- this.domain = (LoaderRepositoryDomain) domain;
- }
-
- /**
- * Get the order this classloader was added to the domain
- *
- * @return the order
- */
- public int getAddedOrder()
- {
- return addedOrder;
- }
-
- /**
- * Set the order this classloader was added to the domain
- *
- * @param addedOrder the added order
- */
- public void setAddedOrder(int addedOrder)
- {
- this.addedOrder = addedOrder;
- }
-
- /**
- * Called to attempt to load a class from the set of URLs associated with this classloader.
- */
- public Class loadClassLocally(String name, boolean resolve)
- throws ClassNotFoundException
- {
- boolean trace = log.isTraceEnabled();
- if( trace )
- log.trace("loadClassLocally, " + this + " name=" + name);
- Class result = null;
- try
- {
- if (isClassBlackListed(name))
- {
- if( trace )
- log.trace("Class in blacklist, name="+name);
- throw new ClassNotFoundException("Class Not Found(blacklist): " + name);
- }
-
- try
- {
- result = super.loadClass(name, resolve);
- return result;
- }
- catch (ClassNotFoundException cnfe)
- {
- addToClassBlackList(name);
- // If this is an array class, use Class.forName to resolve it
- if( name.charAt(0) == '[' )
- {
- result = Class.forName(name, true, this);
- removeFromClassBlackList(name);
- return result;
- }
- if( trace )
- log.trace("CFNE: Adding to blacklist: "+name);
- throw cnfe;
- }
- }
- finally
- {
- if (trace)
- {
- if (result != null)
- log.trace("loadClassLocally, " + this + " name=" + name + " class=" + result + " cl=" + result.getClassLoader());
- else
- log.trace("loadClassLocally, " + this + " name=" + name + " not found");
- }
- }
- }
-
- /**
- * Provides the same functionality as {@link java.net.URLClassLoader#getResource}.
- */
- public URL getResourceLocally(String name)
- {
- URL resURL = (URL) resourceCache.get(name);
- if (resURL != null)
- return resURL;
- if (isResourceBlackListed(name))
- return null;
- resURL = super.getResource(name);
- if( log.isTraceEnabled() == true )
- log.trace("getResourceLocally("+this+"), name="+name+", resURL:"+resURL);
- if (resURL == null)
- addToResourceBlackList(name);
- else
- resourceCache.put(name, resURL);
- return resURL;
- }
- public URL loadResourceLocally(String name)
- {
- return getResourceLocally(name);
- }
-
- /**
- * Get the URL associated with the UCL.
- *
- * @return the url
- */
- public URL getURL()
- {
- URL[] urls = super.getURLs();
- if (urls.length > 0)
- return urls[0];
- else
- return null;
- }
-
- public void unregister()
- {
- log.debug("Unregistering cl=" + this);
- if (domain != null)
- domain.removeClassLoader(this);
- clearBlacklists();
- resourceCache.clear();
- domain = null;
- this.unregisterTrace = new Exception();
- }
-
- /**
- * This method simply invokes the super.getURLs() method to access the
- * list of URLs that make up the DomainClassLoaderImpl classpath.
- *
- * @return the urls that make up the classpath
- */
- public URL[] getClasspath()
- {
- return super.getURLs();
- }
-
- /**
- * Black list a class
- *
- * @param name the name of the class
- */
- public void addToClassBlackList(String name)
- {
- classBlackList.add(name);
- }
-
- /**
- * Remove class from black list
- *
- * @param name the name of the class
- */
- public void removeFromClassBlackList(String name)
- {
- classBlackList.remove(name);
- }
-
- /**
- * Is the class black listed?
- *
- * @param name the name of the class
- * @return true when the class is black listed, false otherwise
- */
- public boolean isClassBlackListed(String name)
- {
- return classBlackList.contains(name);
- }
-
- /**
- * Clear any class black list.
- */
- public void clearClassBlackList()
- {
- classBlackList.clear();
- }
-
- /**
- * Black list a resource
- *
- * @param name the name of the resource
- */
- public void addToResourceBlackList(String name)
- {
- resourceBlackList.add(name);
- }
-
- /**
- * Remove resource from black list
- *
- * @param name the name of the resource
- */
- public void removeFromResourceBlackList(String name)
- {
- resourceBlackList.remove(name);
- }
-
- /**
- * Is the resource black listed?
- *
- * @param name the name of the resource
- * @return true when the resource is black listed, false otherwise
- */
- public boolean isResourceBlackListed(String name)
- {
- return resourceBlackList.contains(name);
- }
-
- /**
- * Clear any resource blacklist.
- */
- public void clearResourceBlackList()
- {
- resourceBlackList.clear();
- }
-
- /**
- * Clear all blacklists
- */
- public void clearBlacklists()
- {
- clearClassBlackList();
- clearResourceBlackList();
- }
-
-
- // URLClassLoader overrides --------------------------------------
-
- /** The only caller of this method should be the VM initiated
- * loadClassInternal() method. This method attempts to acquire the
- * UnifiedLoaderRepository2 lock and then asks the domain to
- * load the class.
- *
- * <p>Forwards request to {@link LoaderRepository}.
- */
- public Class loadClass(String name, boolean resolve)
- throws ClassNotFoundException
- {
- boolean trace = log.isTraceEnabled();
- if (trace)
- log.trace("loadClass " + this + " name=" + name+", loadClassDepth="+loadClassDepth);
- Class clazz = null;
- try
- {
- if (domain != null)
- {
- clazz = domain.getCachedClass(name);
- if (clazz != null)
- {
- if( log.isTraceEnabled() )
- {
- StringBuffer buffer = new StringBuffer("Loaded class from cache, ");
- ClassToStringAction.toString(clazz, buffer);
- log.trace(buffer.toString());
- }
- return clazz;
- }
- }
- clazz = loadClassImpl(name, resolve, Integer.MAX_VALUE);
- return clazz;
- }
- finally
- {
- if (trace)
- {
- if (clazz != null)
- log.trace("loadClass " + this + " name=" + name + " class=" + clazz + " cl=" + clazz.getClassLoader());
- else
- log.trace("loadClass " + this + " name=" + name + " not found");
- }
- }
- }
-
- /** The only caller of this method should be the VM initiated
- * loadClassInternal() method. This method attempts to acquire the
- * UnifiedLoaderRepository2 lock and then asks the domain to
- * load the class.
- *
- * <p>Forwards request to {@link LoaderRepository}.
- */
- public Class loadClassBefore(String name)
- throws ClassNotFoundException
- {
- boolean trace = log.isTraceEnabled();
- if (trace)
- log.trace("loadClassBefore " + this + " name=" + name);
- Class clazz = null;
- try
- {
- clazz = loadClassImpl(name, false, addedOrder);
- return clazz;
- }
- finally
- {
- if (trace)
- {
- if (clazz != null)
- log.trace("loadClassBefore " + this + " name=" + name + " class=" + clazz + " cl=" + clazz.getClassLoader());
- else
- log.trace("loadClassBefore " + this + " name=" + name + " not found");
- }
- }
- }
-
- public abstract Class loadClassImpl(String name, boolean resolve, int stopAt)
- throws ClassNotFoundException;
-
- /**
- * Attempts to load the resource from its URL and if not found
- * forwards to the request to {@link LoaderRepository}.
- */
- public URL getResource(String name)
- {
- if (domain != null)
- return domain.getResource(name, this);
- return null;
- }
-
- /** Find all resource URLs for the given name. This overrides the
- * URLClassLoader version to look for resources in the domain.
- *
- * @param name the name of the resource
- * @return Enumeration<URL>
- * @throws java.io.IOException
- */
- public Enumeration<URL> findResources(String name) throws IOException
- {
- Vector<URL> resURLs = new Vector<URL>();
- if( domain == null )
- {
- String msg = "Invalid use of destroyed classloader, UCL destroyed at:";
- IOException e = new IOException(msg);
- e.initCause(this.unregisterTrace);
- throw e;
- }
- domain.getResources(name, this, resURLs);
- return resURLs.elements();
- }
-
- /**
- * Provides the same functionality as {@link java.net.URLClassLoader#findResources}.
- */
- public Enumeration findResourcesLocally(String name) throws IOException
- {
- return super.findResources(name);
- }
-
- /** Called by loadClassLocally to find the requested class within this
- * class loaders class path.
- *
- * @param name the name of the class
- * @return the resulting class
- * @exception ClassNotFoundException if the class could not be found
- */
- protected Class findClass(String name) throws ClassNotFoundException
- {
- boolean trace = log.isTraceEnabled();
- if( trace )
- log.trace("findClass, name="+name);
- if (isClassBlackListed(name))
- {
- if( trace )
- log.trace("Class in blacklist, name="+name);
- throw new ClassNotFoundException("Class Not Found(blacklist): " + name);
- }
-
- Translator translator = domain.getTranslator();
- if (translator != null)
- {
- // Obtain the transformed class bytecode
- try
- {
- // Obtain the raw bytecode from the classpath
- URL classUrl = getClassURL(name);
- byte[] rawcode = loadByteCode(classUrl);
- URL codeSourceUrl = getCodeSourceURL(name, classUrl);
- ProtectionDomain pd = getProtectionDomain(codeSourceUrl);
- byte[] bytecode = translator.transform(this, name, null, pd, rawcode);
- // If there was no transform use the raw bytecode
- if( bytecode == null )
- bytecode = rawcode;
- // Define the class package and instance
- definePackage(name);
- return defineClass(name, bytecode, 0, bytecode.length, pd);
- }
- catch(ClassNotFoundException e)
- {
- throw e;
- }
- catch (Throwable ex)
- {
- throw new ClassNotFoundException(name, ex);
- }
- }
-
- Class clazz = null;
- try
- {
- clazz = findClassLocally(name);
- }
- catch(ClassNotFoundException e)
- {
- if( trace )
- log.trace("CFNE: Adding to blacklist: "+name);
- addToClassBlackList(name);
- throw e;
- }
- return clazz;
- }
-
- /**
- * Find the class
- *
- * @param name the name of the class
- * @return the class
- */
- protected Class findClassLocally(String name) throws ClassNotFoundException
- {
- return super.findClass(name);
- }
-
- /**
- * Define the package for the class if not already done
- *
- * @todo this properly
- * @param className the class name
- */
- protected void definePackage(String className)
- {
- int i = className.lastIndexOf('.');
- if (i == -1)
- return;
-
- try
- {
- definePackage(className.substring(0, i), null, null, null, null, null, null, null);
- }
- catch (IllegalArgumentException alreadyDone)
- {
- }
- }
-
- /** Append the given url to the URLs used for class and resource loading
- * @param url the URL to load from
- */
- public void addURL(URL url)
- {
- if( url == null )
- throw new IllegalArgumentException("url cannot be null");
-
- if( domain.addClassLoaderURL(this, url) == true )
- {
- log.debug("Added url: "+url+", to ucl: "+this);
- // Strip any query parameters
- String query = url.getQuery();
- if( query != null )
- {
- String ext = url.toExternalForm();
- String ext2 = ext.substring(0, ext.length() - query.length() - 1);
- try
- {
- url = new URL (ext2);
- }
- catch(MalformedURLException e)
- {
- log.warn("Failed to strip query from: "+url, e);
- }
- }
- super.addURL(url);
- clearBlacklists();
- }
- else if( log.isTraceEnabled() )
- {
- log.trace("Ignoring duplicate url: "+url+", for ucl: "+this);
- }
- }
-
- public Package getPackage(String name)
- {
- return super.getPackage(name);
- }
-
- public Package[] getPackages()
- {
- return super.getPackages();
- }
-
- // Object overrides ----------------------------------------------
-
- /**
- * This is here to document that this must delegate to the
- * super implementation to perform identity based equality. Using
- * URL based equality caused conflicts with the Class.forName(String,
- * boolean, ClassLoader).
- */
- public final boolean equals(Object other)
- {
- return super.equals(other);
- }
-
- /**
- * This is here to document that this must delegate to the
- * super implementation to perform identity based hashing. Using
- * URL based hashing caused conflicts with the Class.forName(String,
- * boolean, ClassLoader).
- */
- public final int hashCode()
- {
- return super.hashCode();
- }
-
- /**
- * Returns a string representation.
- */
- public String toString()
- {
- return super.toString() + "{ url=" + getURL() + " }";
- }
-
- // Protected -----------------------------------------------------
-
- /** Attempt to acquire the class loading lock. This lock must be acquired
- * before a thread enters the class loading task loop in loadClass. This
- * method maintains any interrupted state of the calling thread.
- *@see #loadClass(String, boolean)
- */
- protected boolean attempt(long waitMS)
- {
- boolean acquired = false;
- boolean trace = log.isTraceEnabled();
- // Save and clear the interrupted state of the incoming thread
- boolean threadWasInterrupted = Thread.interrupted();
- try
- {
- acquired = loadLock.attempt(waitMS);
- }
- catch(InterruptedException e)
- {
- }
- finally
- {
- // Restore the interrupted state of the thread
- if( threadWasInterrupted )
- Thread.currentThread().interrupt();
- }
- if( trace )
- log.trace("attempt("+loadLock.holds()+") was: "+acquired+" for :"+this);
- return acquired;
- }
-
- /** Acquire the class loading lock. This lock must be acquired
- * before a thread enters the class loading task loop in loadClass.
- *@see #loadClass(String, boolean)
- */
- protected void acquire()
- {
- // Save and clear the interrupted state of the incoming thread
- boolean threadWasInterrupted = Thread.interrupted();
- try
- {
- loadLock.acquire();
- }
- catch(InterruptedException e)
- {
- }
- finally
- {
- // Restore the interrupted state of the thread
- if( threadWasInterrupted )
- Thread.currentThread().interrupt();
- }
- if( log.isTraceEnabled() )
- log.trace("acquired("+loadLock.holds()+") for :"+this);
- }
- /** Release the class loading lock previous acquired through the acquire
- * method.
- */
- protected void release()
- {
- if( log.isTraceEnabled() )
- log.trace("release("+loadLock.holds()+") for :"+this);
- loadLock.release();
- if( log.isTraceEnabled() )
- log.trace("released, holds: "+loadLock.holds());
- }
-
- /** Obtain the bytecode for the indicated class from this class loaders
- * classpath.
- *
- * @param classname
- * @return the bytecode array if found
- * @exception ClassNotFoundException - if the class resource could not
- * be found
- */
- protected byte[] loadByteCode(String classname)
- throws ClassNotFoundException, IOException
- {
- byte[] bytecode = null;
- URL classURL = getClassURL(classname);
-
- // Load the class bytecode
- InputStream is = null;
- try
- {
- is = classURL.openStream();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] tmp = new byte[1024];
- int read = 0;
- while( (read = is.read(tmp)) > 0 )
- {
- baos.write(tmp, 0, read);
- }
- bytecode = baos.toByteArray();
- }
- finally
- {
- if( is != null )
- is.close();
- }
-
- return bytecode;
- }
-
- /** Obtain the bytecode for the indicated class from this class loaders
- * classpath.
- *
- * @param classURL
- * @return the bytecode array if found
- * @exception ClassNotFoundException - if the class resource could not
- * be found
- */
- protected byte[] loadByteCode(URL classURL)
- throws ClassNotFoundException, IOException
- {
- byte[] bytecode = null;
- // Load the class bytecode
- InputStream is = null;
- try
- {
- is = classURL.openStream();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] tmp = new byte[1024];
- int read = 0;
- while( (read = is.read(tmp)) > 0 )
- {
- baos.write(tmp, 0, read);
- }
- bytecode = baos.toByteArray();
- }
- finally
- {
- if( is != null )
- is.close();
- }
-
- return bytecode;
- }
-
- /**
- * Determine the protection domain. If we are a copy of the original
- * deployment, use the original url as the codebase.
- * @return the protection domain
- * @todo certificates and principles?
- */
- protected ProtectionDomain getProtectionDomain(URL codesourceUrl)
- {
- Certificate certs[] = null;
- CodeSource cs = new CodeSource(codesourceUrl, certs);
- PermissionCollection permissions = Policy.getPolicy().getPermissions(cs);
- if (log.isTraceEnabled())
- log.trace("getProtectionDomain, url=" + codesourceUrl +
- " codeSource=" + cs + " permissions=" + permissions);
- return new ProtectionDomain(cs, permissions);
- }
-
- // Package Private -----------------------------------------------
-
- // Private -------------------------------------------------------
-
- private URL getCodeSourceURL(String classname, URL classURL) throws java.net.MalformedURLException
- {
- String classRsrcName = classname.replace('.', '/') + ".class";
- String urlAsString = classURL.toString();
- int idx = urlAsString.indexOf(classRsrcName);
- if (idx == -1) return classURL;
- urlAsString = urlAsString.substring(0, idx);
- return new URL(urlAsString);
- }
-
- private URL getClassURL(String classname) throws ClassNotFoundException
- {
- String classRsrcName = classname.replace('.', '/') + ".class";
- URL classURL = this.getResourceLocally(classRsrcName);
- if( classURL == null )
- {
- String msg = "Failed to find: "+classname+" as resource: "+classRsrcName;
- throw new ClassNotFoundException(msg);
- }
- return classURL;
- }
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/j2se/src/main/org/jboss/mx/loading/LoaderRepositoryDomain.java
===================================================================
--- trunk/j2se/src/main/org/jboss/mx/loading/LoaderRepositoryDomain.java 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/j2se/src/main/org/jboss/mx/loading/LoaderRepositoryDomain.java 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1,263 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.mx.loading;
-
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-
-import org.jboss.classloading.spi.ClassLoadingDomain;
-import org.jboss.classloading.spi.DomainClassLoader;
-import org.jboss.classloading.spi.Translator;
-import org.jboss.logging.Logger;
-import org.jboss.mx.server.ServerConstants;
-
-import java.net.URL;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Vector;
-
-/**
- * Port of legacy LoaderRepository to a ClassLoadingDomain base.
- *
- * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>.
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public abstract class LoaderRepositoryDomain
- implements ServerConstants, ClassLoadingDomain
-{
-
- // Attributes ----------------------------------------------------
- protected static Vector loaders = new Vector();
- protected static LoaderRepositoryDomain instance = null;
- protected Translator translator = null;
-
- /** The loaded classes cache, HashMap<String, Class>.
- * Access synchronized via this.classes monitor.
- */
- private ConcurrentReaderHashMap classes = new ConcurrentReaderHashMap();
-
-
- /**
- * Native signature to class map
- */
- private static HashMap nativeClassBySignature;
-
- // Static --------------------------------------------------------
- private static final Logger log = Logger.getLogger(LoaderRepositoryDomain.class);
-
- /**
- * Construct the native class map
- */
- static
- {
- nativeClassBySignature = new HashMap();
- nativeClassBySignature.put("boolean", boolean.class);
- nativeClassBySignature.put("byte", byte.class);
- nativeClassBySignature.put("char", char.class);
- nativeClassBySignature.put("double", double.class);
- nativeClassBySignature.put("float", float.class);
- nativeClassBySignature.put("int", int.class);
- nativeClassBySignature.put("long", long.class);
- nativeClassBySignature.put("short", short.class);
- nativeClassBySignature.put("void", void.class);
-
- nativeClassBySignature.put("boolean[]", boolean[].class);
- nativeClassBySignature.put("byte[]", byte[].class);
- nativeClassBySignature.put("char[]", char[].class);
- nativeClassBySignature.put("double[]", double[].class);
- nativeClassBySignature.put("float[]", float[].class);
- nativeClassBySignature.put("int[]", int[].class);
- nativeClassBySignature.put("long[]", long[].class);
- nativeClassBySignature.put("short[]", short[].class);
- }
-
- // Public --------------------------------------------------------
- public Vector getLoaders()
- {
- return loaders;
- }
-
- public URL[] getURLs()
- {
- return null;
- }
-
- public Class getCachedClass(String classname)
- {
- return (Class)classes.get(classname);
- }
-
- public Translator getTranslator()
- {
- return translator;
- }
-
- public void setTranslator(Translator t)
- {
- translator = t;
- }
-
- /**
- * Compare two loader repository, by default we do no special ordering
- *
- * @param lr the loader repository
- * @return -1, 0, 1 depending upon the order
- */
- public int compare(LoaderRepositoryDomain lr)
- {
- if (lr == this)
- return 0;
- else
- return 1;
- }
-
- // BEGIN ClassLoadingDomain **************************************************************************************
-
- /**
- * Loads a class from the repository. This method attempts to load the class
- * using all the classloader registered to the repository.
- *
- * @param className the class to load
- * @return the found class
- * @exception ClassNotFoundException when there is no such class
- */
- public abstract Class loadClass(String className) throws ClassNotFoundException;
- /**
- * Load a class from this domain
- *
- * @param name the class to load
- * @param resolve whether to resolve the class
- * @param classLoader the requesting classloader
- * @return the class
- * @throws ClassNotFoundException when the class is not found
- */
- public abstract Class loadClass(String name, boolean resolve, DomainClassLoader classLoader) throws ClassNotFoundException;
-
- // END ClassLoadingDomain ****************************************************************************************
-
- /** Create DomainClassLoader and optionally add it to the repository
- * @param url the URL to use for class loading
- * @param addToRepository a flag indicating if the CL should be added to
- * the repository
- * @return the UCL instance
- * @throws Exception
- */
- public abstract DomainClassLoader newClassLoader(final URL url, boolean addToRepository)
- throws Exception;
- /** Create DomainClassLoader and optionally add it to the repository
- * @param url the URL to use for class loading
- * @param origURL an orignal URL to use as the URL for the CL CodeSource.
- * This is useful when the url is a local copy that is difficult to use for
- * security policy writing.
- * @param addToRepository a flag indicating if the CL should be added to
- * the repository
- * @return the CL instance
- * @throws Exception
- */
- public abstract DomainClassLoader newClassLoader(final URL url, final URL origURL,
- boolean addToRepository)
- throws Exception;
-
- /** Find a resource URL for the given name
- *
- * @param name the resource name
- * @param cl the requesting class loader
- * @return The resource URL if found, null otherwise
- */
- public abstract URL getResource(String name, DomainClassLoader cl);
- /** Find all resource URLs for the given name. Since this typically
- * entails an exhuastive search of the repository it can be a relatively
- * slow operation.
- *
- * @param name the resource name
- * @param cl the requesting class loader
- * @param urls a list into which the located resource URLs will be placed
- */
- public abstract void getResources(String name, DomainClassLoader cl, List urls);
-
- /** Add a class loader to the repository
- */
- public abstract void addClassLoader(DomainClassLoader cl);
- /** Update the set of URLs known to be associated with a previously added
- * class loader.
- *
- * @param cl
- * @param url
- */
- public abstract boolean addClassLoaderURL(DomainClassLoader cl, URL url);
- /** Remove a cladd loader from the repository.
- * @param cl
- */
- public abstract void removeClassLoader(DomainClassLoader cl);
-
- /**
- * Return the class of a java native type
- * @return the class, or null if className is not a native class name
- */
- public static final Class getNativeClassForName(String className)
- {
- // Check for native classes
- return (Class)nativeClassBySignature.get(className);
- }
-
- /**
- * Allow subclasses to override the ordering
- *
- * @param lr the loader repository
- * @return -1, 0, 1 depending upon the order
- */
- protected int reverseCompare(LoaderRepositoryDomain lr)
- {
- return 0;
- }
-
- /**
- * Add a class to the the cache
- */
- void cacheLoadedClass(String name, Class cls, DomainClassLoader cl)
- {
- synchronized( classes )
- {
- // Update the global cache
- classes.put(name, cls);
- if( log.isTraceEnabled() )
- {
- log.trace("cacheLoadedClass, classname: "+name+", class: "+cls
- +", cl: "+cl);
- }
-
- /**
- * TODO: Adding this implementation is a hack for jmx 1.2 checkin.
- * Had to add this because need getCachedClass() to work.
- * However, this method does not add loaded classes to collection
- * to be unloaded when called to remove classloader.
- * Hopefully this will be a short term workaround.
- * Contact telrod at e2technologies.net if you have questions. -TME
- */
- }
- }
-
- void clear()
- {
- classes.clear();
- }
-}
Deleted: trunk/jmx/src/main/org/jboss/mx/loading/ClassLoadingTaskDCL.java
===================================================================
--- trunk/jmx/src/main/org/jboss/mx/loading/ClassLoadingTaskDCL.java 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/jmx/src/main/org/jboss/mx/loading/ClassLoadingTaskDCL.java 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1,254 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.mx.loading;
-
-import java.security.CodeSource;
-import java.security.ProtectionDomain;
-import java.util.Comparator;
-import java.io.StringWriter;
-import java.io.PrintWriter;
-
-import org.jboss.logging.Logger;
-
-/** An encapsulation of a UCL3.loadClass task.
- * @author Scott.Stark at jboss.org
- * @version $Revision$
-*/
-public class ClassLoadingTaskDCL
-{
- protected static Logger log = Logger.getLogger(ClassLoadingTaskDCL.class);
- protected static Comparator taskComparator = new ThreadTaskComparator();
-
- public static final int FOUND_CLASS_LOADER = 1;
- public static final int NEXT_EVENT = 2;
- public static final int WAIT_ON_EVENT = 3;
- public static final int FINISHED = 4;
-
- protected String classname;
- protected Thread requestingThread;
- protected DomainClassLoaderUCLImpl requestingClassLoader;
- protected Class loadedClass;
- protected int loadOrder = Integer.MAX_VALUE;
- protected int stopOrder = Integer.MAX_VALUE;
- protected Throwable loadException;
- /** The number of ThreadTasks remaining */
- protected int threadTaskCount;
- /** The state of the requestingThread */
- protected int state;
- /** The Logger trace level flag */
- protected boolean trace;
-
- protected int numCCE;
-
- /** Compare ThreadTask first based on their order ivar, and then the
- * relative ordering with which their UCLs were added to the ULR.
- */
- static class ThreadTaskComparator implements Comparator
- {
- public int compare(Object o1, Object o2)
- {
- ThreadTask t1 = (ThreadTask) o1;
- ThreadTask t2 = (ThreadTask) o2;
- int compare = t1.order - t2.order;
- /*
- if( compare == 0 )
- {
- compare = t1.ucl.getAddedOrder() - t2.ucl.getAddedOrder();
- }
- */
- return compare;
- }
- }
-
- /** An ecapsulation of a <Thread, UCL3> task used when requestingClassLoader
- * needs to ask another UCL3 to perform the class loading.
- */
- class ThreadTask
- {
- /** The class loader for the classname package */
- DomainClassLoaderUCLImpl ucl;
- /** The thread that owns the ucl monitor */
- Thread t;
- /** The relative order of the task. If o0 < o1 then the class loaded
- by task o0 is preferred to o1.
- */
- int order;
- boolean releaseInNextTask;
-
- ThreadTask(DomainClassLoaderUCLImpl ucl, Thread t, int order,
- boolean releaseInNextTask)
- {
- this.ucl = ucl;
- this.t = t;
- this.order = order;
- this.releaseInNextTask = releaseInNextTask;
- }
-
- public String toString()
- {
- return "{t="+t+", ucl="+ucl+", name="+classname
- +", requestingThread="+requestingThread
- +", order="+order+", releaseInNextTask="+releaseInNextTask
- +"}";
- }
-
- String getClassname()
- {
- return classname;
- }
- Class getLoadedClass()
- {
- return loadedClass;
- }
- ClassLoadingTaskDCL getLoadTask()
- {
- return ClassLoadingTaskDCL.this;
- }
-
- void run() throws ClassNotFoundException
- {
- Class theClass = null;
- try
- {
- if( loadedClass == null )
- {
- theClass = ucl.loadClassLocally(classname, false);
- setLoadedClass(theClass, order);
- }
- else if( trace )
- {
- log.trace("Already found class("+loadedClass+"), skipping loadClassLocally");
- }
- }
- finally
- {
- ;//setLoadedClass(theClass, order);
- }
- }
- }
-
- protected ClassLoadingTaskDCL(String classname, DomainClassLoaderUCLImpl requestingClassLoader,
- Thread requestingThread)
- {
- this(classname, requestingClassLoader, requestingThread, Integer.MAX_VALUE);
- }
-
- protected ClassLoadingTaskDCL(String classname, DomainClassLoaderUCLImpl requestingClassLoader,
- Thread requestingThread, int stopAt)
- {
- this.requestingThread = requestingThread;
- this.requestingClassLoader = requestingClassLoader;
- this.classname = classname;
- this.stopOrder = stopAt;
- this.trace = log.isTraceEnabled();
- }
-
- public String toString()
- {
- StringBuffer buffer = new StringBuffer(super.toString());
- buffer.append('{');
- buffer.append("classname: "+classname);
- buffer.append(", requestingThread: "+requestingThread);
- buffer.append(", requestingClassLoader: "+requestingClassLoader);
- buffer.append(", loadedClass: "+loadedClass);
- ClassToStringAction.toString(loadedClass, buffer);
- buffer.append(", loadOrder: "+loadOrder);
- buffer.append(", loadException: "+loadException);
- buffer.append(", threadTaskCount: "+threadTaskCount);
- buffer.append(", state: "+state);
- buffer.append(", #CCE: "+numCCE);
- buffer.append('}');
- if( trace && loadException != null )
- {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- loadException.printStackTrace(pw);
- buffer.append("loadException details:\n");
- buffer.append(sw.toString());
- }
- return buffer.toString();
- }
-
- ThreadTask newThreadTask(DomainClassLoaderUCLImpl ucl, Thread t, int order,
- boolean reschedule, boolean releaseInNextTask)
- {
- // Only update the threadTaskCount if this is not a reschedule
- if( reschedule == false )
- threadTaskCount ++;
- return new ThreadTask(ucl, t, order, releaseInNextTask);
- }
-
- synchronized void setLoadError(Throwable t)
- {
- this.threadTaskCount--;
- if( trace )
- log.trace("setLoadedError, error="+t);
- loadException = t;
- }
-
-
- /** This is called from run on success or failure to mark the end
- * of the load attempt. This must decrement the threadTaskCount or
- * the ClassLoadingTaskDCL will never complete.
- */
- private synchronized void setLoadedClass(Class theClass, int order)
- {
- this.threadTaskCount --;
- if( trace )
- log.trace("setLoadedClass, theClass="+theClass+", order="+order);
-
- // Warn about duplicate classes
- if( this.loadedClass != null && order == loadOrder && theClass != null )
- {
- StringBuffer tmp = new StringBuffer("Duplicate class found: "+classname);
- tmp.append('\n');
- ProtectionDomain pd = this.loadedClass.getProtectionDomain();
- CodeSource cs = pd != null ? pd.getCodeSource() : null;
- tmp.append("Current CS: "+cs);
- tmp.append('\n');
- pd = theClass.getProtectionDomain();
- cs = pd != null ? pd.getCodeSource() : null;
- tmp.append("Duplicate CS: "+cs);
- log.warn(tmp.toString());
- }
-
- // Accept the lowest order source of the class
- if( theClass != null )
- {
- if( loadedClass == null || order <= loadOrder )
- {
- this.loadedClass = theClass;
- this.loadOrder = order;
- }
- else
- {
- ProtectionDomain pd = this.loadedClass.getProtectionDomain();
- CodeSource cs = pd != null ? pd.getCodeSource() : null;
- ProtectionDomain pd2 = theClass.getProtectionDomain();
- CodeSource cs2 = pd != null ? pd2.getCodeSource() : null;
- log.debug("Ignoring source of: "+classname+" from CodeSource: "+cs2
- +", due to order("+order+">="+loadOrder+"), "
- +"accepted CodeSource: "+cs);
- }
- }
- }
-}
Deleted: trunk/jmx/src/main/org/jboss/mx/loading/DomainClassLoaderUCLImpl.java
===================================================================
--- trunk/jmx/src/main/org/jboss/mx/loading/DomainClassLoaderUCLImpl.java 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/jmx/src/main/org/jboss/mx/loading/DomainClassLoaderUCLImpl.java 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1,221 +0,0 @@
-package org.jboss.mx.loading;
-
-import java.net.URL;
-import java.security.CodeSource;
-import java.security.Permission;
-import java.security.PermissionCollection;
-import java.security.Policy;
-import java.security.ProtectionDomain;
-import java.util.Enumeration;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.jboss.logging.Logger;
-
-/**
-* A port of the UnifiedClassLoader3 to a DomainClassLoader
-*
-* @author <a href="marc.fleury at jboss.org">Marc Fleury</a>
-* @author <a href="christoph.jung at jboss.org">Christoph G. Jung</a>
-* @author <a href="scott.stark at jboss.org">Scott Stark</a>
-* @author <a href="juha at jboss.org">Juha Lindfors</a>
-* @author <a href="bill at jboss.org">Bill Burke</a>
-* @version $Revision: 44243 $
-*/
-public class DomainClassLoaderUCLImpl extends LegacyDomainClassLoader
- implements UnifiedClassLoaderMBean
-{
- // Static --------------------------------------------------------
-
- private static final Logger log = Logger.getLogger(DomainClassLoaderUCLImpl.class);
-
- // Attributes ----------------------------------------------------
-
- // Constructors --------------------------------------------------
- /**
- * Construct a DomainClassLoaderUCLImpl with the given classpath and register
- * it to the given repository.
- * @param cp - the loader classpath
- * @param repository - the repository this classloader delegates to
- */
- public DomainClassLoaderUCLImpl(URL[] cp, LoaderRepositoryDomain repository)
- {
- super(cp, null);
-
- // register this loader to the given repository
- repository.addClassLoader(this);
- }
-
- // Public --------------------------------------------------------
-
- /** Obtain the ObjectName under which the UCL can be registered with the
- JMX server. This creates a name of the form "jmx.loading:UCL=hashCode"
- since we don't currently care that UCL be easily queriable.
- */
- public ObjectName getObjectName() throws MalformedObjectNameException
- {
- String name = "jmx.loading:UCL="+Integer.toHexString(super.hashCode());
- return new ObjectName(name);
- }
-
- /**
- * Get the class loader package names from the class loader URLs
- */
- public String[] getPackageNames()
- {
- UnifiedLoaderRepositoryDCL ulr = (UnifiedLoaderRepositoryDCL) domain;
- return ulr.getPackageNames(this);
- }
-
- public void unregister()
- {
- super.unregister();
- }
-
- public synchronized Class loadClassImpl(String name, boolean resolve, int stopAt)
- throws ClassNotFoundException
- {
- loadClassDepth ++;
- boolean trace = log.isTraceEnabled();
-
- if( trace )
- log.trace("loadClassImpl, name="+name+", resolve="+resolve);
- if( domain == null )
- {
- // If we have been undeployed we can still try locally
- try
- {
- return super.loadClass(name, resolve);
- }
- catch (ClassNotFoundException ignored)
- {
- }
- String msg = "Invalid use of destroyed classloader, UCL destroyed at:";
- throw new ClassNotFoundException(msg, this.unregisterTrace);
- }
-
- /* Since loadClass can be called from loadClassInternal with the monitor
- already held, we need to determine if there is a ClassLoadingTask
- which requires this UCL. If there is, we release the UCL monitor
- so that the ClassLoadingTask can use the UCL.
- */
- boolean acquired = attempt(1);
- while( acquired == false )
- {
- /* Another thread needs this UCL to load a class so release the
- monitor acquired by the synchronized method. We loop until
- we can acquire the class loading lock.
- */
- try
- {
- if( trace )
- log.trace("Waiting for loadClass lock");
- this.wait();
- }
- catch(InterruptedException ignore)
- {
- }
- acquired = attempt(1);
- }
-
- ClassLoadingTaskDCL task = null;
- try
- {
- Thread t = Thread.currentThread();
- // Register this thread as owning this UCL
- if( loadLock.holds() == 1 )
- LoadMgrDCL.registerLoaderThread(this, t);
-
- // Create a class loading task and submit it to the repository
- task = new ClassLoadingTaskDCL(name, this, t, stopAt);
- /* Process class loading tasks needing this UCL until our task has
- been completed by the thread owning the required UCL(s).
- */
- UnifiedLoaderRepositoryDCL repository = (UnifiedLoaderRepositoryDCL) domain;
- if( LoadMgrDCL.beginLoadTask(task, repository) == false )
- {
- while( task.threadTaskCount != 0 )
- {
- try
- {
- LoadMgrDCL.nextTask(t, task, repository);
- }
- catch(InterruptedException e)
- {
- // Abort the load or retry?
- break;
- }
- }
- }
- }
- finally
- {
- // Unregister as the UCL owner to reschedule any remaining load tasks
- if( loadLock.holds() == 1 )
- LoadMgrDCL.endLoadTask(task);
- // Notify any threads waiting to use this UCL
- this.release();
- this.notifyAll();
- loadClassDepth --;
- }
-
- if( task.loadedClass == null )
- {
- if( task.loadException instanceof ClassNotFoundException )
- throw (ClassNotFoundException) task.loadException;
- else if( task.loadException instanceof NoClassDefFoundError )
- throw (NoClassDefFoundError) task.loadException;
- else if( task.loadException != null )
- {
- if( log.isTraceEnabled() )
- log.trace("Unexpected error during load of:"+name, task.loadException);
- String msg = "Unexpected error during load of: "+name
- + ", msg="+task.loadException.getMessage();
- ClassNotFoundException cnfe = new ClassNotFoundException(msg, task.loadException);
- throw cnfe;
- }
- // Assert that loadedClass is not null
- else
- throw new IllegalStateException("ClassLoadingTask.loadedTask is null, name: "+name);
- }
-
- return task.loadedClass;
- }
-
- // URLClassLoader overrides --------------------------------------
-
- /** Override the permissions accessor to use the CodeSource
- based on the original URL if one exists. This allows the
- security policy to be defined in terms of the static URL
- namespace rather than the local copy or nested URL.
- This builds a PermissionCollection from:
- 1. The origURL CodeSource
- 2. The argument CodeSource
- 3. The Policy.getPermission(origURL CodeSource)
-
- This is necessary because we cannot define the CodeSource the
- SecureClassLoader uses to register the class under.
-
- @param cs the location and signatures of the codebase.
- */
- protected PermissionCollection getPermissions(CodeSource cs)
- {
- CodeSource permCS = cs;
- Policy policy = Policy.getPolicy();
- PermissionCollection perms = super.getPermissions(permCS);
- PermissionCollection perms2 = super.getPermissions(cs);
- PermissionCollection perms3 = policy.getPermissions(permCS);
- Enumeration iter = perms2.elements();
- while( iter.hasMoreElements() )
- perms.add((Permission) iter.nextElement());
- iter = perms3.elements();
- while( iter.hasMoreElements() )
- perms.add((Permission) iter.nextElement());
- if( log.isTraceEnabled() )
- log.trace("getPermissions, cp: "+getURLs()+" -> "+perms);
- return perms;
- }
-
-}
Deleted: trunk/jmx/src/main/org/jboss/mx/loading/LoadMgrDCL.java
===================================================================
--- trunk/jmx/src/main/org/jboss/mx/loading/LoadMgrDCL.java 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/jmx/src/main/org/jboss/mx/loading/LoadMgrDCL.java 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1,627 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.mx.loading;
-
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.security.PrivilegedAction;
-import java.security.AccessController;
-
-import org.jboss.classloading.spi.DomainClassLoader;
-import org.jboss.logging.Logger;
-import org.jboss.mx.loading.ClassLoadingTaskDCL.ThreadTask;
-
-
-/** A utility class used by the DomainClassLoaderUCLImpl to manage the thread
- * based class loading tasks.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class LoadMgrDCL
-{
- private static Logger log = Logger.getLogger(LoadMgrDCL.class);
- /** Used as a synchronization monitor during the setup/teardown of the
- thread owning a UCL.loadClass lock
- */
- private static Object registrationLock = new Object();
-
- /** A Map<UnifiedClassLoader3, Thread> of the active loadClass UCL3/threads.
- * This must be accessed under the registrationLock monitor.
- */
- private static HashMap loadClassThreads = new HashMap();
- /** A Map<Thread, LinkedList<ThreadTask> > of the class loading tasks
- * associated with a thread
- */
- private static Map loadTasksByThread = Collections.synchronizedMap(new WeakHashMap());
-
- private static SecurityManager sm = System.getSecurityManager();
-
- /** A UCL and its relative ordering with respect to the class loading.
- * The UCL with the lowest order to load a class is the UCL that will
- * populate the repository cache and be assigned as the UCL.loadClass
- * return value.
- */
- public static class PkgClassLoader
- {
- public final DomainClassLoaderUCLImpl ucl;
- public final int order;
-
- public PkgClassLoader(DomainClassLoaderUCLImpl ucl)
- {
- this(ucl, Integer.MAX_VALUE);
- }
- public PkgClassLoader(DomainClassLoaderUCLImpl ucl, int order)
- {
- this.ucl = ucl;
- this.order = order;
- }
-
- public String toString()
- {
- StringBuffer buffer = new StringBuffer(100);
- buffer.append(super.toString());
- buffer.append("{ucl=").append(ucl);
- buffer.append(" order=").append(order);
- buffer.append('}');
- return buffer.toString();
- }
- }
- /** A PrivilegedAction for locating a class as a resource
- *
- */
- private static class ResourceAction implements PrivilegedAction
- {
- DomainClassLoader ucl;
- String classRsrcName;
- ResourceAction(DomainClassLoader ucl, String classRsrcName)
- {
- this.ucl = ucl;
- this.classRsrcName = classRsrcName;
- }
- public Object run()
- {
- URL url = ucl.loadResourceLocally(classRsrcName);
- ucl = null;
- classRsrcName = null;
- return url;
- }
- }
-
- /** Register that a thread owns the UCL3.loadClass monitor. This is called
- * from within UCL3.loadClass(String,boolean) and this method creates
- * entries in the loadClassThreads and loadTasksByThread maps.
- */
- public static void registerLoaderThread(DomainClassLoader ucl, Thread t)
- {
- synchronized( registrationLock )
- {
- Object prevThread = loadClassThreads.put(ucl, t);
- if( log.isTraceEnabled() )
- log.trace("registerLoaderThread, ucl="+ucl+", t="+t+", prevT="+prevThread);
-
- synchronized( loadTasksByThread )
- {
- List taskList = (List) loadTasksByThread.get(t);
- if( taskList == null )
- {
- taskList = Collections.synchronizedList(new LinkedList());
- loadTasksByThread.put(t, taskList);
- if( log.isTraceEnabled() )
- log.trace("created new task list");
- }
- }
- registrationLock.notifyAll();
- }
- }
-
- /** Initiate the class loading task. This is called by UCL3.loadClass to
- * initiate the process of loading the requested class. This first attempts
- * to load the class from the repository cache, and then the class loaders
- * in the repsository. If the package of the class is found in the repository
- * then one or more ThreadTask are created to complete the ClassLoadingTaskDCL.
- * The ThreadTask are assigned to the threads that own the associated UCL3
- * monitor. If no class loader serves the class package, then the requesting
- * class loader is asked if it can load the class.
- *
- * @return true if the class could be loaded from the cache or requesting
- * UCL3, false to indicate the calling thread must process the
- * tasks assigned to it until the ClassLoadingTaskDCL state is FINISHED
- * @exception ClassNotFoundException if there is no chance the class can
- * be loaded from the current repository class loaders.
- */
- public static boolean beginLoadTask(ClassLoadingTaskDCL task,
- UnifiedLoaderRepositoryDCL repository)
- throws ClassNotFoundException
- {
- boolean trace = log.isTraceEnabled();
- if( trace )
- log.trace("Begin beginLoadTask, task="+task);
-
- // Try the cache before anything else.
- Class cls = repository.loadClassFromCache(task.classname);
- if( cls != null )
- {
- task.loadedClass = cls;
- task.state = ClassLoadingTaskDCL.FINISHED;
- if( trace )
- log.trace("End beginLoadTask, loadClassFromCache, classname: "+task.classname);
- return true;
- }
-
- // Next get the set of class loaders from the packages map
- Set pkgSet = repository.getPackageClassLoaders(task.classname);
- if( pkgSet == null || pkgSet.size() == 0 )
- {
- if (task.stopOrder == Integer.MAX_VALUE)
- {
- /* If there are no class loaders in the repository capable of handling
- the request ask the class loader itself in the event that its parent(s)
- can load the class.
- */
- try
- {
- cls = repository.loadClassFromClassLoader(task.classname, false,
- task.requestingClassLoader);
- }
- catch(LinkageError e)
- {
- if( trace )
- log.trace("End beginLoadTask, LinkageError for task: "+task, e);
- throw e;
- }
- if( cls != null )
- {
- task.loadedClass = cls;
- task.state = ClassLoadingTaskDCL.FINISHED;
- if( trace )
- log.trace("End beginLoadTask, loadClassFromClassLoader");
- return true;
- }
- }
-
- // Else, fail the load
- if( trace )
- log.trace("End beginLoadTask, ClassNotFoundException");
- String msg = "No ClassLoaders found for: "+task.classname;
- throw new ClassNotFoundException(msg);
- }
-
- /* A class loading task for each ClassLoader is needed. There can be
- multiple class loaders for a pkg due to the pkg being spread out over
- multiple jars, or duplicate classes due to versioning/patches, or
- just bad packaging.
-
- In the case of a non-scoped deployment of multiple classes which
- will provide a PkgClassLoader to define the ordering, we simply
- choose an ordering based on the order the UCL3s were added to the
- repository. At most one of the candidate UCL3s will load the class
- in order to avoid ClassCastExceptions or LinkageErrors due to the
- strong Java type system/security model.
-
- TODO: A simple ordering mechanism exists, but this probably needs
- to be augmented.
- */
- Iterator iter = pkgSet.iterator();
- DomainClassLoaderUCLImpl theUCL = null;
- int order = Integer.MAX_VALUE;
- while( iter.hasNext() )
- {
- Object next = iter.next();
- int uclOrder;
- DomainClassLoaderUCLImpl ucl;
- // This may be either a PkgClassLoader or a UCL3
- if( next instanceof DomainClassLoaderUCLImpl )
- {
- ucl = (DomainClassLoaderUCLImpl) next;
- uclOrder = 0; //ucl.getAddedOrder();
- }
- else
- {
- PkgClassLoader pkgUcl = (PkgClassLoader) next;
- ucl = pkgUcl.ucl;
- uclOrder = pkgUcl.order;
- }
-
- // If we have a stop order check it
- if (task.stopOrder != Integer.MAX_VALUE && task.stopOrder <= uclOrder)
- break;
-
- // Validate that the ucl has the class as a resource
- String classRsrcName = task.classname.replace('.', '/') + ".class";
- URL url = null;
- if( sm != null )
- {
- ResourceAction action = new ResourceAction(ucl, classRsrcName);
- url = (URL) AccessController.doPrivileged(action);
- }
- else
- {
- url = ucl.loadResourceLocally(classRsrcName);
- }
-
- if( url != null && uclOrder < order )
- {
- if( trace && theUCL != null )
- log.trace("Replacing UCL: "+theUCL+" with UCL:"+ucl);
- theUCL = ucl;
- order = uclOrder;
- }
- }
- if( theUCL == null && task.stopOrder == Integer.MAX_VALUE)
- {
- /* If there are no class loaders in the repository capable of handling
- the request ask the class loader itself in the event that its parent(s)
- can load the class. But not if we have a stopOrder.
- */
- try
- {
- cls = repository.loadClassFromClassLoader(task.classname, false,
- task.requestingClassLoader);
- }
- catch(LinkageError e)
- {
- if( trace )
- log.trace("End beginLoadTask, LinkageError for task: "+task, e);
- throw e;
- }
- if( cls != null )
- {
- task.loadedClass = cls;
- task.state = ClassLoadingTaskDCL.FINISHED;
- if( trace )
- log.trace("End beginLoadTask, loadClassFromClassLoader");
- return true;
- }
-
- // Else, fail the load
- if( trace )
- log.trace("End beginLoadTask, ClassNotFoundException");
- String msg = "No ClassLoaders found for: "+task.classname;
- throw new ClassNotFoundException(msg);
- }
-
- if (theUCL == null)
- {
- if( trace )
- log.trace("End beginLoadTask, ClassNotFoundException");
- String msg = "No ClassLoaders found for: "+task.classname;
- throw new ClassNotFoundException(msg);
- }
-
- scheduleTask(task, theUCL, order, false, trace);
- task.state = ClassLoadingTaskDCL.FOUND_CLASS_LOADER;
- if( trace )
- log.trace("End beginLoadTask, task="+task);
-
- return false;
- }
-
- /** Called by threads owning a UCL3.loadLock from within UCL3.loadClass to
- * process ThreadTasks assigned to them. This is the mechanism by which we
- * avoid deadlock due to a given loadClass request requiring multiple UCLs
- * to be involved. Any thread active in loadClass with the monitor held
- * processes class loading tasks that must be handled by its UCL3. The
- * active set of threads loading classes form a pool of cooperating threads.
- */
- public static void nextTask(Thread t, ClassLoadingTaskDCL task,
- UnifiedLoaderRepositoryDCL repository)
- throws InterruptedException
- {
- boolean trace = log.isTraceEnabled();
- List taskList = (List) loadTasksByThread.get(t);
- synchronized( taskList )
- {
- // There may not be any ThreadTasks
- while( taskList.size() == 0 && task.threadTaskCount != 0 )
- {
- /* There are no more tasks for the calling thread to execute, so the
- calling thread must wait until the task.threadTaskCount reaches 0
- */
- if( trace )
- log.trace("Begin nextTask(WAIT_ON_EVENT), task="+task);
- try
- {
- task.state = ClassLoadingTaskDCL.WAIT_ON_EVENT;
- taskList.wait();
- }
- catch(InterruptedException e)
- {
- if( trace )
- log.trace("nextTask(WAIT_ON_EVENT), interrupted, task="+task, e);
- // Abort this task attempt
- throw e;
- }
- if( trace )
- log.trace("nextTask(WAIT_ON_EVENT), notified, task="+task);
- }
-
- if( trace )
- log.trace("Continue nextTask("+taskList.size()+"), task="+task);
-
- // See if the task is complete
- if( task.threadTaskCount == 0 )
- {
- task.state = ClassLoadingTaskDCL.FINISHED;
- log.trace("End nextTask(FINISHED), task="+task);
- return;
- }
- }
-
- ThreadTask threadTask = (ThreadTask) taskList.remove(0);
- ClassLoadingTaskDCL loadTask = threadTask.getLoadTask();
- if( trace )
- log.trace("Begin nextTask("+taskList.size()+"), loadTask="+loadTask);
-
- DomainClassLoaderUCLImpl ucl3 = threadTask.ucl;
- try
- {
- if( threadTask.t == null )
- {
- /* This is a task that has been reassigned back to the original
- requesting thread ClassLoadingTaskDCL, so a new ThreadTask must
- be scheduled.
- */
- if( trace )
- log.trace("Rescheduling threadTask="+threadTask);
- scheduleTask(loadTask, ucl3, threadTask.order, true, trace);
- }
- else
- {
- if( trace )
- log.trace("Running threadTask="+threadTask);
- // Load the class using this thread
- threadTask.run();
- }
- }
- catch(Throwable e)
- {
- if( e instanceof ClassCircularityError /*&& taskList.size() > 0 */ )
- {
- /* Reschedule this task after all existing tasks to allow the
- current load tasks which are conflicting to complete.
- */
- try
- {
- if( trace )
- log.trace("Run failed with exception", e);
- // Reschedule and update the loadTask.threadTaskCount
- scheduleTask(loadTask, ucl3, Integer.MAX_VALUE, true, trace);
- }
- catch(ClassNotFoundException ex)
- {
- loadTask.setLoadError(ex);
- log.warn("Failed to reschedule task after CCE", ex);
- }
- if( trace )
- log.trace("Post CCE state, loadTask="+loadTask);
- }
- else
- {
- loadTask.setLoadError(e);
- if( trace )
- log.trace("Run failed with exception", e);
- }
- }
- finally
- {
- // We must release the loadLock acquired in beginLoadTask
- if( threadTask.releaseInNextTask == true )
- {
- if( trace )
- log.trace("Releasing loadLock and ownership of UCL: "+threadTask.ucl);
- synchronized( registrationLock )
- {
- loadClassThreads.remove(threadTask.ucl);
- }
- synchronized( threadTask.ucl )
- {
- ucl3.release();
- ucl3.notifyAll();
- }
- }
- }
-
- // If the ThreadTasks are complete mark the ClassLoadingTaskDCL finished
- if( loadTask.threadTaskCount == 0 )
- {
- Class loadedClass = threadTask.getLoadedClass();
- if( loadedClass != null )
- {
- ClassLoader loader = loadedClass.getClassLoader();
- ClassLoader wrapper = null;
- if (wrapper != null)
- loader=wrapper;
- // Place the loaded class into the repositry cache
- //repository.cacheLoadedClass(threadTask.getClassname(), loadedClass, loader);
- }
- /*
- synchronized( loadTask )
- {
- if( trace )
- log.trace("Notifying task of thread completion, loadTask:"+loadTask);
- loadTask.state = ClassLoadingTaskDCL.FINISHED;
- loadTask.notify();
- }
- */
- List loadTaskThreadTasks = (List) loadTasksByThread.get(loadTask.requestingThread);
- synchronized( loadTaskThreadTasks )
- {
- if( trace )
- log.trace("Notifying task of thread completion, loadTask:"+loadTask);
- loadTask.state = ClassLoadingTaskDCL.FINISHED;
- loadTaskThreadTasks.notify();
- }
- }
- if( trace )
- log.trace("End nextTask("+taskList.size()+"), loadTask="+loadTask);
- }
-
- /** Complete a ClassLoadingTaskDCL. This is called by UCL3.loadClass to indicate
- * that the thread is existing the loadClass method.
- */
- public static void endLoadTask(ClassLoadingTaskDCL task)
- {
- boolean trace = log.isTraceEnabled();
- if( trace )
- log.trace("Begin endLoadTask, task="+task);
-
- // Unregister as the owning thread and notify any waiting threads
- synchronized( registrationLock )
- {
- loadClassThreads.remove(task.requestingClassLoader);
- registrationLock.notifyAll();
- }
-
- // Any ThreadTasks associated with this thread must be reassigned
- List taskList = (List) loadTasksByThread.get(task.requestingThread);
- int size = taskList != null ? taskList.size() : 0;
- synchronized( taskList )
- {
- for(int i = 0; i < size; i ++)
- {
- ThreadTask threadTask = (ThreadTask) taskList.remove(0);
- ClassLoadingTaskDCL loadTask = threadTask.getLoadTask();
- /* Synchronize on loadTask and reassign the thread task back to the
- requesting thread of loadTask. We need to synchronize on loadTask
- to ensure that the transfer of this task back to loadTask.requestingThread
- is atomic wrt loadTask.requestingThread checking its task list.
- synchronized( loadTask )
- {
- if( trace )
- log.trace("Reassigning task: "+threadTask+", to: "+loadTask.requestingThread);
- threadTask.t = null;
- // Insert the task into the front of requestingThread task list
- List toTaskList = (List) loadTasksByThread.get(loadTask.requestingThread);
- toTaskList.add(0, threadTask);
- loadTask.state = ClassLoadingTaskDCL.NEXT_EVENT;
- loadTask.notify();
- }
- */
- if( trace )
- log.trace("Reassigning task: "+threadTask+", to: "+loadTask.requestingThread);
- threadTask.t = null;
- // Insert the task into the front of requestingThread task list
- List toTaskList = (List) loadTasksByThread.get(loadTask.requestingThread);
- synchronized( toTaskList )
- {
- toTaskList.add(0, threadTask);
- loadTask.state = ClassLoadingTaskDCL.NEXT_EVENT;
- toTaskList.notify();
- }
- }
- }
- }
-
- /** Invoked to create a ThreadTask to assign a thread to the task of
- * loading the class of ClassLoadingTaskDCL.
- *
- * @param task the orginating UCL3.loadClass task for which the thread
- * @param ucl the UCL3 the ThreadTask will call loadClassLocally on
- * @param order the heirachical ordering of the task
- * @param reschedule a boolean indicating if this task is being rescheduled
- * with another UCL3
- * @param trace the Logger trace level flag
- * @throws ClassNotFoundException
- */
- static private void scheduleTask(ClassLoadingTaskDCL task, DomainClassLoaderUCLImpl ucl,
- int order, boolean reschedule, boolean trace) throws ClassNotFoundException
- {
- Thread t = null;
- boolean releaseInNextTask = false;
- ThreadTask subtask = null;
- List taskList = null;
- synchronized( registrationLock )
- {
- // Find the thread that owns the ucl
- t = (Thread) loadClassThreads.get(ucl);
- if( t == null )
- {
- /* There is no thread in the UCL.loadClass yet that has registered
- as the owning thread. We must attempt to acquire the loadLock
- and if we cannot, wait until the thread entering UCL.loadClass
- gets to the registerLoaderThread call. By the time we are
- notified, the thread coule in fact have exited loadClass, so
- we either assign the task to the thread, or take ownership of
- the UCL.
- */
- while( t == null && ucl.attempt(1) == false )
- {
- if( trace )
- log.trace("Waiting for owner of UCL: "+ucl);
- try
- {
- registrationLock.wait();
- }
- catch(InterruptedException e)
- {
- String msg = "Interrupted waiting for registration notify,"
- + " classame: "+task.classname;
- throw new ClassNotFoundException(msg);
- }
-
- t = (Thread) loadClassThreads.get(ucl);
- if( trace )
- log.trace("Notified that UCL owner is: "+t);
- }
-
- // Get the thread registered as owning the UCL.loadClass lock
- t = (Thread) loadClassThreads.get(ucl);
- if( t == null )
- {
- // There is no such thread, register as the owner
- releaseInNextTask = true;
- t = task.requestingThread;
- Object prevThread = loadClassThreads.put(ucl, t);
- if( trace )
- {
- log.trace("scheduleTask, taking ownership of ucl="+ucl
- +", t="+t+", prevT="+prevThread);
- }
- }
- }
-
- // Now that we have the UCL owner thread, create and assign the task
- subtask = task.newThreadTask(ucl, t, order, reschedule,
- releaseInNextTask);
- // Add the task to the owning thread
- taskList = (List) loadTasksByThread.get(t);
- synchronized( taskList )
- {
- taskList.add(subtask);
- // Order the tasks by either the heirarchial order, or the repository order
- Collections.sort(taskList, task.taskComparator);
- taskList.notify();
- }
- }
-
- if( trace )
- log.trace("scheduleTask("+taskList.size()+"), created subtask: "+subtask);
- }
-}
Deleted: trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCL.java
===================================================================
--- trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCL.java 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCL.java 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1,1089 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.mx.loading;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.Vector;
-import java.io.IOException;
-
-import javax.management.ListenerNotFoundException;
-import javax.management.MBeanNotificationInfo;
-import javax.management.Notification;
-import javax.management.NotificationBroadcaster;
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
-import javax.management.MBeanRegistration;
-import javax.management.ObjectName;
-import javax.management.MBeanServer;
-
-import org.jboss.classloading.spi.ClassLoadingDomain;
-import org.jboss.classloading.spi.DomainClassLoader;
-import org.jboss.logging.Logger;
-import org.jboss.mx.loading.LoadMgr3.PkgClassLoader;
-import org.jboss.mx.util.JBossNotificationBroadcasterSupport;
-import org.jboss.util.Classes;
-
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-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 DomainClassLoaderUCLImpl instances. Class
- * and resource loading is synchronized by the acquiring the monitor to the
- * associated repository structure monitor. See the variable javadoc comments
- * for what monitor is used to access a given structure.
- *
- * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>.
- * @author <a href="mailto:Adrian.Brock at HappeningTimes.com">Adrian Brock</a>.
- * @version $Revision: 37459 $
- * just a hint... xdoclet not really used
- * @jmx.name="JMImplementation:service=UnifiedLoaderRepository,name=Default"
- */
-public class UnifiedLoaderRepositoryDCL extends LoaderRepositoryDomain
- implements MBeanRegistration, NotificationBroadcaster,
- UnifiedLoaderRepositoryDCLMBean
-{
- // Static --------------------------------------------------------
- private static final Logger log = Logger.getLogger(UnifiedLoaderRepository3.class);
- /** Used to provide a relative ordering of UCLs based on the order in
- * which they are added to the repository */
- private static int addedCount;
-
- // Attributes ----------------------------------------------------
-
- /** HashSet<UCL> of classloaders in the repository.
- * Access synchronized via this.classLoaders monitor.
- */
- 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).
- */
- private HashSet dynamicClassLoaders = new HashSet();
- /** A HashMap<DomainClassLoader, 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
- by the UCL.equals, but this caused problems with Class.forName(String,
- boolean, DomainClassLoader) caching.
- Access synchronized via this.classLoaders monitor.
- */
- private HashSet classLoaderURLs = new HashSet();
-
- /** The loaded classes cache, HashMap<String, Class>.
- * Access synchronized via this.classes monitor.
- */
- private ConcurrentReaderHashMap classes = new ConcurrentReaderHashMap();
-
- /** HashMap<UCL, HashSet<String>> class loaders to the set of class names
- * loaded via the UCL.
- * Access synchronized via this.classes monitor.
- */
- private HashMap loaderToClassesMap = new HashMap();
-
- /** HashMap<UCL, HashMap<String, URL>> class loaders to the set of
- * resource names they looked up.
- * Access synchronized via this.loaderToResourcesMap monitor.
- */
- private HashMap loaderToResourcesMap = new HashMap();
-
- /** HashMap<String, ResourceInfo(URL, UCL)> of global resources not unique
- * to a UCL
- * Access synchronized via this.loaderToResourcesMap monitor.
- */
- private HashMap globalResources = new HashMap();
-
- /** A HashMap<String, Set<UCL>> of package names to the set of
- * ClassLoaders which have classes in the package.
- * Access synchronized via this.packagesMap monitor.
- */
- private ConcurrentReaderHashMap packagesMap = new ConcurrentReaderHashMap();
-
- /** A HashMap<UCL, String[]> of class loaders to the array of pckages names
- * they serve
- * Access synchronized via this.packagesMap monitor.
- */
- private HashMap<DomainClassLoader, List<String>> loaderToPackagesMap = new HashMap<DomainClassLoader, List<String>>();
-
- /**
- * The sequenceNumber used to number notifications.
- */
- private long sequenceNumber = 0;
-
- /**
- * We delegate our notification sending to a support object.
- */
- private final JBossNotificationBroadcasterSupport broadcaster = new JBossNotificationBroadcasterSupport();
-
- /**
- * The NotificationInfo we emit.
- */
- private MBeanNotificationInfo[] info;
-
-
- // Public --------------------------------------------------------
-
- public DomainClassLoader newClassLoader(final URL url, boolean addToRepository)
- throws Exception
- {
- URL[] cp = {url};
- DomainClassLoaderUCLImpl ucl = new DomainClassLoaderUCLImpl(cp, this);
- if (addToRepository)
- this.registerClassLoader(ucl);
- return ucl;
- }
-
- public DomainClassLoader newClassLoader(final URL url, final URL origURL, boolean addToRepository)
- throws Exception
- {
- URL[] cp = {url};
- DomainClassLoaderUCLImpl ucl = new DomainClassLoaderUCLImpl(cp, this);
- if (addToRepository)
- this.registerClassLoader(ucl);
- return ucl;
- }
-
- public ClassLoadingDomain getParent()
- {
- return null;
- }
-
- public int getCacheSize()
- {
- return classes.size();
- }
-
- public int getClassLoadersSize()
- {
- return classLoaders.size();
- }
-
- public void flush()
- {
- synchronized (classes)
- {
- classes.clear();
- }
- }
-
- public Class getCachedClass(String classname)
- {
- return (Class) classes.get(classname);
- }
-
- /** Calls loadClassFromClassLoader(name, resolve, cl)
- */
- public Class loadClass(String name, boolean resolve, DomainClassLoader cl)
- throws ClassNotFoundException
- {
- return this.loadClassFromClassLoader(name, resolve, cl);
- }
-
- /** Called by LoadMgr to obtain all class loaders for the given className
- * @return Set<DomainClassLoaderUCLImpl>, may be null
- */
- public Set getPackageClassLoaders(String className)
- {
- String pkgName = ClassLoaderUtils.getPackageName(className);
- Set pkgSet = (Set) packagesMap.get(pkgName);
- if (dynamicClassLoaders.size() > 0)
- {
- if (pkgSet == null)
- pkgSet = ClassLoaderUtils.newPackageSet();
- pkgSet.addAll(dynamicClassLoaders);
- }
- return pkgSet;
- }
-
- private String getResourcePackageName(String rsrcName)
- {
- int index = rsrcName.lastIndexOf('/');
- String pkgName = rsrcName;
- if (index > 0)
- pkgName = rsrcName.substring(0, index);
- return pkgName.replace('/', '.');
- }
-
- /** Lookup a Class from the repository cache.
- * @param name the fully qualified class name
- * @return the cached Class if found, null otherwise
- */
- public Class loadClassFromCache(String name)
- {
- Class cls = null;
- synchronized (classes)
- {
- cls = (Class) classes.get(name);
- }
- return cls;
- }
-
- /** Add a Class to the repository cache.
- * @param name the fully qualified class name
- * @param cls the Class instance
- * @param cl the repository UCL
- */
- public void cacheLoadedClass(String name, Class cls, DomainClassLoader cl)
- {
- synchronized (classes)
- {
- // Update the global cache
- Object prevClass = classes.put(name, cls);
- if (log.isTraceEnabled())
- {
- log.trace("cacheLoadedClass, classname: " + name + ", class: " + cls
- + ", ucl: " + cl + ", prevClass: " + prevClass);
- }
-
- // Update the cache for this classloader
- // This is used to cycling classloaders
- HashSet loadedClasses = (HashSet) loaderToClassesMap.get(cl);
- if (loadedClasses == null)
- {
- loadedClasses = new HashSet();
- loaderToClassesMap.put(cl, loadedClasses);
- }
- loadedClasses.add(name);
- }
- }
-
- Class loadClassFromClassLoader(String name, boolean resolve, DomainClassLoader cl)
- {
- try
- {
- Class cls = cl.loadClassLocally(name, resolve);
- cacheLoadedClass(name, cls, cl);
- return cls;
- }
- catch (ClassNotFoundException x)
- {
- // The class is not visible by the calling classloader
- }
- return null;
- }
-
- /**
- * Loads a resource following the Unified DomainClassLoader architecture
- */
- public URL getResource(String name, DomainClassLoader cl)
- {
- // getResource() calls are not synchronized on the classloader from JDK code.
- // First ask the cache (of the calling classloader)
- URL resource = getResourceFromCache(name, cl);
-
- // The resource was already loaded by the calling classloader, we're done
- if (resource != null)
- return resource;
-
- // Not found in cache, ask the calling classloader
- resource = getResourceFromClassLoader(name, cl);
-
- // The calling classloader sees the resource, we're done
- if (resource != null)
- return resource;
-
- // 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
- if (resource != null)
- return resource;
-
- // This resource is not visible
- return null;
- }
-
- /** Find all resource URLs for the given name. This is entails an
- * exhuastive search of the repository and is an expensive operation.
- *
- * @param name the resource name
- * @param cl the requesting class loader
- * @param urls a list into which the located resource URLs will be placed
- */
- public void getResources(String name, DomainClassLoader cl, List urls)
- {
- // Go through all class loaders
- Iterator iter = classLoaders.iterator();
- while (iter.hasNext() == true)
- {
- DomainClassLoader nextCL = (DomainClassLoader) iter.next();
- if (nextCL instanceof DomainClassLoader)
- {
- DomainClassLoader ucl = (DomainClassLoader) nextCL;
- try
- {
- Enumeration<URL> resURLs = ucl.findResourcesLocally(name);
- while (resURLs.hasMoreElements())
- {
- Object res = resURLs.nextElement();
- urls.add(res);
- }
- }
- catch (IOException ignore)
- {
- }
- }
- }
- }
- public Enumeration<URL> findResources(String name)
- {
- Vector<URL> resources = new Vector<URL>();
- getResources(name, null, resources);
- return resources.elements();
- }
-
- /** As opposed to classes, resource are not looked up in a global cache,
- * since it is possible that 2 classloaders have the same resource name
- * (ejb-jar.xml), a global cache will overwrite. Instead we look in the
- * classloader's cache that we mantain to cycle the classloaders
- * @param name the resource name
- * @param cl the repository classloader
- * @return the resource URL if found, null otherwise
- */
- private URL getResourceFromCache(String name, DomainClassLoader cl)
- {
- URL resource = null;
- synchronized (loaderToResourcesMap)
- {
- if (loaderToResourcesMap.containsKey(cl))
- {
- HashMap resources = (HashMap) loaderToResourcesMap.get(cl);
- resource = (URL) resources.get(name);
- }
- }
- return resource;
- }
-
- private URL getResourceFromClassLoader(String name, DomainClassLoader cl)
- {
- URL resource = null;
- if (cl instanceof DomainClassLoader)
- {
- DomainClassLoader ucl = (DomainClassLoader) cl;
- resource = ucl.loadResourceLocally(name);
- cacheLoadedResource(name, resource, cl);
- }
- return resource;
- }
-
- /** Check for a resource in the global cache
- * Synchronizes access to globalResources using the loaderToResourcesMap monitor
- * @param name
- * @return
- */
- protected URL getResourceFromGlobalCache(String name)
- {
- ResourceInfo ri = null;
- synchronized (loaderToResourcesMap)
- {
- ri = (ResourceInfo) globalResources.get(name);
- }
- URL resource = null;
- if (ri != null)
- resource = ri.url;
- return resource;
- }
-
- protected URL getResourceFromRepository(String name, DomainClassLoader cl)
- {
- // Get the set of class loaders from the packages map
- String pkgName = getResourcePackageName(name);
- Iterator i = null;
- Set pkgSet = (Set) this.packagesMap.get(pkgName);
- if (pkgSet != null)
- {
- i = pkgSet.iterator();
- }
- if (i == null)
- {
- // If no pkg match was found just go through all class loaders
- i = classLoaders.iterator();
- }
-
- URL url = null;
- while (i.hasNext() == true)
- {
- DomainClassLoader classloader = (DomainClassLoader) i.next();
- if (classloader.equals(cl))
- {
- continue;
- }
-
- if (classloader instanceof DomainClassLoader)
- {
- url = ((DomainClassLoader) classloader).loadResourceLocally(name);
- if (url != null)
- {
- cacheLoadedResource(name, url, classloader);
- cacheGlobalResource(name, url, classloader);
- break;
- }
- else
- {
- // Do nothing, go on with next classloader
- }
- }
- }
- return url;
- }
-
- /** Update the loaderToResourcesMap
- * @param name the resource name
- * @param url the resource URL
- * @param cl the UCL
- */
- private void cacheLoadedResource(String name, URL url, DomainClassLoader cl)
- {
- // Update the cache for this classloader only
- // This is used for cycling classloaders
- synchronized (loaderToResourcesMap)
- {
- HashMap resources = (HashMap) loaderToResourcesMap.get(cl);
- if (resources == null)
- {
- resources = new HashMap();
- loaderToResourcesMap.put(cl, resources);
- }
- resources.put(name, url);
- }
- }
-
- /** Update cache of resources looked up via one UCL, buf found in another UCL
- * @param name the resource name
- * @param url the resource URL
- * @param cl the UCL
- */
- private void cacheGlobalResource(String name, URL url, DomainClassLoader cl)
- {
- synchronized (loaderToResourcesMap)
- {
- globalResources.put(name, new ResourceInfo(url, cl));
- }
- }
-
- /** This is a utility method a listing of the URL for all UnifiedClassLoaders
- * associated with the repository. It is never called in response to
- * class or resource loading.
- */
- public URL[] getURLs()
- {
- HashSet classpath = new HashSet();
- Set tmp = classLoaders;
- for (Iterator iter = tmp.iterator(); iter.hasNext();)
- {
- Object obj = iter.next();
- if (obj instanceof DomainClassLoader)
- {
- DomainClassLoader cl = (DomainClassLoader) obj;
- URL[] urls = cl.getClasspath();
- int length = urls != null ? urls.length : 0;
- for (int u = 0; u < length; u++)
- {
- URL path = urls[u];
- classpath.add(path);
- }
- }
- } // for all ClassLoaders
-
- URL[] cp = new URL[classpath.size()];
- classpath.toArray(cp);
- return cp;
- }
-
- /** A utility method that iterates over all repository class loaders and
- * display the class information for every UCL that contains the given
- * className
- */
- public String displayClassInfo(String className)
- {
- /* We have to find the class as a resource as we don't want to invoke
- loadClass(name) and cause the side-effect of loading new classes.
- */
- String classRsrcName = className.replace('.', '/') + ".class";
-
- int count = 0;
- Class loadedClass = this.loadClassFromCache(className);
- StringBuffer results = new StringBuffer(className + " Information\n");
- if (loadedClass != null)
- {
- results.append("Repository cache version:");
- Classes.displayClassInfo(loadedClass, results);
- }
- else
- {
- results.append("Not loaded in repository cache\n");
- }
- 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++;
- }
- }
-
- // 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 cl = stack[s];
- URL classURL = cl.findResource(classRsrcName);
- if (classURL != null)
- {
- results.append("\n\n### Instance" + count + " via UCL: " + cl + "\n");
- count++;
- }
- }
-
- return results.toString();
- }
-
- // LoaderRepository overrides ------------------------------------
-
- /** First tries to load from any UCL in the ULR, and if the
- * class is not found, next tries the current thread context
- * class loader.
- * @param className - the class to load
- */
- public Class loadClass(String className) throws ClassNotFoundException
- {
- // Try to load from a UCL in the ULR first
- ClassLoader scl = Thread.currentThread().getContextClassLoader();
- DomainClassLoader ucl = null;
- if (classLoaders.size() > 0)
- ucl = (DomainClassLoader) this.classLoaders.iterator().next();
- try
- {
- if (ucl != null)
- return loadClass(className, false, ucl);
- }
- catch (ClassNotFoundException ignore)
- {
- // go on and try the next loader
- }
-
- try
- {
- // If there is no class try the TCL
- return scl.loadClass(className);
- }
- catch (ClassNotFoundException e)
- {
- // go on and try the next loader
- }
-
- // at last try a native
- Class clazz = getNativeClassForName(className);
- if (clazz != null) return clazz;
-
- throw new ClassNotFoundException(className);
- }
-
- /**
- * Loads a class from the repository, excluding the given
- * classloader.
- *
- * @param loader the classloader to exclude
- * @param className the class to load
- * @return the found class
- * @exception ClassNotFoundException when there is no such class
- */
- public Class loadClassWithout(DomainClassLoader loader, String className)
- throws ClassNotFoundException
- {
- throw new ClassNotFoundException("NYI");
- }
-
- /**
- * Get any wrapping classloader for the passed classloader
- *
- * @param cl the wrapped classloader
- * @return the wrapping classloader or null if not wrapped
- */
- public DomainClassLoader getWrappingClassLoader(DomainClassLoader cl)
- {
- synchronized (classLoaders)
- {
- return (DomainClassLoader) nonUCLClassLoader.get(cl);
- }
- }
-
- /** Add a class loader to the repository.
- */
- public void addClassLoader(DomainClassLoader loader)
- {
- // if you come to us as UCL we send you straight to the orbit
- addDomainClassLoader((DomainClassLoaderUCLImpl) loader);
- }
-
- public boolean addClassLoaderURL(DomainClassLoader cl, URL url)
- {
- DomainClassLoader ucl = (DomainClassLoader) cl;
- boolean added = false;
- synchronized (classLoaders)
- {
- // Strip any query parameter
- String query = url.getQuery();
- if (query != null)
- {
- String ext = url.toExternalForm();
- String ext2 = ext.substring(0, ext.length() - query.length() - 1);
- try
- {
- url = new URL(ext2);
- }
- catch (MalformedURLException 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)
- {
- updatePackageMap(ucl);
- classLoaderURLs.add(url);
- added = true;
- // Check for a dynamic URL
- if (query != null && query.indexOf("dynamic=true") >= 0)
- dynamicClassLoaders.add(ucl);
- }
- }
- return added;
- }
-
- /** Add a UCL to the repository.
- * This sychronizes on classLoaders.
- * @param cl
- */
- private void addDomainClassLoader(DomainClassLoaderUCLImpl cl)
- {
- cl.setDomain(this);
- boolean added = false;
- synchronized (classLoaders)
- {
- boolean exists = false;
- URL[] cp = cl.getClasspath();
- classLoaderURLs.addAll(Arrays.asList(cp));
- added = classLoaders.add(cl);
- if (added)
- {
- log.debug("Adding " + cl);
- addedCount++;
- cl.setAddedOrder(addedCount);
- updatePackageMap(cl);
- }
- else
- {
- log.debug("Skipping duplicate " + cl);
- }
- }
- }
-
- /** Walk through the class loader URL to see what packages it is capable
- of handling
- */
- private synchronized void updatePackageMap(DomainClassLoader cl)
- {
- boolean trace = log.isTraceEnabled();
- try
- {
- PackageMapper listener = new PackageMapper(cl);
- URL[] cp = cl.getClasspath();
- for(URL url : cp)
- {
- ClassLoaderUtils.updatePackageMap(url, listener);
- }
- }
- catch (Exception 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);
- }
- }
-
- /** Remove the class loader from the repository. This synchronizes on the
- * this.classLoaders
- */
- public void removeClassLoader(DomainClassLoader loader)
- {
- ArrayList removeNotifications = new ArrayList();
- DomainClassLoader cl = loader;
- synchronized (classLoaders)
- {
- if ((loader instanceof DomainClassLoader) == false)
- {
- cl = (DomainClassLoader) nonUCLClassLoader.remove(loader);
- }
- if (cl instanceof DomainClassLoader)
- {
- DomainClassLoader ucl = (DomainClassLoader) cl;
- if (getTranslator() != null)
- getTranslator().unregisterClassLoader(ucl);
- URL[] urls = ucl.getClasspath();
- for (int u = 0; u < urls.length; u++)
- classLoaderURLs.remove(urls[u]);
- }
- boolean dynamic = dynamicClassLoaders.remove(cl);
- boolean removed = classLoaders.remove(cl);
- log.debug("UnifiedLoaderRepository removed(" + removed + ") " + cl);
-
- // Take care also of the cycling mapping for classes
- HashSet loadedClasses = null;
- boolean hasLoadedClasses = false;
- synchronized (classes)
- {
- hasLoadedClasses = loaderToClassesMap.containsKey(cl);
- if (hasLoadedClasses)
- loadedClasses = (HashSet) loaderToClassesMap.remove(cl);
- // This classloader has loaded at least one class
- if (loadedClasses != null)
- {
- // Notify that classes are about to be removed
- for (Iterator iter = loadedClasses.iterator(); iter.hasNext();)
- {
- String className = (String) iter.next();
- Notification n = new Notification(CLASS_REMOVED, this,
- getNextSequenceNumber(), className);
- removeNotifications.add(n);
- }
-
- // Remove the classes from the global cache
- for (Iterator i = loadedClasses.iterator(); i.hasNext();)
- {
- String cls = (String) i.next();
- this.classes.remove(cls);
- }
- }
- }
-
- // Take care also of the cycling mapping for resources
- synchronized (loaderToResourcesMap)
- {
- 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
- if (dynamic == false)
- {
- List<String> pkgNames = loaderToPackagesMap.remove(cl);
- if( pkgNames != null )
- {
- for(String pkgName : pkgNames)
- {
- Set pkgSet = (Set) packagesMap.get(pkgName);
- if (pkgSet != null)
- {
- pkgSet.remove(cl);
- if (pkgSet.isEmpty())
- packagesMap.remove(pkgName);
- }
- }
- }
- }
- else
- {
- // A dynamic classloader could end up in any package set
- loaderToPackagesMap.remove(cl);
- for (Iterator i = packagesMap.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry) i.next();
- Set pkgSet = (Set) entry.getValue();
- pkgSet.remove(cl);
- if (pkgSet.isEmpty())
- i.remove();
- }
- }
- }
-
- // Send the class removal notfications outside of the synchronized block
- for (int n = 0; n < removeNotifications.size(); n++)
- {
- Notification msg = (Notification) removeNotifications.get(n);
- broadcaster.sendNotification(msg);
- }
-
- Notification msg = new Notification(CLASSLOADER_REMOVED, this, getNextSequenceNumber());
- msg.setUserData(cl);
- broadcaster.sendNotification(msg);
- }
-
- /**
- * This method provides an mbean-accessible way to add a
- * UnifiedClassloader, and sends a notification when it is added.
- *
- * @param ucl an <code>UnifiedClassLoader</code> value
- * @return a <code>LoaderRepository</code> value
- *
- * @jmx.managed-operation
- */
- public LoaderRepositoryDomain registerClassLoader(DomainClassLoader ucl)
- {
- addClassLoader(ucl);
- Notification msg = new Notification(CLASSLOADER_ADDED, this, getNextSequenceNumber());
- msg.setUserData(ucl);
- broadcaster.sendNotification(msg);
-
- return this;
- }
-
- /**
- * @jmx.managed-operation
- */
- public LoaderRepositoryDomain getInstance()
- {
- return this;
- }
-
- // implementation of javax.management.NotificationBroadcaster interface
-
- /**
- * addNotificationListener delegates to the broadcaster object we hold.
- *
- * @param listener a <code>NotificationListener</code> value
- * @param filter a <code>NotificationFilter</code> value
- * @param handback an <code>Object</code> value
- * @exception IllegalArgumentException if an error occurs
- */
- public void addNotificationListener(NotificationListener listener,
- NotificationFilter filter, Object handback) throws IllegalArgumentException
- {
- broadcaster.addNotificationListener(listener, filter, handback);
- }
-
- /**
- *
- * @return <description>
- */
- public MBeanNotificationInfo[] getNotificationInfo()
- {
- if (info == null)
- {
- info = new MBeanNotificationInfo[]{
- new MBeanNotificationInfo(new String[]{"CLASSLOADER_ADDED"},
- "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")
-
- };
- }
- return info;
- }
-
- /**
- * removeNotificationListener delegates to our broadcaster object
- *
- * @param listener a <code>NotificationListener</code> value
- * @exception ListenerNotFoundException if an error occurs
- */
- public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException
- {
- broadcaster.removeNotificationListener(listener);
- }
-
- // MBeanRegistration
- public ObjectName preRegister(MBeanServer server, ObjectName name)
- throws Exception
- {
- return name;
- }
-
- public void postRegister(Boolean registrationDone)
- {
- }
-
- public void preDeregister()
- throws Exception
- {
- }
-
- public void postDeregister()
- {
- log.debug("postDeregister, clearing all references");
- classLoaders.clear();
- dynamicClassLoaders.clear();
- nonUCLClassLoader.clear();
- classLoaderURLs.clear();
- classes.clear();
- loaderToClassesMap.clear();
- loaderToResourcesMap.clear();
- globalResources.clear();
- packagesMap.clear();
- loaderToPackagesMap.clear();
- }
-
- /**
- * lookup the package names for a given class loader
- * @param loader
- * @return
- */
- String[] getPackageNames(DomainClassLoaderUCLImpl loader)
- {
- List<String> pkgNames = loaderToPackagesMap.get(loader);
- String[] tmp = {};
- if( pkgNames != null )
- {
- tmp = new String[pkgNames.size()];
- pkgNames.toArray(tmp);
- }
- return tmp;
- }
-
- private synchronized long getNextSequenceNumber()
- {
- return sequenceNumber++;
- }
-
- /**
- * A comparator for comparing repository classloaders
- */
- private static class DomainClassLoaderUCLImplComparator implements Comparator
- {
- /**
- * Compares two repository classloaders, they are ordered by:
- * 1) parent->child delegation rules in the loader repository
- * 2) added order inside the loader repository
- */
- public int compare(Object o1, Object o2)
- {
- if (o1 instanceof PkgClassLoader)
- {
- PkgClassLoader pkg1 = (PkgClassLoader) o1;
- PkgClassLoader pkg2 = (PkgClassLoader) o2;
- RepositoryClassLoader rcl1 = pkg1.ucl;
- RepositoryClassLoader rcl2 = pkg2.ucl;
- // We use the package classloader ordering before the repository order
- int test = (pkg1.order - pkg2.order);
- if (test != 0)
- return test;
- else
- return rcl1.getAddedOrder() - rcl2.getAddedOrder();
- }
- else
- {
- DomainClassLoaderUCLImpl rcl1 = (DomainClassLoaderUCLImpl) o1;
- DomainClassLoaderUCLImpl rcl2 = (DomainClassLoaderUCLImpl) o2;
- return rcl1.getAddedOrder() - rcl2.getAddedOrder();
-
- // REVIEW: Alternative to using the pkgClassLoader is
- // ordering based on the loader repository
-
- //LoaderRepository lr1 = rcl1.getLoaderRepository();
- //LoaderRepository lr2 = rcl2.getLoaderRepository();
-
- // Are the loader repositories ordered?
- //int test = lr1.compare(lr2);
- //if (test != 0)
- // return test;
- //else
- // return rcl1.getAddedOrder() - rcl2.getAddedOrder();
- }
- }
- }
-
- class PackageMapper implements ClassLoaderUtils.PkgNameListener
- {
- private DomainClassLoader loader;
- PackageMapper(DomainClassLoader loader)
- {
- this.loader = loader;
- }
- public void addPackage(String pkgName)
- {
- // Skip the standard J2EE archive directories
- if( pkgName.startsWith("META-INF") || pkgName.startsWith("WEB-INF") )
- return;
-
- Set<DomainClassLoader> pkgSet = (Set<DomainClassLoader>) packagesMap.get(pkgName);
- if( pkgSet == null )
- {
- pkgSet = new TreeSet<DomainClassLoader>(new DomainClassLoaderUCLImplComparator());
- packagesMap.put(pkgName, pkgSet);
- }
- if( pkgSet.contains(loader) == false )
- {
- pkgSet.add((DomainClassLoader)loader);
- List<String> loaderPkgNames = loaderToPackagesMap.get(loader);
- if( loaderPkgNames == null )
- {
- loaderPkgNames = new ArrayList<String>();
- loaderToPackagesMap.put((DomainClassLoader)loader, loaderPkgNames);
- }
- loaderPkgNames.add(pkgName);
-
- // Anytime more than one class loader exists this may indicate a problem
- if( pkgSet.size() > 1 )
- {
- log.debug("Multiple class loaders found for pkg: "+pkgName);
- }
- if( log.isTraceEnabled() )
- log.trace("Indexed pkg: "+pkgName+", UCL: "+loader);
- }
- }
- }
-}
Deleted: trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCLMBean.java
===================================================================
--- trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCLMBean.java 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryDCLMBean.java 2008-03-21 21:44:39 UTC (rev 71164)
@@ -1,50 +0,0 @@
-package org.jboss.mx.loading;
-
-import java.net.URL;
-import java.util.Set;
-
-import org.jboss.classloading.spi.DomainClassLoader;
-import org.jboss.classloading.spi.Translator;
-
-public interface UnifiedLoaderRepositoryDCLMBean
-{
- public DomainClassLoader newClassLoader(final URL url, boolean addToRepository)
- throws Exception;
- public DomainClassLoader newClassLoader(final URL url, final URL origURL, boolean addToRepository)
- throws Exception;
-
- public void removeClassLoader(DomainClassLoader cl);
-
- public LoaderRepositoryDomain registerClassLoader(DomainClassLoader ucl);
-
- public LoaderRepositoryDomain getInstance();
-
- public URL[] getURLs();
-
- // Aspect stuff
- public Translator getTranslator();
- public void setTranslator(Translator t);
-
- /** Called by LoadMgr to obtain all class loaders for the given className
- *@return LinkedList<UnifiedClassLoader3>, may be null
- */
- public Set getPackageClassLoaders(String className);
-
- /** A utility method that iterates over all repository class loader and
- * display the class information for every UCL that contains the given
- * className
- */
- public String displayClassInfo(String className);
-
- /** Get the number of classes loaded into the ULR cache.
- * @return the classes cache size.
- */
- public int getCacheSize();
- /** Get the number of UnifiedClassLoader3s (UCLs) in the ULR
- * @return the number of UCLs in the ULR
- */
- public int getClassLoadersSize();
- /** Flush the ULR classes cache
- */
- public void flush();
-}
Modified: trunk/messaging/build.xml
===================================================================
--- trunk/messaging/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/messaging/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -84,6 +84,7 @@
<path refid="jboss.j2se.classpath"/>
<path refid="jboss.messaging.classpath"/>
<path refid="jboss.systemjmx.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jbosssx.classpath"/>
<path refid="jboss.jboss.jaspi.api.classpath"/>
Modified: trunk/profileservice/build.xml
===================================================================
--- trunk/profileservice/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/profileservice/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -74,6 +74,10 @@
<path refid="jboss.common.core.classpath"/>
<path refid="jboss.common.logging.spi.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
+ <path refid="jboss.jboss.mdr.classpath"/>
+ <path refid="jboss.jboss.reflect.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.remoting.classpath"/>
<path refid="jboss.system.classpath"/>
Modified: trunk/security/build.xml
===================================================================
--- trunk/security/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/security/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -94,6 +94,7 @@
<path refid="jboss.jboss.javaee.classpath"/>
<path refid="jboss.jboss.jaspi.api.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.naming.classpath"/>
<path refid="jboss.jboss.security.spi.classpath"/>
Modified: trunk/server/build.xml
===================================================================
--- trunk/server/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/server/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -87,6 +87,9 @@
<path refid="jboss.jbossws.classpath"/>
<path refid="jboss.jbossws.spi.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
+ <path refid="jboss.jboss.mdr.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="junit.junit.classpath"/>
Modified: trunk/spring-int/build.xml
===================================================================
--- trunk/spring-int/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/spring-int/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -97,6 +97,8 @@
<path refid="jboss.server.classpath"/>
<path refid="jboss.system.classpath"/>
<path refid="jboss.systemjmx.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="jboss.jboss.javaee.classpath"/>
Modified: trunk/system/build.xml
===================================================================
--- trunk/system/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/system/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -74,6 +74,8 @@
<path refid="dom4j.dom4j.classpath"/>
<path refid="jboss.aop.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="jboss.common.core.classpath"/>
Modified: trunk/system-jmx/build.xml
===================================================================
--- trunk/system-jmx/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/system-jmx/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -76,6 +76,11 @@
<path refid="dom4j.dom4j.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
<path refid="sun.jaxb.classpath"/>
+ <path refid="jboss.jboss.cl.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
+ <path refid="jboss.jboss.mdr.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.reflect.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.integration.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
Modified: trunk/testsuite/build.xml
===================================================================
--- trunk/testsuite/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/testsuite/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -156,6 +156,11 @@
<!-- xml binding -->
<path refid="xmlunit.xmlunit.classpath"/>
+ <path refid="jboss.jboss.reflect.classpath"/>
+ <path refid="jboss.jboss.mdr.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.cl.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<!-- For classloader leak tests -->
Modified: trunk/tomcat/build.xml
===================================================================
--- trunk/tomcat/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/tomcat/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -66,6 +66,9 @@
<path refid="jboss.jbossxb.classpath"/>
<path refid="jboss.serialization.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.cl.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="jboss.integration.classpath"/>
Modified: trunk/varia/build.xml
===================================================================
--- trunk/varia/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/varia/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -93,6 +93,8 @@
<path refid="oswego.concurrent.classpath"/>
<path refid="juddi.juddi.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
+ <path refid="jboss.jboss.man.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jbossws.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
Modified: trunk/webservices/build.xml
===================================================================
--- trunk/webservices/build.xml 2008-03-21 20:16:34 UTC (rev 71163)
+++ trunk/webservices/build.xml 2008-03-21 21:44:39 UTC (rev 71164)
@@ -85,6 +85,7 @@
<path refid="jboss.jbossws.spi.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
<path refid="jboss.metadata.classpath"/>
+ <path refid="jboss.jboss.deployers.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="sun.jaxb.classpath"/>
<path refid="sun.servlet.classpath"/>
More information about the jboss-cvs-commits
mailing list