X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2Fmapping%2FRefreshingSCPModuleInfoRegistry.java;h=9871a04f42ca0c243182a2150ad822583328c4e8;hp=6217476fa9f0b3da97c1c39c829c24016233317e;hb=2b78ca93f44c372fd72927db6cbd65f5d8387b49;hpb=db89afdefb3cfa4454dfdc6008e1d54d3ede66fb diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.java index 6217476fa9..9871a04f42 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.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, @@ -20,15 +20,12 @@ import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** - * Update SchemaContext service in Service Registry each time new YangModuleInfo is added or removed. + * Update SchemaContext service in Service Registry each time new YangModuleInfo + * is added or removed. */ public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, AutoCloseable { - private static final Logger LOG = LoggerFactory.getLogger(RefreshingSCPModuleInfoRegistry.class); - private final ModuleInfoRegistry moduleInfoRegistry; private final SchemaContextProvider schemaContextProvider; private final SchemaSourceProvider sourceProvider; @@ -38,45 +35,41 @@ public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, Auto private volatile ServiceRegistration osgiReg; public RefreshingSCPModuleInfoRegistry(final ModuleInfoRegistry moduleInfoRegistry, - final SchemaContextProvider schemaContextProvider, final ClassLoadingStrategy classLoadingStrat, - final SchemaSourceProvider sourceProvider, final BindingContextProvider bindingContextProvider, - final BundleContext bundleContext) { + final SchemaContextProvider schemaContextProvider, final ClassLoadingStrategy classLoadingStrat, + final SchemaSourceProvider sourceProvider, + final BindingContextProvider bindingContextProvider, final BundleContext bundleContext) { this.moduleInfoRegistry = moduleInfoRegistry; this.schemaContextProvider = schemaContextProvider; this.classLoadingStrat = classLoadingStrat; this.sourceProvider = sourceProvider; this.bindingContextProvider = bindingContextProvider; - this.osgiReg = bundleContext - .registerService(SchemaContextProvider.class, schemaContextProvider, new Hashtable()); + this.osgiReg = bundleContext.registerService(SchemaContextProvider.class, schemaContextProvider, + new Hashtable()); } - public void updateService() { - if(this.osgiReg != null) { - try { - this.bindingContextProvider.update(this.classLoadingStrat, this.schemaContextProvider); - - final Dictionary props = new Hashtable<>(); - props.put(BindingRuntimeContext.class.getName(), this.bindingContextProvider.getBindingContext()); - props.put(SchemaSourceProvider.class.getName(), this.sourceProvider); - // send modifiedService event - this.osgiReg.setProperties(props); - } catch (final RuntimeException e) { - // The ModuleInfoBackedContext throws a RuntimeException if it can't create the schema context. - LOG.warn("Error updating the BindingContextProvider", e); - } + public synchronized void updateService() { + if (this.osgiReg != null) { + this.bindingContextProvider.update(this.classLoadingStrat, this.schemaContextProvider); + + final Dictionary props = new Hashtable<>(); + props.put(BindingRuntimeContext.class.getName(), this.bindingContextProvider.getBindingContext()); + props.put(SchemaSourceProvider.class.getName(), this.sourceProvider); + // send modifiedService event + this.osgiReg.setProperties(props); } } @Override public ObjectRegistration registerModuleInfo(final YangModuleInfo yangModuleInfo) { - final ObjectRegistration yangModuleInfoObjectRegistration = this.moduleInfoRegistry.registerModuleInfo(yangModuleInfo); + final ObjectRegistration yangModuleInfoObjectRegistration = this.moduleInfoRegistry + .registerModuleInfo(yangModuleInfo); return new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration); } @Override - public void close() throws Exception { - if(this.osgiReg != null) { + public synchronized void close() throws Exception { + if (this.osgiReg != null) { this.osgiReg.unregister(); }