public class MultiClassLoader
extends java.lang.ClassLoader
To use this class loader, set this property when starting the server:
-Djava.system.class.loader=com.goldencode.p2j.classloader.MultiClassLoader
Modifier and Type | Field and Description |
---|---|
private static java.util.Set<java.lang.String> |
classpathJars
A set containing all jars added to the classpath when the server was started.
|
private java.util.Map<java.lang.String,JarClassLoader> |
jclByClasses
Map each class to the classloader which handles it.
|
private java.util.Map<java.lang.String,JarClassLoader> |
loaders
Map containing as key the jar name and as value its associated class loader.
|
private static java.util.logging.Logger |
LOG
logger
|
private static java.lang.String |
managedLibsDir
Managed customer libraries directory path.
|
Constructor and Description |
---|
MultiClassLoader(java.lang.ClassLoader parent)
C'tor.
|
Modifier and Type | Method and Description |
---|---|
static ErrorCode |
addJarLoader(java.lang.String jarName)
Register the given jar to be handled by its own class loader.
|
private ErrorCode |
addJarLoaderImpl(java.lang.String jarName,
boolean fullPath)
Register the given jar to be handled by its own class loader.
|
private void |
appendToClassPathForInstrumentation(java.lang.String path)
To support dynamic additions to the class path at runtime, the class loader needs to define
this private method.
|
protected java.lang.Class<?> |
findClass(java.lang.String name)
Find and load the class with the given name.
|
protected java.net.URL |
findResource(java.lang.String name)
Finds the resource with the given name.
|
java.lang.Class<?> |
getClass(java.lang.String name)
Find and load the class with the given name.
|
static boolean |
handledByJar(java.lang.Class<?> clazz,
java.lang.String jarName)
Check if the given class is handled by a custom jar loader for the given
jar.
|
static boolean |
handledByJar(java.lang.String className,
java.lang.String jarName)
Check if the given class is handled by a custom jar loader for the given
jar.
|
static ClassInfo[] |
listClasses(java.lang.String jarName)
List all classes in the given jar.
|
static java.lang.String[] |
listRegisteredJars()
List the jars handled by custom class loaders.
|
static java.lang.String[] |
listUnregisteredJars()
List the jars which may be handled by custom class loaders (they reside
in the given path, are not yet handled by custom class loaders and are
not in the classpath).
|
java.lang.Class<?> |
loadClass(java.lang.String name)
Find and load the class with the given name.
|
static java.lang.String |
managedCustomerLibs()
Get the managed customer libs folder.
|
static java.lang.String |
prettyName(java.lang.String path)
Get the actual jar name from the given path.
|
static ErrorCode |
removeJarLoader(java.lang.String jarName)
Remove the classloader associated with the given jar.
|
private ErrorCode |
removeJarLoaderImpl(java.lang.String jarName)
Remove the classloader associated with the given jar.
|
static java.lang.String |
resolveJarName(java.lang.String jarName,
boolean fullPath)
Resolve the jar name and return it as an unique name.
|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
private static final java.util.logging.Logger LOG
private final java.util.Map<java.lang.String,JarClassLoader> loaders
private final java.util.Map<java.lang.String,JarClassLoader> jclByClasses
private static volatile java.lang.String managedLibsDir
null
then
it hasn't been read yet, otherwise it is contained in the zero element
of the array.private static final java.util.Set<java.lang.String> classpathJars
public MultiClassLoader(java.lang.ClassLoader parent)
parent
- Parent class loader.public static boolean handledByJar(java.lang.Class<?> clazz, java.lang.String jarName)
clazz
- The class object.jarName
- The jar name.public static boolean handledByJar(java.lang.String className, java.lang.String jarName)
className
- The name of the class to be checked.jarName
- The jar name.public static ErrorCode addJarLoader(java.lang.String jarName) throws RestrictedUseException
jarName
- The jar name.ErrorCode.SUCCESS
if the loading was done. Else,
it returns an error code
.RestrictedUseException
- if called improperly.public static ErrorCode removeJarLoader(java.lang.String jarName) throws RestrictedUseException
jarName
- The jar name.ErrorCode.SUCCESS
if the deregistration was done. Else,
it returns an error code
.RestrictedUseException
- if called improperly.public static java.lang.String managedCustomerLibs()
/server/default/managed-libs-dir
or
/server/<serverID>/managed-libs-dir
).null
if it is not
specified.public static java.lang.String prettyName(java.lang.String path)
path
- The jar name, with full path.public static java.lang.String resolveJarName(java.lang.String jarName, boolean fullPath)
null
.jarName
- The jar name.fullPath
- true
if the jarName
contains also
the jar's path. When false
, it is assumed that
the path is the one specified in the "customer_libs" system
property.public static ClassInfo[] listClasses(java.lang.String jarName)
jarName
- The jar name.null
in case
of error.public static java.lang.String[] listRegisteredJars()
public static java.lang.String[] listUnregisteredJars()
The unregistered jars are searched in the customer_libs property specified at server startup. If it was not specified, then it will return an empty list.
protected java.net.URL findResource(java.lang.String name)
findResource
in class java.lang.ClassLoader
name
- The resource nameprotected java.lang.Class<?> findClass(java.lang.String name) throws java.lang.ClassNotFoundException
findClass
in class java.lang.ClassLoader
Class
object.java.lang.ClassNotFoundException
- If the class can not be found or class linkage has error
occurred.public java.lang.Class<?> loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
Class
object.java.lang.ClassNotFoundException
- If the class can not be found or class linkage has error
occurred.public java.lang.Class<?> getClass(java.lang.String name) throws java.lang.ClassNotFoundException
Class
object, or null
if this class
does not belong to any of the registered jars.java.lang.ClassNotFoundException
- If the class belongs must be handled by a JarClassLoader
but can not be loaded.private void appendToClassPathForInstrumentation(java.lang.String path)
This method does not have to be public.
path
- The full path of the jar to be appended.private ErrorCode addJarLoaderImpl(java.lang.String jarName, boolean fullPath)
jarName
- The jar name.fullPath
- true
if the jarName
contains also
the jar's path. When false
, it is assumed that
the path is the one specified in the "customer_libs" system
property.ErrorCode.SUCCESS
if the loading was done. Else,
it returns an error code
.private ErrorCode removeJarLoaderImpl(java.lang.String jarName)
jarName
- The jar name.ErrorCode.SUCCESS
if the deregistration was done. Else,
it returns an error code
.