madkit.kernel

## Class MadkitClassLoader

- java.lang.Object
- - java.lang.ClassLoader
  - - java.security.SecureClassLoader
    - - java.net.URLClassLoader
      - - madkit.kernel.MadkitClassLoader

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public final class MadkitClassLoader
      extends URLClassLoader

  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.2
  Author:
    Fabien Michel, Jacques Ferber

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `findJavaExecutable(String executable)` Find a JDK/JRE program
    `static Set<String>` | `getAgentsWithMain()`
    `static Set<String>` | `getAllAgentClasses()` Returns the names of all the available agent classes
    `static Set<MASModel>` | `getAvailableConfigurations()` Returns all the session configurations available on the class path
    `static 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` | `getLoader()` Returns the last class loader, thus having all the loaded jars on the classpath.
    `static Set<String>` | `getMDKFiles()` Returns the names of all the mdk properties files available
    `static Set<String>` | `getXMLConfigurations()` Returns the names of all the xml configuration files available
    `protected Class<?>` | `loadClass(String name, boolean resolve)`
    `static boolean` | `loadJarsFromDirectory(String directoryPath)` Loads all the jars present in a directory
    `static boolean` | `loadUrl(URL url)` Adds a directory or a jar file to the class path.
    `static void` | `main(String[] args)` 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.
    `String` | `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, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### getLoader

          public static MadkitClassLoader getLoader()

      Returns the last class loader, thus having all the loaded jars on the classpath.
      Returns:
        the last class loader.

    - #### loadClass

          protected Class<?> loadClass(String name,
                           boolean resolve)
                                throws ClassNotFoundException

      Overrides:
        `loadClass` in class `ClassLoader`
      Throws:
        `ClassNotFoundException`

    - #### reloadClass

          public static void reloadClass(String name)
                                  throws ClassNotFoundException

      Schedule the reloading of the byte code of a class for its next loading. So new instances, created using `Class.newInstance()` on a class object obtained with `ClassLoader.loadClass(String)`, will reflect compilation changes during run time. In fact, using `ClassLoader.loadClass(String)` on the current MDK class loader obtained with `getLoader()` 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 than `Class.forName(String)` because `Class.forName(String)` uses the `ClassLoader` of the caller's current class which could be different than the current one (i.e. the one obtained `getLoader()`) 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

          public static boolean loadJarsFromDirectory(String directoryPath)

      Loads all the jars present in a directory
      Parameters:
        `directoryPath` - directory's path
      Returns:
        `true` if at least one new jar has been loaded

    - #### getClassPackageName

          public static String getClassPackageName(String classFullName)

      Returns the package name for this class name. E.g. `java.lang.Object` as input gives `java.lang` as output.
      Parameters:
        `classFullName` - the full name of a class
      Returns:
        the package name or `null` if no package is defined

    - #### getClassSimpleName

          public static String getClassSimpleName(String classFullName)

      Returns the simple name for a full class name. E.g. `java.lang.Object` as input gives `Object` as output.
      Parameters:
        `classFullName` - the full name of a class
      Returns:
        the simple name of a class name

    - #### loadUrl

          public static boolean loadUrl(URL url)

      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

          public static Set<MASModel> getAvailableConfigurations()

      Returns all the session configurations available on the class path
      Returns:
        a set of session configurations available on the class path

    - #### getAllAgentClasses

          public static Set<String> getAllAgentClasses()

      Returns the names of all the available agent classes
      Returns:
        All the agent classes available on the class path

    - #### getMDKFiles

          public static Set<String> getMDKFiles()

      Returns the names of all the mdk properties files available
      Returns:
        All the mdk files available on the class path

    - #### getXMLConfigurations

          public static Set<String> getXMLConfigurations()

      Returns the names of all the xml configuration files available
      Returns:
        All the xml configuration file available on the class path

    - #### getAgentsWithMain

          public static Set<String> getAgentsWithMain()

      Returns:
        all the agent classes having a `main` method.

    - #### findJavaExecutable

          public static String findJavaExecutable(String executable)

      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

          public static void main(String[] args)
                           throws FileNotFoundException,
                                  IOException

      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

          public String toString()

      Overrides:
        `toString` in class `Object`

Fabien Michel, Olivier Gutknecht, Jacques Ferber - February 12 2016