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 StringfindJavaExecutable(String executable) Find a JDK/JRE programReturns the names of all the available agent classesReturns all the session configurations available on the class pathstatic StringgetClassPackageName(String classFullName) Returns the package name for this class name.static StringgetClassSimpleName(String classFullName) Returns the simple name for a full class name.static MadkitClassLoaderReturns 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 booleanloadJarsFromDirectory(String directoryPath) Loads all jar files from a directorystatic booleanAdds a directory or a jar file to the class path.static voidThis is only used by ant scripts for building MDK jar files.static voidreloadClass(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, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods 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:
loadClassin 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 theClassLoaderof 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:
trueif at least one new jar has been loaded
-
getClassPackageName
Returns the package name for this class name. E.g.java.lang.Objectas input givesjava.langas output.- Parameters:
classFullName- the full name of a class- Returns:
- the package name or
nullif no package is defined
-
getClassSimpleName
Returns the simple name for a full class name. E.g.java.lang.Objectas input givesObjectas 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:
trueif 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
mainmethod.
-
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
nullif 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:
FileNotFoundExceptionIOException
-
toString
-