Merge "Bug 716: Errors on controller shutdown"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / RuntimeMappingModule.java
index aadf2fcc8dfdeb730877e40392bc04ae6505ce0e..0f0ce0dc9dd24fb41bc54bde70c196ba2d4d511e 100644 (file)
@@ -1,11 +1,9 @@
-/**
- * Generated file
-
- * Generated from: yang module name: opendaylight-sal-binding-broker-impl  yang module local name: runtime-generated-mapping
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Wed Nov 20 18:20:19 CET 2013
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
- * Do not modify this file unless it is present under src/main directory
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.controller.config.yang.md.sal.binding.impl;
 
@@ -13,8 +11,6 @@ import java.util.Hashtable;
 import java.util.Map.Entry;
 import java.util.Set;
 
-import javassist.ClassPool;
-
 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
 import org.opendaylight.yangtools.concepts.Delegator;
 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
@@ -30,7 +26,10 @@ import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
 /**
@@ -39,6 +38,8 @@ import com.google.common.base.Preconditions;
 public final class RuntimeMappingModule extends
         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractRuntimeMappingModule {
 
+    private static final Logger LOG = LoggerFactory.getLogger(RuntimeMappingModule.class);
+
     private BundleContext bundleContext;
 
     public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
@@ -66,14 +67,13 @@ public final class RuntimeMappingModule extends
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        
+
         RuntimeGeneratedMappingServiceProxy potential = tryToReuseGlobalInstance();
         if(potential != null) {
             return potential;
         }
-        RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
-        service.setPool(SingletonHolder.CLASS_POOL);
-        service.init();
+
+        final RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl(SingletonHolder.CLASS_POOL);
         bundleContext.registerService(SchemaServiceListener.class, service, new Hashtable<String,String>());
         return service;
     }
@@ -103,7 +103,7 @@ public final class RuntimeMappingModule extends
     BindingIndependentMappingService, //
     Delegator<BindingIndependentMappingService>, //
     AutoCloseable {
-        
+
         private BindingIndependentMappingService delegate;
         private ServiceReference<BindingIndependentMappingService> reference;
         private BundleContext bundleContext;
@@ -116,48 +116,68 @@ public final class RuntimeMappingModule extends
             this.delegate = Preconditions.checkNotNull(delegate);
         }
 
+        @Override
         public CodecRegistry getCodecRegistry() {
             return delegate.getCodecRegistry();
         }
 
+        @Override
         public CompositeNode toDataDom(DataObject data) {
             return delegate.toDataDom(data);
         }
 
+        @Override
         public Entry<InstanceIdentifier, CompositeNode> toDataDom(
                 Entry<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject>, DataObject> entry) {
             return delegate.toDataDom(entry);
         }
 
+        @Override
         public InstanceIdentifier toDataDom(
                 org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path) {
             return delegate.toDataDom(path);
         }
 
+        @Override
         public DataObject dataObjectFromDataDom(
                 org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path,
                 CompositeNode result) throws DeserializationException {
             return delegate.dataObjectFromDataDom(path, result);
         }
 
+        @Override
         public org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> fromDataDom(InstanceIdentifier entry)
                 throws DeserializationException {
             return delegate.fromDataDom(entry);
         }
 
+        @Override
         public Set<QName> getRpcQNamesFor(Class<? extends RpcService> service) {
             return delegate.getRpcQNamesFor(service);
         }
 
+        @Override
+        public Optional<Class<? extends RpcService>> getRpcServiceClassFor(String namespace, String revision) {
+            return delegate.getRpcServiceClassFor(namespace,revision);
+        }
+
+        @Override
         public DataContainer dataObjectFromDataDom(Class<? extends DataContainer> inputClass, CompositeNode domInput) {
             return delegate.dataObjectFromDataDom(inputClass, domInput);
         }
-        
+
         @Override
-        public void close() throws Exception {
+        public void close() {
             if(delegate != null) {
                 delegate = null;
-                bundleContext.ungetService(reference);
+
+                try {
+                    bundleContext.ungetService(reference);
+                } catch (IllegalStateException e) {
+                    // Indicates the BundleContext is no longer valid which can happen normally on shutdown.
+                    LOG.debug( "Error unregistering service", e );
+                }
+
                 bundleContext= null;
                 reference = null;
             }