in core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommandHandler.java [50:97]
public ManageHandlersResult execute(ManageHandlersCommand command) {
ManageHandlersResult result = new ManageHandlersResult(command.getId());
BundleContext bundleContext = ((BundleReference) getClass().getClassLoader()).getBundle().getBundleContext();
ServiceReference[] references = new ServiceReference[0];
try {
references = bundleContext.getServiceReferences(EventHandler.class.getName(), EventHandler.MANAGED_FILTER);
if (references != null && references.length > 0) {
for (ServiceReference ref : references) {
EventHandler handler = (EventHandler) bundleContext.getService(ref);
// unproxy if required (due to the Service Guard of Karaf 3.0.x)
if (proxyManager.isProxy(handler)) {
handler = (EventHandler) proxyManager.unwrap(handler).call();
}
if (command.getHandlerName() == null) {
result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name());
} else {
if (command.getHandlerName().equals(handler.getClass().getName())) {
if (command.getStatus() != null) {
if (command.getStatus()) {
// persist the handler switch status to configuration admin
persist(handler.getClass().getName(), SwitchStatus.ON);
handler.getSwitch().turnOn();
} else {
// persist the handler switch status to configuration admin
persist(handler.getClass().getName(), SwitchStatus.OFF);
handler.getSwitch().turnOff();
}
}
result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name());
break;
}
}
}
}
} catch (Exception e) {
LOGGER.error("Can't get the current handlers status", e);
} finally {
if (references != null) {
for (ServiceReference ref : references) {
bundleContext.ungetService(ref);
}
}
}
return result;
}