com.caucho.loader
Class EnvironmentClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by com.caucho.loader.DynamicClassLoader
                  extended by com.caucho.loader.EnvironmentClassLoader
All Implemented Interfaces:
Make, DynamicClassLoaderMXBean, Dependency
Direct Known Subclasses:
ArtifactClassLoader, EnhancingClassLoader, SystemClassLoader

public class EnvironmentClassLoader
extends DynamicClassLoader

Class loader which checks for changes in class files and automatically picks up new jars.

DynamicClassLoaders can be chained creating one virtual class loader. From the perspective of the JDK, it's all one classloader. Internally, the class loader chain searches like a classpath.


Constructor Summary
protected EnvironmentClassLoader(java.lang.ClassLoader parent, java.lang.String id)
          Creates a new environment class loader.
 
Method Summary
 void addListener(EnvironmentListener listener)
          Adds a listener to detect environment lifecycle changes.
 void addLoaderListener(AddLoaderListener listener)
          Adds a child listener.
 void addScanListener(ScanListener listener)
          Adds a scan listener.
 void addScanPackage(java.net.URL url, java.lang.String rootPackage)
          Adds a virtual module root for scanning.
 void addScanRoot()
          Tells the classloader to scan the root classpath.
 void addURL(java.net.URL url)
          Adds the URL to the URLClassLoader.
 void applyVisibleModules(EnvironmentApply apply)
          Applies the action to all visible environment modules.
protected  void buildImportClassPath(java.util.ArrayList<java.lang.String> cp)
           
protected  void configureEnhancerEvent()
          Adds a listener to detect class loader changes.
protected  void configurePostEnhancerEvent()
          Adds a listener to detect class loader changes.
static EnvironmentClassLoader create()
          Creates a new environment class loader.
static EnvironmentClassLoader create(java.lang.ClassLoader parent)
          Creates a new environment class loader.
static EnvironmentClassLoader create(java.lang.ClassLoader parent, java.lang.String id)
          Creates a new environment class loader.
static EnvironmentClassLoader create(java.lang.String id)
          Creates a new environment class loader.
 ArtifactManager createArtifactManager()
          Returns the artifact manager
 void destroy()
          Destroys the class loader.
protected  java.lang.Class<?> findImportClass(java.lang.String name)
          Returns any import class, e.g.
 EnvironmentMXBean getAdmin()
          Returns the admin
 ArtifactManager getArtifactManager()
          Returns the artifact manager
 java.lang.Object getAttribute(java.lang.String name)
          Returns the named attributes
 java.lang.Throwable getConfigException()
          Gets the config exception.
protected  java.util.ArrayList<EnvironmentListener> getEnvironmentListeners()
          Returns the listeners.
 java.lang.String getHash()
          Add the custom packages to the classloader hash.
protected  java.net.URL getImportResource(java.lang.String name)
          Get resource from an artifact
protected  java.util.ArrayList<AddLoaderListener> getLoaderListeners()
          Returns the listeners.
 EnvironmentBean getOwner()
          Returns the environment's owner.
 java.net.URL getResource(java.lang.String name)
          Overrides getResource to implement caching.
 java.lang.String getResourceAlias(java.lang.String name)
           
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Overrides getResource to implement caching.
 void init()
          Initialize the environment.
protected  void initEnvironment()
           
 boolean isActive()
          Returns true if the environment is active
 java.lang.Object putIfAbsent(java.lang.String name, java.lang.Object obj)
          Sets the named attributes
 void putResourceAlias(java.lang.String name, java.lang.String actualName)
           
 java.lang.Object removeAttribute(java.lang.String name)
          Removes the named attributes
 void removeListener(EnvironmentListener listener)
          Adds a listener to detect environment lifecycle changes.
 void scan()
           
 java.lang.Object setAttribute(java.lang.String name, java.lang.Object obj)
          Sets the named attributes
 void setConfigException(java.lang.Throwable e)
          Sets the config exception.
 void setOwner(EnvironmentBean owner)
          Sets the environment's owner.
 void start()
          Marks the environment of the class loader as started.
 void stop()
          Stops the environment, closing down any resources.
 java.lang.String toString()
           
 void validate()
          Called when the completes.
 
Methods inherited from class com.caucho.loader.DynamicClassLoader
addCodeBasePath, addDependency, addJar, addJarManifestClassPath, addListener, addLoader, addLoader, addManifestClassPath, addNative, addParentPriorityPackage, addParentPriorityPackages, addPathClass, addPermission, addPermission, addPermissions, addPriorityPackage, addRoot, addTransformer, addURL, addURL, appendToClassPathForInstrumentation, buildClassPath, buildResourcePathSpecificFirst, buildSourcePath, clearModified, containsURL, containsURL, definePackage, findClass, findClassImpl, findLibrary, findPath, findResources, getClassEntry, getClassPath, getDependencyCheckInterval, getGlobalDependencyCheckInterval, getHash, getHashCrc, getId, getInstrumentableClassLoader, getListeners, getLoaders, getLocalClassPath, getNewTempClassLoader, getPermissions, getPermissions, getResourcePathSpecificFirst, getResources, getSourcePath, getThrowawayClassLoader, getTransformerList, getURLs, isDestroyed, isDirectoryLoader, isJarCacheEnabled, isJarCacheEnabledDefault, isModified, isModified, isModified, isModifiedNow, loadClass, loadClass, loadClass, loadClassEntry, loadClassImpl, logModified, make, removeListener, removeLoader, replace, resetDependencyCheckInterval, sendAddLoaderEvent, setDependencyCheckInterval, setEnableDependencyCheck, setGlobalDependencyCheckInterval, setId, setJarCacheEnabled, setOldLoader, setServletHack, toClassPath
 
Methods inherited from class java.net.URLClassLoader
definePackage, findResource, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnvironmentClassLoader

protected EnvironmentClassLoader(java.lang.ClassLoader parent,
                                 java.lang.String id)
Creates a new environment class loader.

Method Detail

create

public static EnvironmentClassLoader create()
Creates a new environment class loader.


create

public static EnvironmentClassLoader create(java.lang.String id)
Creates a new environment class loader.


create

public static EnvironmentClassLoader create(java.lang.ClassLoader parent)
Creates a new environment class loader.


create

public static EnvironmentClassLoader create(java.lang.ClassLoader parent,
                                            java.lang.String id)
Creates a new environment class loader.


getOwner

public EnvironmentBean getOwner()
Returns the environment's owner.


setOwner

public void setOwner(EnvironmentBean owner)
Sets the environment's owner.


setConfigException

public void setConfigException(java.lang.Throwable e)
Sets the config exception.


getConfigException

public java.lang.Throwable getConfigException()
Gets the config exception.


isActive

public boolean isActive()
Returns true if the environment is active


getAdmin

public EnvironmentMXBean getAdmin()
Returns the admin


init

public void init()
Initialize the environment.

Overrides:
init in class DynamicClassLoader

initEnvironment

protected void initEnvironment()

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the named attributes


setAttribute

public java.lang.Object setAttribute(java.lang.String name,
                                     java.lang.Object obj)
Sets the named attributes


putIfAbsent

public java.lang.Object putIfAbsent(java.lang.String name,
                                    java.lang.Object obj)
Sets the named attributes


removeAttribute

public java.lang.Object removeAttribute(java.lang.String name)
Removes the named attributes


getResource

public java.net.URL getResource(java.lang.String name)
Overrides getResource to implement caching.

Overrides:
getResource in class DynamicClassLoader
Parameters:
name - name of the resource

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Overrides getResource to implement caching.

Overrides:
getResourceAsStream in class DynamicClassLoader
Parameters:
name - the path to the resource
Returns:
an input stream to the resource

putResourceAlias

public void putResourceAlias(java.lang.String name,
                             java.lang.String actualName)

getResourceAlias

public java.lang.String getResourceAlias(java.lang.String name)
Overrides:
getResourceAlias in class DynamicClassLoader

addListener

public void addListener(EnvironmentListener listener)
Adds a listener to detect environment lifecycle changes.


removeListener

public void removeListener(EnvironmentListener listener)
Adds a listener to detect environment lifecycle changes.


getEnvironmentListeners

protected java.util.ArrayList<EnvironmentListener> getEnvironmentListeners()
Returns the listeners.


addLoaderListener

public void addLoaderListener(AddLoaderListener listener)
Adds a child listener.


getLoaderListeners

protected java.util.ArrayList<AddLoaderListener> getLoaderListeners()
Returns the listeners.


configureEnhancerEvent

protected void configureEnhancerEvent()
Adds a listener to detect class loader changes.

Overrides:
configureEnhancerEvent in class DynamicClassLoader

configurePostEnhancerEvent

protected void configurePostEnhancerEvent()
Adds a listener to detect class loader changes.

Overrides:
configurePostEnhancerEvent in class DynamicClassLoader

addURL

public void addURL(java.net.URL url)
Adds the URL to the URLClassLoader.

Overrides:
addURL in class DynamicClassLoader

addScanPackage

public void addScanPackage(java.net.URL url,
                           java.lang.String rootPackage)
Adds a virtual module root for scanning.

Parameters:
rootPackage -

getHash

public java.lang.String getHash()
Add the custom packages to the classloader hash.

Overrides:
getHash in class DynamicClassLoader

addScanRoot

public void addScanRoot()
Tells the classloader to scan the root classpath.

Overrides:
addScanRoot in class DynamicClassLoader

addScanListener

public void addScanListener(ScanListener listener)
Adds a scan listener.


createArtifactManager

public ArtifactManager createArtifactManager()
Returns the artifact manager


getArtifactManager

public ArtifactManager getArtifactManager()
Returns the artifact manager


findImportClass

protected java.lang.Class<?> findImportClass(java.lang.String name)
Returns any import class, e.g. from an artifact

Overrides:
findImportClass in class DynamicClassLoader

getImportResource

protected java.net.URL getImportResource(java.lang.String name)
Get resource from an artifact

Overrides:
getImportResource in class DynamicClassLoader

buildImportClassPath

protected void buildImportClassPath(java.util.ArrayList<java.lang.String> cp)
Overrides:
buildImportClassPath in class DynamicClassLoader

applyVisibleModules

public void applyVisibleModules(EnvironmentApply apply)
Applies the action to all visible environment modules. The action may apply to the same environment more than once.


validate

public void validate()
Called when the completes.

Overrides:
validate in class DynamicClassLoader

scan

public void scan()
Overrides:
scan in class DynamicClassLoader

start

public void start()
Marks the environment of the class loader as started. The class loader itself doesn't use this, but a callback might.


stop

public void stop()
Stops the environment, closing down any resources. The resources are closed in the reverse order that they're started

Overrides:
stop in class DynamicClassLoader

destroy

public void destroy()
Destroys the class loader.

Overrides:
destroy in class DynamicClassLoader

toString

public java.lang.String toString()
Overrides:
toString in class DynamicClassLoader