Search in sources :

Example 1 with MultiException

use of org.apache.karaf.shell.support.MultiException in project karaf by apache.

the class DestroyCommand method doExecute.

@SuppressWarnings("deprecation")
protected Object doExecute() throws Exception {
    final MultiException exception = new MultiException("Error destroying instance(s)");
    for (Instance instance : getMatchingInstances(instances)) {
        try {
            instance.destroy();
        } catch (Exception e) {
            exception.addException(e);
        }
    }
    exception.throwIfExceptions();
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) MultiException(org.apache.karaf.shell.support.MultiException) MultiException(org.apache.karaf.shell.support.MultiException)

Example 2 with MultiException

use of org.apache.karaf.shell.support.MultiException in project karaf by apache.

the class RestartCommand method doExecute.

@SuppressWarnings("deprecation")
protected Object doExecute() throws Exception {
    MultiException exception = new MultiException("Error starting instance(s)");
    List<Instance> toWaitFor = new ArrayList<>();
    for (Instance instance : getMatchingInstances(instances)) {
        try {
            String opts = javaOpts;
            if (opts == null) {
                opts = instance.getJavaOpts();
            }
            if (opts == null) {
                opts = DEFAULT_OPTS;
            }
            if (debug) {
                opts += DEBUG_OPTS;
            }
            instance.restart(opts);
        } catch (Exception e) {
            exception.addException(e);
        }
    }
    exception.throwIfExceptions();
    while (true) {
        boolean allStarted = true;
        for (Instance child : toWaitFor) {
            allStarted &= Instance.STARTED.equals(child.getState());
        }
        if (allStarted) {
            break;
        } else {
            Thread.sleep(500);
        }
    }
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) ArrayList(java.util.ArrayList) MultiException(org.apache.karaf.shell.support.MultiException) MultiException(org.apache.karaf.shell.support.MultiException)

Example 3 with MultiException

use of org.apache.karaf.shell.support.MultiException in project karaf by apache.

the class StartCommand method doExecute.

@SuppressWarnings("deprecation")
protected Object doExecute() throws Exception {
    MultiException exception = new MultiException("Error starting instance(s)");
    List<Instance> toWaitFor = new ArrayList<>();
    for (Instance instance : getMatchingInstances(instances)) {
        try {
            String opts = javaOpts;
            if (opts == null) {
                opts = instance.getJavaOpts();
            }
            if (opts == null) {
                opts = DEFAULT_OPTS;
            }
            if (debug) {
                opts += DEBUG_OPTS;
            }
            if (wait) {
                String state = instance.getState();
                if (Instance.STOPPED.equals(state)) {
                    instance.start(opts);
                    toWaitFor.add(instance);
                }
            } else {
                instance.start(opts);
            }
        } catch (Exception e) {
            exception.addException(e);
        }
    }
    exception.throwIfExceptions();
    while (true) {
        boolean allStarted = true;
        for (Instance child : toWaitFor) {
            allStarted &= Instance.STARTED.equals(child.getState());
        }
        if (allStarted) {
            break;
        } else {
            Thread.sleep(500);
        }
    }
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) ArrayList(java.util.ArrayList) MultiException(org.apache.karaf.shell.support.MultiException) MultiException(org.apache.karaf.shell.support.MultiException)

Example 4 with MultiException

use of org.apache.karaf.shell.support.MultiException in project karaf by apache.

the class StopCommand method doExecute.

@SuppressWarnings("deprecation")
protected Object doExecute() throws Exception {
    final MultiException exception = new MultiException("Error stopping instance(s)");
    for (Instance instance : getMatchingInstances(instances)) {
        try {
            instance.stop();
        } catch (Exception e) {
            exception.addException(e);
        }
    }
    exception.throwIfExceptions();
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) MultiException(org.apache.karaf.shell.support.MultiException) MultiException(org.apache.karaf.shell.support.MultiException)

Aggregations

Instance (org.apache.karaf.instance.core.Instance)4 MultiException (org.apache.karaf.shell.support.MultiException)4 ArrayList (java.util.ArrayList)2