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
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
findJavaExecutable
(String executable) Find a JDK/JRE programstatic <T extends Agent>
TgetAgentInstance
(String agentClass) Returns an instance of a class from its name using the current class loader.Returns the names of all the available agent classesstatic 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 availableClass
<?> 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 withloadClass(String)
, will reflect compilation changes during run time. In fact, usingloadClass(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,Agent.launchAgent(String, int)
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
-
getClassSimpleName
-
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
-
getAllAgentClasses
-
getMDKFiles
-
getXMLConfigurations
-
getAgentsWithMain
-
getAgentInstance
Returns an instance of a class from its name using the current class loader.- Type Parameters:
T
- the type of the agent- Parameters:
agentClass
- the name of the class- Returns:
- an instance of the class or
null
if the class cannot be found.
-
findJavaExecutable
-
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
- the command line arguments- Throws:
FileNotFoundException
- if the file is not foundIOException
- if the file cannot be written
-
toString
-