Search in sources :

Example 1 with OnClassFileEvent

use of org.hotswap.agent.annotation.OnClassFileEvent in project HotswapAgent by HotswapProjects.

the class HotswapperPlugin method watchReload.

/**
 * For each changed class create a reload command.
 */
@OnClassFileEvent(classNameRegexp = ".*", events = { FileEvent.MODIFY, FileEvent.CREATE })
public void watchReload(CtClass ctClass, ClassLoader appClassLoader, URL url) throws IOException, CannotCompileException {
    if (!ClassLoaderHelper.isClassLoaded(appClassLoader, ctClass.getName())) {
        LOGGER.trace("Class {} not loaded yet, no need for autoHotswap, skipped URL {}", ctClass.getName(), url);
        return;
    }
    LOGGER.debug("Class {} will be reloaded from URL {}", ctClass.getName(), url);
    // search for a class to reload
    Class clazz;
    try {
        clazz = appClassLoader.loadClass(ctClass.getName());
    } catch (ClassNotFoundException e) {
        LOGGER.warning("Hotswapper tries to reload class {}, which is not known to application classLoader {}.", ctClass.getName(), appClassLoader);
        return;
    }
    synchronized (reloadMap) {
        reloadMap.put(clazz, ctClass.toBytecode());
    }
    scheduler.scheduleCommand(hotswapCommand, 100, Scheduler.DuplicateSheduleBehaviour.SKIP);
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) OnClassFileEvent(org.hotswap.agent.annotation.OnClassFileEvent)

Aggregations

OnClassFileEvent (org.hotswap.agent.annotation.OnClassFileEvent)1 CtClass (org.hotswap.agent.javassist.CtClass)1