| Method from org.jboss.mx.loading.UnifiedLoaderRepository2 Detail: |
public static void acquire() {
// Save and clear the interrupted state of the incoming thread
boolean threadWasInterrupted = Thread.currentThread().interrupted();
try
{
repositoryLock.acquire();
}
catch(InterruptedException e)
{
}
finally
{
// Restore the interrupted state of the thread
if( threadWasInterrupted )
Thread.currentThread().interrupt();
}
} Deprecated! |
public void addClassLoader(ClassLoader loader) {
UnifiedLoaderRepository2.acquire();
try
{
// if you come to us as UCL we send you straight to the orbit
if (loader instanceof UnifiedClassLoader)
addUnifiedClassLoader((UnifiedClassLoader)loader);
// if you come to us as URLCL we'll slice you up and
// orbit UCL per URL
else if (loader instanceof URLClassLoader)
{
URLClassLoader ucl = (URLClassLoader)loader;
URL[] urls = ucl.getURLs();
for (int i = 0; i < urls.length; ++i)
{
addUnifiedClassLoader(new UnifiedClassLoader(urls[i], this));
}
}
else
{
// addNonDelegatingClassLoader(loader);
// throw new RuntimeException("ULR only allows UCL to be added");
log.warn("Tried to add non- URLClassLoader. Ignored");
} // end of else
}
finally
{
UnifiedLoaderRepository2.release();
}
} Deprecated! |
public boolean addClassLoaderURL(ClassLoader cl,
URL url) {
return false;
} Deprecated! |
public void addNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback) throws IllegalArgumentException {
broadcaster.addNotificationListener(listener, filter, handback);
} Deprecated!addNotificationListener delegates to the broadcaster object we hold. |
public static boolean attempt(long waitMS) {
// Public --------------------------------------------------------
boolean acquired = false;
// Save and clear the interrupted state of the incoming thread
boolean threadWasInterrupted = Thread.currentThread().interrupted();
try
{
acquired = repositoryLock.attempt(waitMS);
}
catch(InterruptedException e)
{
}
finally
{
// Restore the interrupted state of the thread
if( threadWasInterrupted )
Thread.currentThread().interrupt();
}
return acquired;
} Deprecated! |
public Class findClass(String name) {
// 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 = name.replace('.", '/") + ".class";
HashSet tmp = (HashSet) classLoaders.clone();
for (Iterator iter = tmp.iterator(); iter.hasNext();)
{
ClassLoader cl = (ClassLoader)iter.next();
URL classURL = cl.getResource(classRsrcName);
log.trace("Checking CL for URL: "+classURL);
if (classURL != null)
{
try
{
// Since the class was found we can load it which should be a noop
Class cls = cl.loadClass(name);
log.trace("Found class in: "+cls.getProtectionDomain());
return cls;
}
catch (ClassNotFoundException e)
{
log.debug("Failed to load class: " + name, e);
}
}
}
log.trace("Class not found");
return null;
} Deprecated!This is a utility method that iterates through the current class loaders
and tries to find the given class name. It is never invoked as part of
class or resource loading. |
public LoaderRepository getInstance() {
return this;
} Deprecated! |
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;
} Deprecated! |
public URL getResource(String name,
ClassLoader 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;
} Deprecated!Loads a resource following the Unified ClassLoader architecture |
public void getResources(String name,
ClassLoader cl,
List urls) {
} Deprecated! |
public URL[] getURLs() {
HashSet classpath = new HashSet();
HashSet tmp = (HashSet) classLoaders.clone();
for (Iterator iter = tmp.iterator(); iter.hasNext();)
{
Object obj = iter.next();
if (obj instanceof UnifiedClassLoader)
{
UnifiedClassLoader cl = (UnifiedClassLoader)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;
} Deprecated!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 Class loadClass(String className) throws ClassNotFoundException {
// if someone comes to us directly through LoaderRepository interface
// notice that UCL loaders will skip this and invoke
// loadClass(name, resolve, cl) directly
ClassLoader scl = Thread.currentThread().getContextClassLoader();
Class clazz = null;
UnifiedLoaderRepository2.acquire();
try
{
clazz = loadClass(className, false, scl);
}
catch (ClassNotFoundException e)
{
// If the TCL is not a UnifiedClassLoader then the scl was not asked
// if it could load the class. Do so here.
if ((scl instanceof UnifiedClassLoader) == false)
clazz = scl.loadClass(className);
// Else we need to rethrow the CNFE
else
throw e;
}
finally
{
UnifiedLoaderRepository2.release();
}
return clazz;
} Deprecated! |
public Class loadClass(String name,
boolean resolve,
ClassLoader cl) throws ClassNotFoundException {
// Try the cache before anything else.
Class cls = loadClassFromCache(name, cl);
// Found in cache, we're done
if (cls != null) {return cls;}
// Not found in cache, ask the calling classloader
cls = loadClassFromClassLoader(name, resolve, cl);
// The calling classloader sees the class, we're done
if (cls != null) {return cls;}
// Not visible by the calling classloader, iterate on the other classloaders
cls = loadClassFromRepository(name, resolve, cl);
if( cls == null && name.charAt(0) == '[" )
{
// First try to load the element class
String subname = name.substring(2, name.length()-1);
cls = loadClassFromRepository(subname, resolve, cl);
if( cls != null )
{
// Retry loading the array class since we have the element class
cls = loadClassFromRepository(name, resolve, cl);
}
}
// Some other classloader sees the class, we're done
if (cls != null) {return cls;}
// This class is not visible
throw new ClassNotFoundException(name);
} Deprecated!Loads a class following the Unified ClassLoader architecture. |
public Class loadClassWithout(ClassLoader loader,
String className) throws ClassNotFoundException {
throw new ClassNotFoundException("NYI");
} Deprecated! |
public UnifiedClassLoader newClassLoader(URL url,
boolean addToRepository) throws Exception {
UnifiedClassLoader2 ucl = new UnifiedClassLoader2(url, null, this);
if( addToRepository )
{
UnifiedClassLoader delegate = ucl.getDelegate();
this.addClassLoader(delegate);
}
return ucl;
} Deprecated! |
public UnifiedClassLoader newClassLoader(URL url,
URL origURL,
boolean addToRepository) throws Exception {
UnifiedClassLoader2 ucl = new UnifiedClassLoader2(url, origURL, this);
if( addToRepository )
{
UnifiedClassLoader delegate = ucl.getDelegate();
this.addClassLoader(delegate);
}
return ucl;
} Deprecated! |
public LoaderRepository registerClassLoader(UnifiedClassLoader ucl) {
addClassLoader(ucl);
Notification msg = new Notification(CLASSLOADER_ADDED, this, getNextSequenceNumber());
msg.setUserData(ucl);
broadcaster.sendNotification(msg);
return this;
} Deprecated!This method provides an mbean-accessible way to add a
UnifiedClassloader, and sends a notification when it is added. |
public static void release() {
repositoryLock.release();
} Deprecated! |
public void removeClassLoader(ClassLoader cl) {
UnifiedLoaderRepository2.acquire();
try
{
if( cl instanceof UnifiedClassLoader )
{
UnifiedClassLoader ucl = (UnifiedClassLoader) cl;
URL url = ucl.getURL();
classLoaderURLs.remove(url);
}
boolean removed = classLoaders.remove(cl);
log.debug("UnifiedLoaderRepository removed("+removed+") " + cl);
// Take care also of the cycling mapping for classes
if (loaderToClassesMap.containsKey(cl))
{
HashSet loaded = (HashSet)loaderToClassesMap.remove(cl);
// This classloader has loaded at least one class
if (loaded != null)
{
// Notify that classes are about to be removed
for (Iterator iter = loaded.iterator(); iter.hasNext();)
{
broadcaster.sendNotification(new Notification(CLASS_REMOVED, this, getNextSequenceNumber(), (String)iter.next()));
}
// Remove the classes from the global cache
for (Iterator i = loaded.iterator(); i.hasNext();)
{
String cls = (String)i.next();
this.classes.remove(cls);
}
}
}
// Take care also of the cycling mapping for resources
if (loaderToResourcesMap.containsKey(cl))
{
HashMap resources = (HashMap)loaderToResourcesMap.remove(cl);
// Remove the resources from the global cache that are from this classloader
if (resources != null)
{
for (Iterator i = resources.keySet().iterator(); i.hasNext();)
{
String name = (String) i.next();
ResourceInfo ri = (ResourceInfo) globalResources.get(name);
if (ri != null && ri.cl == cl)
globalResources.remove(name);
}
}
}
// Clean up the package name to class loader mapping
String[] pkgNames = (String[]) loaderToPackagesMap.remove(cl);
int length = pkgNames != null ? pkgNames.length : 0;
for(int p = 0; p < length; p ++)
{
String pkgName = pkgNames[p];
HashSet pkgSet = (HashSet) packagesMap.get(pkgName);
if( pkgSet != null )
{
pkgSet.remove(cl);
if( pkgSet.isEmpty() )
packagesMap.remove(pkgName);
}
}
}
finally
{
UnifiedLoaderRepository2.release();
}
} Deprecated! |
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
broadcaster.removeNotificationListener(listener);
} Deprecated!removeNotificationListener delegates to our broadcaster object |