Search in sources :

Example 1 with BeanClassRefreshCommand

use of org.hotswap.agent.plugin.weld.command.BeanClassRefreshCommand in project HotswapAgent by HotswapProjects.

the class WeldPlugin method classReload.

/**
 * If bda archive is defined for given class than new BeanClassRefreshCommand is created
 *
 * @param classLoader
 * @param ctClass
 * @param original
 */
@OnClassLoadEvent(classNameRegexp = ".*", events = LoadEvent.REDEFINE)
public void classReload(ClassLoader classLoader, CtClass ctClass, Class<?> original) {
    if (original != null && !isSyntheticCdiClass(ctClass.getName()) && !isInnerNonPublicStaticClass(ctClass)) {
        try {
            String archivePath = getArchivePath(classLoader, ctClass, original.getName());
            LOGGER.debug("Class '{}' redefined for archive {} ", original.getName(), archivePath);
            if (isBdaRegistered(classLoader, archivePath)) {
                String oldSignatureForProxyCheck = WeldClassSignatureHelper.getSignatureForProxyClass(original);
                String oldSignatureByStrategy = WeldClassSignatureHelper.getSignatureByStrategy(beanReloadStrategy, original);
                scheduler.scheduleCommand(new BeanClassRefreshCommand(classLoader, archivePath, registeredProxiedBeans, original.getName(), oldSignatureForProxyCheck, oldSignatureByStrategy, beanReloadStrategy), WAIT_ON_REDEFINE);
            }
        } catch (Exception e) {
            LOGGER.error("classReload() exception {}.", e, e.getMessage());
        }
    }
}
Also used : BeanClassRefreshCommand(org.hotswap.agent.plugin.weld.command.BeanClassRefreshCommand) URISyntaxException(java.net.URISyntaxException) NotFoundException(org.hotswap.agent.javassist.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 2 with BeanClassRefreshCommand

use of org.hotswap.agent.plugin.weld.command.BeanClassRefreshCommand in project HotswapAgent by HotswapProjects.

the class WeldPlugin method registerBeanDeplArchivePath.

/**
 * Register BeanDeploymentArchive's normalizedArchivePath to watcher. In case of new class, the class file is not known
 * to JVM hence no hotswap is called and therefore it must be handled by watcher.
 *
 * @param archivePath the archive path
 */
public synchronized void registerBeanDeplArchivePath(final String archivePath) {
    URL resource = null;
    try {
        resource = resourceNameToURL(archivePath);
        URI uri = resource.toURI();
        if (!IOUtils.isDirectoryURL(uri.toURL())) {
            LOGGER.trace("Unable to watch for new files. Archive '{}' is not directory.", archivePath);
            return;
        } else {
            LOGGER.info("Registering archive path '{}'", archivePath);
            watcher.addEventListener(appClassLoader, uri, new WatchEventListener() {

                @Override
                public void onEvent(WatchFileEvent event) {
                    if (event.isFile() && event.getURI().toString().endsWith(".class")) {
                        // check that the class is not loaded by the classloader yet (avoid duplicate reload)
                        String className;
                        try {
                            className = IOUtils.urlToClassName(event.getURI());
                        } catch (IOException e) {
                            LOGGER.trace("Watch event on resource '{}' skipped, probably Ok because of delete/create event sequence (compilation not finished yet).", e, event.getURI());
                            return;
                        }
                        if (!ClassLoaderHelper.isClassLoaded(appClassLoader, className) || isTestEnvironment) {
                            // refresh weld only for new classes
                            LOGGER.trace("Register reload command: {} ", className);
                            if (isBdaRegistered(appClassLoader, archivePath)) {
                                // TODO : Create proxy factory
                                scheduler.scheduleCommand(new BeanClassRefreshCommand(appClassLoader, archivePath, event), WAIT_ON_CREATE);
                            }
                        }
                    }
                }
            });
        }
        LOGGER.info("Registered  watch for path '{}' for changes.", resource);
    } catch (URISyntaxException e) {
        LOGGER.error("Unable to watch path '{}' for changes.", e, archivePath);
    } catch (Exception e) {
        LOGGER.warning("registerBeanDeplArchivePath() exception : {}", e.getMessage());
    }
}
Also used : WatchFileEvent(org.hotswap.agent.watch.WatchFileEvent) BeanClassRefreshCommand(org.hotswap.agent.plugin.weld.command.BeanClassRefreshCommand) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WatchEventListener(org.hotswap.agent.watch.WatchEventListener) URI(java.net.URI) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) NotFoundException(org.hotswap.agent.javassist.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 NotFoundException (org.hotswap.agent.javassist.NotFoundException)2 BeanClassRefreshCommand (org.hotswap.agent.plugin.weld.command.BeanClassRefreshCommand)2 URI (java.net.URI)1 URL (java.net.URL)1 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)1 WatchEventListener (org.hotswap.agent.watch.WatchEventListener)1 WatchFileEvent (org.hotswap.agent.watch.WatchFileEvent)1