JBossMX Parent POM 6.0.0.GA

org.jboss.mx.loading
Class UnifiedLoaderRepository3

java.lang.Object
  extended by org.jboss.mx.loading.LoaderRepository
      extended by org.jboss.mx.loading.UnifiedLoaderRepository3
All Implemented Interfaces:
ClassLoaderRepository, MBeanRegistration, NotificationBroadcaster, UnifiedLoaderRepository3MBean, UnifiedLoaderRepositoryMBean, ServerConstants
Direct Known Subclasses:
HeirarchicalLoaderRepository3

public class UnifiedLoaderRepository3
extends LoaderRepository
implements MBeanRegistration, NotificationBroadcaster, UnifiedLoaderRepository3MBean

A repository of class loaders that form a flat namespace of classes and resources. This version uses UnifiedClassLoader3 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.

Version:
$Revision: 85671 $ just a hint... xdoclet not really used
Author:
Scott Stark., Adrian Brock.

Field Summary
 
Fields inherited from class org.jboss.mx.loading.LoaderRepository
instance, loaders, translator
 
Fields inherited from interface org.jboss.mx.server.ServerConstants
CLASS_REMOVED, CLASSLOADER, CLASSLOADER_ADDED, CLASSLOADER_REMOVED, DEFAULT_DOMAIN, DEFAULT_LOADER_NAME, DEFAULT_LOADER_REPOSITORY_CLASS, DEFAULT_MBEAN_REGISTRY_CLASS, DEFAULT_MBEAN_SERVER_BUILDER_CLASS, DEFAULT_REQUIRED_MODELMBEAN_CLASS, DEFAULT_SCOPED_REPOSITORY_CLASS, DEFAULT_SCOPED_REPOSITORY_PARSER_CLASS, IMPLEMENTATION_NAME, IMPLEMENTATION_VENDOR, IMPLEMENTATION_VERSION, JMI_DOMAIN, LOADER_REPOSITORY_CLASS_PROPERTY, MBEAN_REGISTRY, MBEAN_REGISTRY_CLASS_PROPERTY, MBEAN_SERVER_BUILDER_CLASS_PROPERTY, MBEAN_SERVER_CONFIGURATION, MBEAN_SERVER_DELEGATE, OPTIMIZE_REFLECTED_DISPATCHER, REQUIRED_MODELMBEAN_CLASS_PROPERTY, SPECIFICATION_NAME, SPECIFICATION_VENDOR, SPECIFICATION_VERSION, UNIFIED_LOADER_REPOSITORY_CLASS
 
Constructor Summary
UnifiedLoaderRepository3()
           
 
Method Summary
 void addClassLoader(ClassLoader loader)
          Add a class loader to the repository.
 boolean addClassLoaderURL(ClassLoader cl, URL url)
          Update the set of URLs known to be associated with a previously added class loader.
 void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
          addNotificationListener delegates to the broadcaster object we hold.
 void cacheLoadedClass(String name, Class<?> cls, ClassLoader cl)
          Add a Class to the repository cache.
 String displayClassInfo(String className)
          A utility method that iterates over all repository class loaders and display the class information for every UCL that contains the given className
 void flush()
          Flush the ULR classes cache
 Class<?> getCachedClass(String classname)
           
 int getCacheSize()
          Get the number of classes loaded into the ULR cache.
 int getClassLoadersSize()
          Get the number of UnifiedClassLoader3s (UCLs) in the ULR
 LoaderRepository getInstance()
           
 MBeanNotificationInfo[] getNotificationInfo()
           
 Set<ClassLoader> getPackageClassLoaders(String className)
          Called by LoadMgr to obtain all class loaders for the given className
 URL getResource(String name, ClassLoader cl)
          Loads a resource following the Unified ClassLoader architecture
protected  URL getResourceFromGlobalCache(String name)
          Check for a resource in the global cache Synchronizes access to globalResources using the loaderToResourcesMap monitor
protected  URL getResourceFromRepository(String name, ClassLoader cl)
           
 void getResources(String name, ClassLoader cl, List<URL> urls)
          Find all resource URLs for the given name.
 URL[] getURLs()
          This is a utility method a listing of the URL for all UnifiedClassLoaders associated with the repository.
 RepositoryClassLoader getWrappingClassLoader(ClassLoader cl)
          Get any wrapping classloader for the passed classloader
 Class<?> loadClass(String className)
          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.
 Class<?> loadClass(String name, boolean resolve, ClassLoader cl)
          Unlike other implementations of LoaderRepository, this method does nothing but ask the UnifiedClassLoader3 to load the class as UCL3s do not use this method.
 Class<?> loadClassBefore(ClassLoader stop, String className)
          Loads a class from the repository, using the classloaders that were registered before the given classloader.
 Class<?> loadClassFromCache(String name)
          Lookup a Class from the repository cache.
 Class<?> loadClassWithout(ClassLoader loader, String className)
          Loads a class from the repository, excluding the given classloader.
 RepositoryClassLoader newClassLoader(URL url, boolean addToRepository)
          Create RepositoryClassLoader and optionally add it to the repository
 RepositoryClassLoader newClassLoader(URL url, URL origURL, boolean addToRepository)
          Create RepositoryClassLoader and optionally add it to the repository
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
 LoaderRepository registerClassLoader(RepositoryClassLoader ucl)
          This method provides an mbean-accessible way to add a UnifiedClassloader, and sends a notification when it is added.
 void removeClassLoader(ClassLoader loader)
          Remove the class loader from the repository.
 void removeNotificationListener(NotificationListener listener)
          removeNotificationListener delegates to our broadcaster object
 
Methods inherited from class org.jboss.mx.loading.LoaderRepository
compare, getLoaders, getNativeClassForName, getTranslator, reverseCompare, setTranslator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.mx.loading.UnifiedLoaderRepositoryMBean
getTranslator, setTranslator
 

Constructor Detail

UnifiedLoaderRepository3

public UnifiedLoaderRepository3()
Method Detail

newClassLoader

public RepositoryClassLoader newClassLoader(URL url,
                                            boolean addToRepository)
                                     throws Exception
Description copied from class: LoaderRepository
Create RepositoryClassLoader and optionally add it to the repository

Specified by:
newClassLoader in interface UnifiedLoaderRepositoryMBean
Specified by:
newClassLoader in class LoaderRepository
Parameters:
url - the URL to use for class loading
addToRepository - a flag indicating if the CL should be added to the repository
Returns:
the UCL instance
Throws:
Exception

newClassLoader

public RepositoryClassLoader newClassLoader(URL url,
                                            URL origURL,
                                            boolean addToRepository)
                                     throws Exception
Description copied from class: LoaderRepository
Create RepositoryClassLoader and optionally add it to the repository

Specified by:
newClassLoader in interface UnifiedLoaderRepositoryMBean
Specified by:
newClassLoader in class LoaderRepository
Parameters:
url - the URL to use for class loading
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.
addToRepository - a flag indicating if the CL should be added to the repository
Returns:
the CL instance
Throws:
Exception

getCacheSize

public int getCacheSize()
Description copied from interface: UnifiedLoaderRepository3MBean
Get the number of classes loaded into the ULR cache.

Specified by:
getCacheSize in interface UnifiedLoaderRepository3MBean
Returns:
the classes cache size.

getClassLoadersSize

public int getClassLoadersSize()
Description copied from interface: UnifiedLoaderRepository3MBean
Get the number of UnifiedClassLoader3s (UCLs) in the ULR

Specified by:
getClassLoadersSize in interface UnifiedLoaderRepository3MBean
Returns:
the number of UCLs in the ULR

flush

public void flush()
Description copied from interface: UnifiedLoaderRepository3MBean
Flush the ULR classes cache

Specified by:
flush in interface UnifiedLoaderRepository3MBean

getCachedClass

public Class<?> getCachedClass(String classname)
Overrides:
getCachedClass in class LoaderRepository

loadClass

public Class<?> loadClass(String name,
                          boolean resolve,
                          ClassLoader cl)
                   throws ClassNotFoundException
Unlike other implementations of LoaderRepository, this method does nothing but ask the UnifiedClassLoader3 to load the class as UCL3s do not use this method.

Specified by:
loadClass in class LoaderRepository
Returns:
the class
Throws:
ClassNotFoundException

getPackageClassLoaders

public Set<ClassLoader> getPackageClassLoaders(String className)
Called by LoadMgr to obtain all class loaders for the given className

Specified by:
getPackageClassLoaders in interface UnifiedLoaderRepository3MBean
Returns:
Set, may be null

loadClassFromCache

public Class<?> loadClassFromCache(String name)
Lookup a Class from the repository cache.

Parameters:
name - the fully qualified class name
Returns:
the cached Class if found, null otherwise

cacheLoadedClass

public void cacheLoadedClass(String name,
                             Class<?> cls,
                             ClassLoader cl)
Add a Class to the repository cache.

Parameters:
name - the fully qualified class name
cls - the Class instance
cl - the repository UCL

getResource

public URL getResource(String name,
                       ClassLoader cl)
Loads a resource following the Unified ClassLoader architecture

Specified by:
getResource in class LoaderRepository
Parameters:
name - the resource name
cl - the requesting class loader
Returns:
The resource URL if found, null otherwise

getResources

public void getResources(String name,
                         ClassLoader cl,
                         List<URL> urls)
Find all resource URLs for the given name. This is entails an exhuastive search of the repository and is an expensive operation.

Specified by:
getResources in class LoaderRepository
Parameters:
name - the resource name
cl - the requesting class loader
urls - a list into which the located resource URLs will be placed

getResourceFromGlobalCache

protected URL getResourceFromGlobalCache(String name)
Check for a resource in the global cache Synchronizes access to globalResources using the loaderToResourcesMap monitor

Parameters:
name -
Returns:
the URL

getResourceFromRepository

protected URL getResourceFromRepository(String name,
                                        ClassLoader cl)

getURLs

public URL[] getURLs()
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.

Specified by:
getURLs in interface UnifiedLoaderRepositoryMBean
Overrides:
getURLs in class LoaderRepository

displayClassInfo

public String displayClassInfo(String className)
A utility method that iterates over all repository class loaders and display the class information for every UCL that contains the given className

Specified by:
displayClassInfo in interface UnifiedLoaderRepository3MBean
Returns:
the class info

loadClass

public Class<?> loadClass(String className)
                   throws ClassNotFoundException
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.

Specified by:
loadClass in interface ClassLoaderRepository
Specified by:
loadClass in class LoaderRepository
Parameters:
className - - the class to load
Returns:
the found class
Throws:
ClassNotFoundException - when there is no such class

loadClassWithout

public Class<?> loadClassWithout(ClassLoader loader,
                                 String className)
                          throws ClassNotFoundException
Loads a class from the repository, excluding the given classloader.

Specified by:
loadClassWithout in interface ClassLoaderRepository
Specified by:
loadClassWithout in class LoaderRepository
Parameters:
loader - the classloader to exclude
className - the class to load
Returns:
the found class
Throws:
ClassNotFoundException - when there is no such class

loadClassBefore

public Class<?> loadClassBefore(ClassLoader stop,
                                String className)
                         throws ClassNotFoundException
Loads a class from the repository, using the classloaders that were registered before the given classloader.

Specified by:
loadClassBefore in interface ClassLoaderRepository
Specified by:
loadClassBefore in class LoaderRepository
Parameters:
stop - consult all the classloaders registered before this one in an attempt to load a class
className - name of the class to load
Returns:
loaded class instance
Throws:
ClassNotFoundException - if none of the consulted classloaders were able to load the requested class

getWrappingClassLoader

public RepositoryClassLoader getWrappingClassLoader(ClassLoader cl)
Get any wrapping classloader for the passed classloader

Specified by:
getWrappingClassLoader in interface UnifiedLoaderRepositoryMBean
Parameters:
cl - the wrapped classloader
Returns:
the wrapping classloader or null if not wrapped

addClassLoader

public void addClassLoader(ClassLoader loader)
Add a class loader to the repository.

Specified by:
addClassLoader in class LoaderRepository
Parameters:
loader - the classloader

addClassLoaderURL

public boolean addClassLoaderURL(ClassLoader cl,
                                 URL url)
Description copied from class: LoaderRepository
Update the set of URLs known to be associated with a previously added class loader.

Specified by:
addClassLoaderURL in class LoaderRepository
Returns:
true if added

removeClassLoader

public void removeClassLoader(ClassLoader loader)
Remove the class loader from the repository. This synchronizes on the this.classLoaders

Specified by:
removeClassLoader in interface UnifiedLoaderRepositoryMBean
Specified by:
removeClassLoader in class LoaderRepository

registerClassLoader

public LoaderRepository registerClassLoader(RepositoryClassLoader ucl)
This method provides an mbean-accessible way to add a UnifiedClassloader, and sends a notification when it is added.

Specified by:
registerClassLoader in interface UnifiedLoaderRepositoryMBean
Parameters:
ucl - an UnifiedClassLoader value
Returns:
a LoaderRepository value

getInstance

public LoaderRepository getInstance()
Specified by:
getInstance in interface UnifiedLoaderRepositoryMBean

addNotificationListener

public void addNotificationListener(NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
                             throws IllegalArgumentException
addNotificationListener delegates to the broadcaster object we hold.

Specified by:
addNotificationListener in interface NotificationBroadcaster
Parameters:
listener - a NotificationListener value
filter - a NotificationFilter value
handback - an Object value
Throws:
IllegalArgumentException - if an error occurs

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()
Specified by:
getNotificationInfo in interface NotificationBroadcaster
Returns:

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
                                throws ListenerNotFoundException
removeNotificationListener delegates to our broadcaster object

Specified by:
removeNotificationListener in interface NotificationBroadcaster
Parameters:
listener - a NotificationListener value
Throws:
ListenerNotFoundException - if an error occurs

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception

postRegister

public void postRegister(Boolean registrationDone)
Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
                   throws Exception
Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface MBeanRegistration

JBossMX Parent POM 6.0.0.GA

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.