X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FBeanToOsgiServiceManager.java;h=ff504dafdcac22176d798569836bfe6e5ce460c7;hb=cbcc2b61265e903959f11d44c292771e76b3926e;hp=c03bfa450034254360dca663f18abf54d607f83e;hpb=0a16f37f1baa4a2616e9b7289a445649b4f3132d;p=controller.git
diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java
index c03bfa4500..ff504dafdc 100644
--- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java
+++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java
@@ -7,8 +7,7 @@
*/
package org.opendaylight.controller.config.manager.impl.osgi;
-import static com.google.common.base.Preconditions.checkState;
-
+import com.google.common.base.Preconditions;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Hashtable;
@@ -35,21 +34,14 @@ public class BeanToOsgiServiceManager {
* It is expected that before using this method OSGi service registry will
* be cleaned from previous registrations.
*/
- public OsgiRegistration registerToOsgi(AutoCloseable instance, ModuleIdentifier moduleIdentifier,
- BundleContext bundleContext,
- Map serviceNamesToAnnotations) {
+ public OsgiRegistration registerToOsgi(final AutoCloseable instance, final ModuleIdentifier moduleIdentifier,
+ final BundleContext bundleContext,
+ final Map serviceNamesToAnnotations) {
return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations);
}
- private static Dictionary createProps(String serviceName) {
- Hashtable result = new Hashtable<>();
- result.put(SERVICE_NAME_OSGI_PROP, serviceName);
- return result;
- }
-
-
public static class OsgiRegistration implements AutoCloseable {
- private static final Logger LOGGER = LoggerFactory.getLogger(OsgiRegistration.class);
+ private static final Logger LOG = LoggerFactory.getLogger(OsgiRegistration.class);
@GuardedBy("this")
private AutoCloseable instance;
@@ -59,21 +51,28 @@ public class BeanToOsgiServiceManager {
@GuardedBy("this")
private final Map serviceNamesToAnnotations;
- public OsgiRegistration(AutoCloseable instance, ModuleIdentifier moduleIdentifier,
- BundleContext bundleContext,
- Map serviceNamesToAnnotations) {
+ public OsgiRegistration(final AutoCloseable instance, final ModuleIdentifier moduleIdentifier,
+ final BundleContext bundleContext,
+ final Map serviceNamesToAnnotations) {
this.instance = instance;
this.moduleIdentifier = moduleIdentifier;
this.serviceNamesToAnnotations = serviceNamesToAnnotations;
this.serviceRegistrations = registerToSR(instance, bundleContext, serviceNamesToAnnotations);
}
- private static Set> registerToSR(AutoCloseable instance, BundleContext bundleContext,
- Map serviceNamesToAnnotations) {
+ private static Set> registerToSR(final AutoCloseable instance, final BundleContext bundleContext,
+ final Map serviceNamesToAnnotations) {
Set> serviceRegistrations = new HashSet<>();
for (Entry entry : serviceNamesToAnnotations.entrySet()) {
- Class> requiredInterface = entry.getKey().osgiRegistrationType();
- checkState(requiredInterface.isInstance(instance), instance.getClass().getName() +
+ ServiceInterfaceAnnotation annotation = entry.getKey();
+ Class> requiredInterface = annotation.osgiRegistrationType();
+
+ if(!annotation.registerToOsgi()) {
+ LOG.debug("registerToOsgi for service interface {} is false - not registering", requiredInterface);
+ continue;
+ }
+
+ Preconditions.checkState(requiredInterface.isInstance(instance), instance.getClass().getName() +
" instance should implement " + requiredInterface.getName());
Dictionary propertiesForOsgi = createProps(entry.getValue());
ServiceRegistration> serviceRegistration = bundleContext
@@ -88,20 +87,20 @@ public class BeanToOsgiServiceManager {
for (ServiceRegistration> serviceRegistration : serviceRegistrations) {
try {
serviceRegistration.unregister();
- } catch(IllegalStateException e) {
- LOGGER.trace("Cannot unregister {}", serviceRegistration, e);
+ } catch(final IllegalStateException e) {
+ LOG.trace("Cannot unregister {}", serviceRegistration, e);
}
}
serviceRegistrations.clear();
}
- public synchronized void updateRegistrations(Map newAnnotationMapping,
- BundleContext bundleContext, AutoCloseable newInstance) {
- boolean notEquals = this.instance != newInstance;
- notEquals |= newAnnotationMapping.equals(serviceNamesToAnnotations) == false;
+ public synchronized void updateRegistrations(final Map newAnnotationMapping,
+ final BundleContext bundleContext, final AutoCloseable newInstance) {
+ boolean notEquals = !this.instance.equals(newInstance);
+ notEquals |= !newAnnotationMapping.equals(serviceNamesToAnnotations);
if (notEquals) {
// FIXME: changing from old state to new state can be improved by computing the diff
- LOGGER.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier,
+ LOG.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier,
serviceNamesToAnnotations, newAnnotationMapping);
close();
this.instance = newInstance;
@@ -110,5 +109,11 @@ public class BeanToOsgiServiceManager {
serviceRegistrations.addAll(newRegs);
}
}
+
+ private static Dictionary createProps(final String serviceName) {
+ Hashtable result = new Hashtable<>();
+ result.put(SERVICE_NAME_OSGI_PROP, serviceName);
+ return result;
+ }
}
}