Search in sources :

Example 1 with CommandExecutionFlag

use of org.apache.sling.ide.transport.Repository.CommandExecutionFlag in project sling by apache.

the class TracingCommand method execute.

@Override
public Result<T> execute() {
    long start = System.currentTimeMillis();
    Result<T> result = command.execute();
    long end = System.currentTimeMillis();
    if (eventAdmin != null) {
        Map<String, Object> props = new HashMap<>();
        props.put(CommandExecutionProperties.RESULT_TEXT, result.toString());
        props.put(CommandExecutionProperties.RESULT_STATUS, result.isSuccess());
        try {
            result.get();
        } catch (RepositoryException e) {
            props.put(CommandExecutionProperties.RESULT_THROWABLE, e);
        }
        props.put(CommandExecutionProperties.ACTION_TYPE, command.getClass().getSimpleName());
        Set<CommandExecutionFlag> flags = command.getFlags();
        if (!flags.isEmpty()) {
            StringBuilder flagsString = new StringBuilder();
            for (CommandExecutionFlag flag : flags) {
                flagsString.append(flag).append(',');
            }
            flagsString.deleteCharAt(flagsString.length() - 1);
            props.put(CommandExecutionProperties.ACTION_FLAGS, flagsString.toString());
        }
        props.put(CommandExecutionProperties.ACTION_TARGET, command.getPath());
        props.put(CommandExecutionProperties.TIMESTAMP_START, start);
        props.put(CommandExecutionProperties.TIMESTAMP_END, end);
        Event event = new Event(CommandExecutionProperties.REPOSITORY_TOPIC, props);
        eventAdmin.postEvent(event);
    }
    return result;
}
Also used : CommandExecutionFlag(org.apache.sling.ide.transport.Repository.CommandExecutionFlag) HashMap(java.util.HashMap) Event(org.osgi.service.event.Event)

Aggregations

HashMap (java.util.HashMap)1 CommandExecutionFlag (org.apache.sling.ide.transport.Repository.CommandExecutionFlag)1 Event (org.osgi.service.event.Event)1