org.jboss.mx.loading
Class UnifiedLoaderRepository3

java.lang.Object
  extended byorg.jboss.mx.loading.LoaderRepository (src) 
      extended byorg.jboss.mx.loading.UnifiedLoaderRepository3
All Implemented Interfaces:
ClassLoaderRepository (src) , MBeanRegistration (src) , NotificationBroadcaster (src) , NotificationEmitter (src) , ServerConstants (src) , UnifiedLoaderRepository3MBean (src) , UnifiedLoaderRepositoryMBean (src)
Direct Known Subclasses:
HeirarchicalLoaderRepository3 (src)

public class UnifiedLoaderRepository3
extends LoaderRepository (src)
implements MBeanRegistration (src) , NotificationEmitter (src) , UnifiedLoaderRepository3MBean (src)

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.


Field Summary
 
Fields inherited from class org.jboss.mx.loading.LoaderRepository (src)
instance, loaders, translator
 
Fields inherited from interface org.jboss.mx.server.ServerConstants (src)
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(java.lang.ClassLoader loader)
          Add a class loader to the repository.
 boolean addClassLoaderURL(java.lang.ClassLoader cl, java.net.URL url)
          Update the set of URLs known to be associated with a previously added class loader.
 void addNotificationListener(NotificationListener (src)  listener, NotificationFilter (src)  filter, java.lang.Object handback)
          addNotificationListener delegates to the broadcaster object we hold.
 void cacheLoadedClass(java.lang.String name, java.lang.Class cls, java.lang.ClassLoader cl)
          Add a Class to the repository cache.
 java.lang.String displayClassInfo(java.lang.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
 java.lang.Class getCachedClass(java.lang.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 (src) getInstance()
           
 MBeanNotificationInfo (src) [] getNotificationInfo()
          Returns the notification metadata associated with the MBean.
 java.util.Set getPackageClassLoaders(java.lang.String className)
          Called by LoadMgr to obtain all class loaders for the given className
 java.net.URL getResource(java.lang.String name, java.lang.ClassLoader cl)
          Loads a resource following the Unified ClassLoader architecture
protected  java.net.URL getResourceFromGlobalCache(java.lang.String name)
          Check for a resource in the global cache Synchronizes access to globalResources using the loaderToResourcesMap monitor
protected  java.net.URL getResourceFromRepository(java.lang.String name, java.lang.ClassLoader cl)
           
 void getResources(java.lang.String name, java.lang.ClassLoader cl, java.util.List urls)
          Find all resource URLs for the given name.
 java.net.URL[] getURLs()
          This is a utility method a listing of the URL for all UnifiedClassLoaders associated with the repository.
 RepositoryClassLoader (src) getWrappingClassLoader(java.lang.ClassLoader cl)
          Get any wrapping classloader for the passed classloader
 java.lang.Class loadClass(java.lang.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.
 java.lang.Class loadClass(java.lang.String name, boolean resolve, java.lang.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.
 java.lang.Class loadClassBefore(java.lang.ClassLoader stop, java.lang.String className)
          Loads a class from the repository, using the classloaders that were registered before the given classloader.
 java.lang.Class loadClassFromCache(java.lang.String name)
          Lookup a Class from the repository cache.
 java.lang.Class loadClassWithout(java.lang.ClassLoader loader, java.lang.String className)
          Loads a class from the repository, excluding the given classloader.
 RepositoryClassLoader (src) newClassLoader(java.net.URL url, boolean addToRepository)
          Create RepositoryClassLoader and optionally add it to the repository
 RepositoryClassLoader (src) newClassLoader(java.net.URL url, java.net.URL origURL, boolean addToRepository)
          Create RepositoryClassLoader and optionally add it to the repository
 void postDeregister()
          This method is called by the MBeanServer after deregistration takes place.
 void postRegister(java.lang.Boolean registrationDone)
          This method is called by the MBeanServer after registration takes place or when registration fails.
 void preDeregister()
          This method is called by the MBeanServer before deregistration takes place.
 ObjectName (src) preRegister(MBeanServer (src)  server, ObjectName (src)  name)
          This method is called by the MBeanServer before registration takes place.
 LoaderRepository (src) registerClassLoader(RepositoryClassLoader (src)  ucl)
          This method provides an mbean-accessible way to add a UnifiedClassloader, and sends a notification when it is added.
 void removeClassLoader(java.lang.ClassLoader loader)
          Remove the class loader from the repository.
 void removeNotificationListener(NotificationListener (src)  listener)
          removeNotificationListener delegates to our broadcaster object
 void removeNotificationListener(NotificationListener (src)  listener, NotificationFilter (src)  filter, java.lang.Object handback)
          Removes a listener from the Emitter.
 
Methods inherited from class org.jboss.mx.loading.LoaderRepository (src)
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 (src)
getTranslator, setTranslator
 

Constructor Detail

UnifiedLoaderRepository3

public UnifiedLoaderRepository3()
Method Detail

newClassLoader

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

Specified by:
newClassLoader in interface UnifiedLoaderRepositoryMBean (src)
Specified by:
newClassLoader in class LoaderRepository (src)
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:
java.lang.Exception

newClassLoader

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

Specified by:
newClassLoader in interface UnifiedLoaderRepositoryMBean (src)
Specified by:
newClassLoader in class LoaderRepository (src)
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:
java.lang.Exception

getCacheSize

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

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

getClassLoadersSize

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

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

flush

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

Specified by:
flush in interface UnifiedLoaderRepository3MBean (src)

getCachedClass

public java.lang.Class getCachedClass(java.lang.String classname)
Overrides:
getCachedClass in class LoaderRepository (src)

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve,
                                 java.lang.ClassLoader cl)
                          throws java.lang.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 (src)
Parameters:
name -
resolve -
cl -
Returns:
Throws:
java.lang.ClassNotFoundException

getPackageClassLoaders

public java.util.Set getPackageClassLoaders(java.lang.String className)
Called by LoadMgr to obtain all class loaders for the given className

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

loadClassFromCache

public java.lang.Class loadClassFromCache(java.lang.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(java.lang.String name,
                             java.lang.Class cls,
                             java.lang.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 java.net.URL getResource(java.lang.String name,
                                java.lang.ClassLoader cl)
Loads a resource following the Unified ClassLoader architecture

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

getResources

public void getResources(java.lang.String name,
                         java.lang.ClassLoader cl,
                         java.util.List 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 (src)
Parameters:
name - the resource name
cl - the requesting class loader
urls - a list into which the located resource URLs will be placed

getResourceFromGlobalCache

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

Parameters:
name -
Returns:

getResourceFromRepository

protected java.net.URL getResourceFromRepository(java.lang.String name,
                                                 java.lang.ClassLoader cl)

getURLs

public java.net.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 (src)
Overrides:
getURLs in class LoaderRepository (src)

displayClassInfo

public java.lang.String displayClassInfo(java.lang.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 (src)

loadClass

public java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.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 (src)
Specified by:
loadClass in class LoaderRepository (src)
Parameters:
className - - the class to load
Returns:
the found class
Throws:
java.lang.ClassNotFoundException - when there is no such class

loadClassWithout

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

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

loadClassBefore

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

Specified by:
loadClassBefore in interface ClassLoaderRepository (src)
Specified by:
loadClassBefore in class LoaderRepository (src)
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:
java.lang.ClassNotFoundException - if none of the consulted classloaders were able to load the requested class

getWrappingClassLoader

public RepositoryClassLoader (src)  getWrappingClassLoader(java.lang.ClassLoader cl)
Get any wrapping classloader for the passed classloader

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

addClassLoader

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

Specified by:
addClassLoader in class LoaderRepository (src)

addClassLoaderURL

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

Specified by:
addClassLoaderURL in class LoaderRepository (src)
Parameters:
cl -
url -

removeClassLoader

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

Specified by:
removeClassLoader in interface UnifiedLoaderRepositoryMBean (src)
Specified by:
removeClassLoader in class LoaderRepository (src)
Parameters:
loader -

registerClassLoader

public LoaderRepository (src)  registerClassLoader(RepositoryClassLoader (src)  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 (src)
Parameters:
ucl - an UnifiedClassLoader value
Returns:
a LoaderRepository value

getInstance

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

addNotificationListener

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

Specified by:
addNotificationListener in interface NotificationBroadcaster (src)
Parameters:
listener - a NotificationListener value
filter - a NotificationFilter value
handback - an Object value
Throws:
java.lang.IllegalArgumentException - if an error occurs

getNotificationInfo

public MBeanNotificationInfo (src) [] getNotificationInfo()
Description copied from interface: NotificationBroadcaster (src)
Returns the notification metadata associated with the MBean.

Specified by:
getNotificationInfo in interface NotificationBroadcaster (src)
Returns:
See Also:
MBeanNotificationInfo (src)

removeNotificationListener

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

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

removeNotificationListener

public void removeNotificationListener(NotificationListener (src)  listener,
                                       NotificationFilter (src)  filter,
                                       java.lang.Object handback)
                                throws ListenerNotFoundException (src) 
Description copied from interface: NotificationEmitter (src)
Removes a listener from the Emitter.

Only the listener, filter, handback triplet is removed

Specified by:
removeNotificationListener in interface NotificationEmitter (src)
Parameters:
listener - the listener object to remove
filter - the filter registered with the listener
handback - the handback object associated with the registered listener
Throws:
ListenerNotFoundException (src) - if the listener was not found

preRegister

public ObjectName (src)  preRegister(MBeanServer (src)  server,
                              ObjectName (src)  name)
                       throws java.lang.Exception
Description copied from interface: MBeanRegistration (src)
This method is called by the MBeanServer before registration takes place. The MBean is passed a reference of the MBeanServer it is about to be registered with. The MBean must return the ObjectName it will be registered with. The MBeanServer can pass a suggested object depending upon how the MBean is registered.

The MBean can stop the registration by throwing an exception.The exception is forwarded to the invoker wrapped in an MBeanRegistrationException.

Specified by:
preRegister in interface MBeanRegistration (src)
Returns:
the actual ObjectName to register this MBean with.
Throws:
java.lang.Exception - for any error, the MBean is not registered.

postRegister

public void postRegister(java.lang.Boolean registrationDone)
Description copied from interface: MBeanRegistration (src)
This method is called by the MBeanServer after registration takes place or when registration fails.

Specified by:
postRegister in interface MBeanRegistration (src)
Parameters:
registrationDone - the MBeanServer passes true when the MBean was registered, false otherwise.

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Description copied from interface: MBeanRegistration (src)
This method is called by the MBeanServer before deregistration takes place.

The MBean can throw an exception, this will stop the deregistration. The exception is forwarded to the invoker wrapped in an MBeanRegistrationException.

Specified by:
preDeregister in interface MBeanRegistration (src)
Throws:
java.lang.Exception

postDeregister

public void postDeregister()
Description copied from interface: MBeanRegistration (src)
This method is called by the MBeanServer after deregistration takes place.

Specified by:
postDeregister in interface MBeanRegistration (src)