Package madkit.kernel
Class MadkitClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
madkit.kernel.MadkitClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
The MadkitClassLoader is the class loader used by MaDKit. It enables some
specific features such as class hot reloading, jar loading, etc.
- Since:
- MaDKit 4.0
- Version:
- 5.3
- Author:
- Fabien Michel, Jacques Ferber
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
findJavaExecutable
(String executable) Find a JDK/JRE programReturns the names of all the available agent classesReturns all the session configurations available on the class pathstatic String
getClassPackageName
(String classFullName) Returns the package name for this class name.static String
getClassSimpleName
(String classFullName) Returns the simple name for a full class name.static MadkitClassLoader
Returns the last class loader, thus having all the loaded jars on the classpath.Returns the names of all the mdk properties files availableReturns the names of all the xml configuration files availableprotected Class<?>
static boolean
loadJarsFromDirectory
(String directoryPath) Loads all jar files from a directorystatic boolean
Adds a directory or a jar file to the class path.static void
This is only used by ant scripts for building MDK jar files.static void
reloadClass
(String name) Schedule the reloading of the byte code of a class for its next loading.toString()
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Method Details
-
getLoader
Returns the last class loader, thus having all the loaded jars on the classpath.- Returns:
- the last class loader.
-
loadClass
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
reloadClass
Schedule the reloading of the byte code of a class for its next loading. So new instances, created usingClass.newInstance()
on a class object obtained withClassLoader.loadClass(String)
, will reflect compilation changes during run time. In fact, usingClassLoader.loadClass(String)
on the current MDK class loader obtained withgetLoader()
returns the class object corresponding to the last compilation of the java code available on the class path. Especially, this may return a different version thanClass.forName(String)
becauseClass.forName(String)
uses theClassLoader
of the caller's current class which could be different than the current one (i.e. the one obtainedgetLoader()
) if several reloads have been done. Especially,AbstractAgent.launchAgent(String, int, boolean)
always uses the newest version of an agent class.- Parameters:
name
- The fully qualified class name of the class- Throws:
ClassNotFoundException
- if the class cannot be found on the class path
-
loadJarsFromDirectory
Loads all jar files from a directory- Parameters:
directoryPath
- directory's path- Returns:
true
if at least one new jar has been loaded
-
getClassPackageName
Returns the package name for this class name. E.g.java.lang.Object
as input givesjava.lang
as output.- Parameters:
classFullName
- the full name of a class- Returns:
- the package name or
null
if no package is defined
-
getClassSimpleName
Returns the simple name for a full class name. E.g.java.lang.Object
as input givesObject
as output.- Parameters:
classFullName
- the full name of a class- Returns:
- the simple name of a class name
-
loadUrl
Adds a directory or a jar file to the class path.- Parameters:
url
- the resource to add- Returns:
true
if this url was not already loaded
-
getAvailableConfigurations
Returns all the session configurations available on the class path- Returns:
- a set of session configurations available on the class path
-
getAllAgentClasses
Returns the names of all the available agent classes- Returns:
- All the agent classes available on the class path
-
getMDKFiles
Returns the names of all the mdk properties files available- Returns:
- All the mdk files available on the class path
-
getXMLConfigurations
Returns the names of all the xml configuration files available- Returns:
- All the xml configuration file available on the class path
-
getAgentsWithMain
- Returns:
- all the agent classes having a
main
method.
-
findJavaExecutable
Find a JDK/JRE program- Parameters:
executable
- the name of the Java program to look for. E.g. "jarsigner", without file extension.- Returns:
- the path to the executable or
null
if not found.
-
main
This is only used by ant scripts for building MDK jar files. This will create a file in java.io.tmpdir named agents.classes containing the agent classes which are on the class path and other information- Parameters:
args
-- Throws:
FileNotFoundException
IOException
-
toString
-