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;fp=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FBeanToOsgiServiceManager.java;h=9031f23462b520fe7fc8f92e8a8be174a5b06a0c;hb=2b78ca93f44c372fd72927db6cbd65f5d8387b49;hp=ff504dafdcac22176d798569836bfe6e5ce460c7;hpb=c0e813ca83ce80d5f3fb340175ddaecd780c6aea;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 ff504dafdc..9031f23462 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -30,13 +30,19 @@ public class BeanToOsgiServiceManager { private static final String SERVICE_NAME_OSGI_PROP = "name"; /** - * To be called for every created, reconfigured and recreated config bean. - * It is expected that before using this method OSGi service registry will - * be cleaned from previous registrations. + * To be called for every created, reconfigured and recreated config bean. It is + * expected that before using this method OSGi service registry will be cleaned + * from previous registrations. + * + * @param instance instance + * @param moduleIdentifier module identifier + * @param bundleContext bundle context + * @param serviceNamesToAnnotations service names annotations + * @return OSGI registration */ public OsgiRegistration registerToOsgi(final AutoCloseable instance, final ModuleIdentifier moduleIdentifier, - final BundleContext bundleContext, - final Map serviceNamesToAnnotations) { + final BundleContext bundleContext, + final Map serviceNamesToAnnotations) { return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations); } @@ -49,34 +55,36 @@ public class BeanToOsgiServiceManager { @GuardedBy("this") private final Set> serviceRegistrations; @GuardedBy("this") - private final Map serviceNamesToAnnotations; + private final Map serviceNamesToAnnotations; public OsgiRegistration(final AutoCloseable instance, final ModuleIdentifier moduleIdentifier, - final BundleContext bundleContext, - final Map serviceNamesToAnnotations) { + 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(final AutoCloseable instance, final BundleContext bundleContext, - final Map serviceNamesToAnnotations) { + private static Set> registerToSR(final AutoCloseable instance, + final BundleContext bundleContext, + final Map serviceNamesToAnnotations) { Set> serviceRegistrations = new HashSet<>(); - for (Entry entry : serviceNamesToAnnotations.entrySet()) { + for (Entry entry : serviceNamesToAnnotations + .entrySet()) { ServiceInterfaceAnnotation annotation = entry.getKey(); Class requiredInterface = annotation.osgiRegistrationType(); - if(!annotation.registerToOsgi()) { + 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()); + Preconditions.checkState(requiredInterface.isInstance(instance), + instance.getClass().getName() + " instance should implement " + requiredInterface.getName()); Dictionary propertiesForOsgi = createProps(entry.getValue()); - ServiceRegistration serviceRegistration = bundleContext - .registerService(requiredInterface.getName(), instance, propertiesForOsgi); + ServiceRegistration serviceRegistration = bundleContext.registerService(requiredInterface.getName(), + instance, propertiesForOsgi); serviceRegistrations.add(serviceRegistration); } return serviceRegistrations; @@ -87,19 +95,21 @@ public class BeanToOsgiServiceManager { for (ServiceRegistration serviceRegistration : serviceRegistrations) { try { serviceRegistration.unregister(); - } catch(final IllegalStateException e) { + } catch (final IllegalStateException e) { LOG.trace("Cannot unregister {}", serviceRegistration, e); } } serviceRegistrations.clear(); } - public synchronized void updateRegistrations(final Map newAnnotationMapping, - final BundleContext bundleContext, final AutoCloseable newInstance) { + 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 + // FIXME: changing from old state to new state can be improved by computing the + // diff LOG.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier, serviceNamesToAnnotations, newAnnotationMapping); close();