use of org.apache.karaf.instance.core.Instance in project karaf by apache.
the class InstancesMBeanImpl method startInstance.
public void startInstance(String name, String opts, boolean wait, boolean debug) throws MBeanException {
try {
Instance child = getExistingInstance(name);
String options = opts;
if (options == null) {
options = child.getJavaOpts();
}
if (options == null) {
options = DEFAULT_OPTS;
}
if (debug) {
options += DEBUG_OPTS;
}
if (wait) {
String state = child.getState();
if (Instance.STOPPED.equals(state)) {
child.start(opts);
}
if (!Instance.STARTED.equals(state)) {
do {
Thread.sleep(500);
state = child.getState();
} while (Instance.STARTING.equals(state));
}
} else {
child.start(opts);
}
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of org.apache.karaf.instance.core.Instance in project karaf by apache.
the class InstancesMBeanImpl method getInstances.
public TabularData getInstances() throws MBeanException {
List<Instance> instances = Arrays.asList(instanceService.getInstances());
TabularData table = InstanceToTableMapper.tableFrom(instances);
return table;
}
use of org.apache.karaf.instance.core.Instance in project karaf by apache.
the class InstanceServiceMBeanImplTest method testStartInstanceWithJavaOpts.
public void testStartInstanceWithJavaOpts() throws Exception {
Instance inst = EasyMock.createMock(Instance.class);
inst.start("-x -y -z");
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", "-x -y -z");
EasyMock.verify(instanceService);
EasyMock.verify(inst);
}
use of org.apache.karaf.instance.core.Instance in project karaf by apache.
the class InstanceServiceMBeanImplTest method testDestroyInstance.
public void testDestroyInstance() throws Exception {
Instance inst = EasyMock.createMock(Instance.class);
inst.destroy();
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.destroyInstance("test instance");
EasyMock.verify(instanceService);
EasyMock.verify(inst);
}
use of org.apache.karaf.instance.core.Instance in project karaf by apache.
the class InstanceCommandSupport method getMatchingInstances.
protected List<Instance> getMatchingInstances(List<String> patterns) {
List<Instance> instances = new ArrayList<>();
Instance[] allInstances = instanceService.getInstances();
for (Instance instance : allInstances) {
if (match(instance.getName(), patterns)) {
instances.add(instance);
}
}
if (instances.isEmpty()) {
throw new IllegalArgumentException("No matching instances");
}
return instances;
}
Aggregations