Search in sources :

Example 1 with Command

use of org.hotswap.agent.command.Command in project HotswapAgent by HotswapProjects.

the class BeanClassRefreshCommand method executeCommand.

@Override
public void executeCommand() {
    List<Command> mergedCommands = popMergedCommands();
    mergedCommands.add(0, this);
    do {
        // First step : recreate all proxies
        for (Command command : mergedCommands) {
            ((BeanClassRefreshCommand) command).recreateProxy(mergedCommands);
        }
        // Second step : reload beans
        for (Command command : mergedCommands) {
            ((BeanClassRefreshCommand) command).reloadBean(mergedCommands);
        }
        mergedCommands = popMergedCommands();
    } while (!mergedCommands.isEmpty());
}
Also used : Command(org.hotswap.agent.command.Command) MergeableCommand(org.hotswap.agent.command.MergeableCommand)

Example 2 with Command

use of org.hotswap.agent.command.Command in project HotswapAgent by HotswapProjects.

the class ClassPathBeanRefreshCommand method isDeleteEvent.

/**
 * Check all merged events for delete and create events. If delete without create is found, than assume
 * file was deleted.
 */
private boolean isDeleteEvent() {
    // for all merged commands including this command
    List<ClassPathBeanRefreshCommand> mergedCommands = new ArrayList<ClassPathBeanRefreshCommand>();
    for (Command command : getMergedCommands()) {
        mergedCommands.add((ClassPathBeanRefreshCommand) command);
    }
    mergedCommands.add(this);
    boolean createFound = false;
    boolean deleteFound = false;
    for (ClassPathBeanRefreshCommand command : mergedCommands) {
        if (command.event != null) {
            if (command.event.getEventType().equals(FileEvent.DELETE))
                deleteFound = true;
            if (command.event.getEventType().equals(FileEvent.CREATE))
                createFound = true;
        }
    }
    LOGGER.trace("isDeleteEvent result {}: createFound={}, deleteFound={}", createFound, deleteFound);
    return !createFound && deleteFound;
}
Also used : Command(org.hotswap.agent.command.Command) MergeableCommand(org.hotswap.agent.command.MergeableCommand) ArrayList(java.util.ArrayList)

Example 3 with Command

use of org.hotswap.agent.command.Command in project HotswapAgent by HotswapProjects.

the class BeanClassRefreshCommand method executeCommand.

@Override
public void executeCommand() {
    List<Command> mergedCommands = popMergedCommands();
    mergedCommands.add(0, this);
    do {
        // First step : recreate all proxies
        for (Command command : mergedCommands) {
            ((BeanClassRefreshCommand) command).recreateProxy(mergedCommands);
        }
        // Second step : reload beans
        for (Command command : mergedCommands) {
            ((BeanClassRefreshCommand) command).reloadBean(mergedCommands);
        }
        mergedCommands = popMergedCommands();
    } while (!mergedCommands.isEmpty());
}
Also used : Command(org.hotswap.agent.command.Command) MergeableCommand(org.hotswap.agent.command.MergeableCommand)

Example 4 with Command

use of org.hotswap.agent.command.Command in project HotswapAgent by HotswapProjects.

the class OsgiEquinoxPlugin method initOsgiEquinox.

public void initOsgiEquinox() {
    if (hotswapCommand != null)
        return;
    LOGGER.debug("Init OsgiEquinoxPlugin.");
    extraClasspath = pluginConfiguration.getProperty("extraClasspath");
    if (extraClasspath != null) {
        String debugMode = pluginConfiguration.getProperty("osgiEquinox.debugMode");
        isDebugMode = "true".equals(debugMode);
        if (!isDebugMode) {
            URL resource = null;
            try {
                resource = resourceNameToURL(extraClasspath.trim());
                URI uri = resource.toURI();
                LOGGER.info("Initialize hotswap on URL {}.", uri);
                listener = new AutoHotswapPathEventListener(this);
                watcher.addEventListener(null, uri, listener);
            } catch (URISyntaxException e) {
                LOGGER.error("Unable to watch path '{}' for changes.", e, resource);
            } catch (Exception e) {
                LOGGER.warning("initOsgiEquinox() exception : {}", e.getMessage());
            }
            if (resource != null) {
                hotswapCommand = new Command() {

                    @Override
                    public void executeCommand() {
                        pluginManager.hotswap(reloadMap);
                    }

                    @Override
                    public String toString() {
                        return "pluginManager.hotswap(" + Arrays.toString(reloadMap.keySet().toArray()) + ")";
                    }
                };
            }
        }
    }
}
Also used : Command(org.hotswap.agent.command.Command) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) CannotCompileException(org.hotswap.agent.javassist.CannotCompileException)

Example 5 with Command

use of org.hotswap.agent.command.Command in project HotswapAgent by HotswapProjects.

the class SchedulerImpl method scheduleCommand.

@Override
public void scheduleCommand(Command command, int timeout, DuplicateSheduleBehaviour behaviour) {
    synchronized (scheduledCommands) {
        Command targetCommand = command;
        if (scheduledCommands.containsKey(command) && (command instanceof MergeableCommand)) {
            // get existing equals command and merge it
            for (Command scheduledCommand : scheduledCommands.keySet()) {
                if (command.equals(scheduledCommand)) {
                    targetCommand = ((MergeableCommand) command).merge(scheduledCommand);
                    break;
                }
            }
        }
        // map may already contain equals command, put will replace it and reset timer
        scheduledCommands.put(targetCommand, new DuplicateScheduleConfig(System.currentTimeMillis() + timeout, behaviour));
        LOGGER.trace("{} scheduled for execution in {}ms", targetCommand, timeout);
    }
}
Also used : MergeableCommand(org.hotswap.agent.command.MergeableCommand) WatchEventCommand(org.hotswap.agent.annotation.handler.WatchEventCommand) Command(org.hotswap.agent.command.Command) MergeableCommand(org.hotswap.agent.command.MergeableCommand)

Aggregations

Command (org.hotswap.agent.command.Command)13 MergeableCommand (org.hotswap.agent.command.MergeableCommand)9 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)4 NotFoundException (org.hotswap.agent.javassist.NotFoundException)3 ArrayList (java.util.ArrayList)2 WatchEventCommand (org.hotswap.agent.annotation.handler.WatchEventCommand)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)1 CtClass (org.hotswap.agent.javassist.CtClass)1 CtConstructor (org.hotswap.agent.javassist.CtConstructor)1 CtField (org.hotswap.agent.javassist.CtField)1 CtMethod (org.hotswap.agent.javassist.CtMethod)1