Search in sources :

Example 11 with Command

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

the class BeanClassRefreshCommand method isCreateEvent.

/**
 * Check all merged events with same className for create events.
 * @param mergedCommands
 */
private boolean isCreateEvent(List<Command> mergedCommands) {
    boolean createFound = false;
    for (Command cmd : mergedCommands) {
        BeanClassRefreshCommand refreshCommand = (BeanClassRefreshCommand) cmd;
        if (className.equals(refreshCommand.className)) {
            if (refreshCommand.event != null) {
                if (refreshCommand.event.getEventType().equals(FileEvent.CREATE))
                    createFound = true;
            }
        }
    }
    LOGGER.trace("isCreateEvent result {}: createFound={}", createFound);
    return createFound;
}
Also used : Command(org.hotswap.agent.command.Command) MergeableCommand(org.hotswap.agent.command.MergeableCommand)

Example 12 with Command

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

the class BeanClassRefreshCommand method isDeleteEvent.

/**
 * Check all merged events with same className for delete and create events. If delete without create is found, than assume
 * file was deleted.
 * @param mergedCommands
 */
private boolean isDeleteEvent(List<Command> mergedCommands) {
    boolean createFound = false;
    boolean deleteFound = false;
    for (Command cmd : mergedCommands) {
        BeanClassRefreshCommand refreshCommand = (BeanClassRefreshCommand) cmd;
        if (className.equals(refreshCommand.className)) {
            if (refreshCommand.event != null) {
                if (refreshCommand.event.getEventType().equals(FileEvent.DELETE))
                    deleteFound = true;
                if (refreshCommand.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)

Example 13 with Command

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

the class SchedulerImpl method processCommands.

/**
 * One cycle of the scheduler agent. Process all commands which are not currently
 * running and time lower than current milliseconds.
 *
 * @return true if the agent should continue (false for fatal error)
 */
private boolean processCommands() {
    Long currentTime = System.currentTimeMillis();
    synchronized (scheduledCommands) {
        for (Iterator<Map.Entry<Command, DuplicateScheduleConfig>> it = scheduledCommands.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<Command, DuplicateScheduleConfig> entry = it.next();
            DuplicateScheduleConfig config = entry.getValue();
            Command command = entry.getKey();
            // if timeout
            if (config.getTime() < currentTime) {
                // command is currently running
                if (runningCommands.contains(command)) {
                    if (config.getBehaviour().equals(DuplicateSheduleBehaviour.SKIP)) {
                        LOGGER.debug("Skipping duplicate running command {}", command);
                        it.remove();
                    } else if (config.getBehaviour().equals(DuplicateSheduleBehaviour.RUN_DUPLICATE)) {
                        executeCommand(command);
                        it.remove();
                    }
                } else {
                    executeCommand(command);
                    it.remove();
                }
            }
        }
    }
    return true;
}
Also used : WatchEventCommand(org.hotswap.agent.annotation.handler.WatchEventCommand) Command(org.hotswap.agent.command.Command) MergeableCommand(org.hotswap.agent.command.MergeableCommand) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

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