Search in sources :

Example 1 with ConfigurableComponent

use of org.eclipse.kura.configuration.ConfigurableComponent in project kura by eclipse.

the class ConfigurableComponentTracker method open.

// ----------------------------------------------------------------
// 
// Override APIs
// 
// ----------------------------------------------------------------
@SuppressWarnings({ "unchecked" })
@Override
public void open(boolean trackAllServices) {
    s_logger.info("Opening ServiceTracker");
    super.open(trackAllServices);
    try {
        s_logger.info("Getting ServiceReferences");
        ServiceReference[] refs = this.context.getServiceReferences((String) null, null);
        if (refs != null) {
            for (ServiceReference ref : refs) {
                String servicePid = (String) ref.getProperty(Constants.SERVICE_PID);
                String pid = (String) ref.getProperty(ConfigurationService.KURA_SERVICE_PID);
                String factoryPid = (String) ref.getProperty(ConfigurationAdmin.SERVICE_FACTORYPID);
                if (servicePid != null) {
                    Object obj = this.context.getService(ref);
                    try {
                        if (obj == null) {
                            s_logger.info("Could not find service for: {}", ref);
                        } else if (obj instanceof ConfigurableComponent) {
                            s_logger.info("Adding ConfigurableComponent with pid {}, service pid {} and factory pid " + factoryPid, pid, servicePid);
                            this.m_confService.registerComponentConfiguration(pid, servicePid, factoryPid);
                        } else if (obj instanceof SelfConfiguringComponent) {
                            s_logger.info("Adding SelfConfiguringComponent with pid {} and service pid {}", pid, servicePid);
                            this.m_confService.registerSelfConfiguringComponent(servicePid);
                        }
                    } finally {
                        this.context.ungetService(ref);
                    }
                }
            }
        }
    } catch (InvalidSyntaxException ise) {
        s_logger.error("Error in addingBundle", ise);
    }
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ConfigurableComponent(org.eclipse.kura.configuration.ConfigurableComponent) ServiceReference(org.osgi.framework.ServiceReference) SelfConfiguringComponent(org.eclipse.kura.configuration.SelfConfiguringComponent)

Aggregations

ConfigurableComponent (org.eclipse.kura.configuration.ConfigurableComponent)1 SelfConfiguringComponent (org.eclipse.kura.configuration.SelfConfiguringComponent)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1