Search in sources :

Example 1 with Registry

use of org.apache.karaf.shell.api.console.Registry in project karaf by apache.

the class CommandExtension method updateState.

@SuppressWarnings("unchecked")
private synchronized void updateState(AggregateServiceTracker.State state) {
    boolean wasSatisfied = manager != null;
    boolean isSatisfied = state != null && state.isSatisfied();
    String action;
    if (wasSatisfied && isSatisfied) {
        action = "Updating";
    } else if (wasSatisfied) {
        action = "Unregistering";
    } else if (isSatisfied) {
        action = "Registering";
    } else {
        return;
    }
    LOGGER.info("{} commands for bundle {}/{}", action, bundle.getSymbolicName(), bundle.getVersion());
    if (wasSatisfied) {
        for (Class clazz : classes) {
            manager.unregister(clazz);
        }
        manager = null;
    }
    if (isSatisfied) {
        Registry reg = new RegistryImpl(registry);
        manager = new ManagerImpl(reg, registry);
        reg.register(bundle.getBundleContext());
        reg.register(manager);
        for (Map.Entry<Class, Object> entry : state.getSingleServices().entrySet()) {
            reg.register(entry.getValue());
        }
        for (final Map.Entry<Class, List> entry : state.getMultiServices().entrySet()) {
            reg.register((Callable) entry::getValue, entry.getKey());
        }
        for (Class clazz : classes) {
            manager.register(clazz);
        }
    }
}
Also used : ManagerImpl(org.apache.karaf.shell.impl.action.command.ManagerImpl) ArrayList(java.util.ArrayList) List(java.util.List) Registry(org.apache.karaf.shell.api.console.Registry) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Registry (org.apache.karaf.shell.api.console.Registry)1 ManagerImpl (org.apache.karaf.shell.impl.action.command.ManagerImpl)1