Search in sources :

Example 21 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class StatusCommand method doExecute.

protected Object doExecute() throws Exception {
    Instance instance = getExistingInstance(name);
    System.out.println(instance.getState());
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance)

Example 22 with Instance

use of org.apache.karaf.instance.core.Instance 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)

Example 23 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstancePlugin method getStatusLine.

private String getStatusLine() {
    final Instance[] instances = instanceService.getInstances();
    int started = 0, starting = 0, stopped = 0;
    for (Instance instance : instances) {
        try {
            if (instance.getState().equals(Instance.STARTED)) {
                started++;
            } else if (instance.getState().equals(Instance.STARTING)) {
                starting++;
            } else if (instance.getState().equals(Instance.STOPPED)) {
                stopped++;
            }
        } catch (Exception ex) {
            Logger.getLogger(InstancePlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    final StringBuffer buffer = new StringBuffer();
    buffer.append("Instance information: ");
    buffer.append(instances.length);
    buffer.append(" instance");
    if (instances.length != 1) {
        buffer.append('s');
    }
    buffer.append(" in total");
    if (started == instances.length) {
        buffer.append(" - all started");
    } else {
        if (started != 0) {
            buffer.append(", ");
            buffer.append(started);
            buffer.append(" started");
        }
        if (starting != 0) {
            buffer.append(", ");
            buffer.append(starting);
            buffer.append(" starting");
        }
        buffer.append('.');
    }
    return buffer.toString();
}
Also used : Instance(org.apache.karaf.instance.core.Instance) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 24 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceMBeanImplTest method testChangeOptions.

public void testChangeOptions() throws Exception {
    Instance inst = EasyMock.createMock(Instance.class);
    inst.changeJavaOpts("new opts");
    EasyMock.expectLastCall();
    EasyMock.replay(inst);
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
    EasyMock.replay(instanceService);
    InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
    instanceServiceMBean.changeJavaOpts("test instance", "new opts");
    EasyMock.verify(instanceService);
    EasyMock.verify(inst);
}
Also used : Instance(org.apache.karaf.instance.core.Instance) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl) InstancesMBean(org.apache.karaf.instance.core.InstancesMBean) InstanceService(org.apache.karaf.instance.core.InstanceService)

Example 25 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceMBeanImplTest method testStartInstanceWithNoJavaOpts.

public void testStartInstanceWithNoJavaOpts() throws Exception {
    Instance inst = EasyMock.createMock(Instance.class);
    inst.start(null);
    EasyMock.expectLastCall();
    EasyMock.replay(inst);
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
    EasyMock.replay(instanceService);
    InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
    instanceServiceMBean.startInstance("test instance", null);
    EasyMock.verify(instanceService);
    EasyMock.verify(inst);
}
Also used : Instance(org.apache.karaf.instance.core.Instance) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl) InstancesMBean(org.apache.karaf.instance.core.InstancesMBean) InstanceService(org.apache.karaf.instance.core.InstanceService)

Aggregations

Instance (org.apache.karaf.instance.core.Instance)28 InstanceService (org.apache.karaf.instance.core.InstanceService)11 InstancesMBeanImpl (org.apache.karaf.instance.core.internal.InstancesMBeanImpl)10 InstancesMBean (org.apache.karaf.instance.core.InstancesMBean)8 InstanceSettings (org.apache.karaf.instance.core.InstanceSettings)5 TabularData (javax.management.openmbean.TabularData)4 MultiException (org.apache.karaf.shell.support.MultiException)4 ArrayList (java.util.ArrayList)3 CompositeData (javax.management.openmbean.CompositeData)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 MBeanException (javax.management.MBeanException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 ServletException (javax.servlet.ServletException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1