Avoid Map-Register inconsistencies due to SMR handling exceptions
[lispflowmapping.git] / mappingservice / netconf / src / main / java / org / opendaylight / lispflowmapping / config / yang / netconf / impl / LfmNetconfConnectorProviderModule.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.lispflowmapping.config.yang.netconf.impl;
10
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
12 import org.opendaylight.lispflowmapping.netconf.impl.LispDeviceNetconfConnector;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lispflowmapping.netconf.rev140706.LfmNetconfConnectorService;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class LfmNetconfConnectorProviderModule extends org.opendaylight.lispflowmapping.config.yang.netconf.impl.AbstractLfmNetconfConnectorProviderModule {
18     private static final Logger log = LoggerFactory.getLogger(LfmNetconfConnectorProviderModule.class);
19
20     public LfmNetconfConnectorProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
21         super(identifier, dependencyResolver);
22     }
23
24     public LfmNetconfConnectorProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.lispflowmapping.config.yang.netconf.impl.LfmNetconfConnectorProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
25         super(identifier, dependencyResolver, oldModule, oldInstance);
26     }
27
28     @Override
29     public void customValidation() {
30         // add custom validation form module attributes here.
31     }
32
33     @Override
34     public java.lang.AutoCloseable createInstance() {
35
36         final LispDeviceNetconfConnector lnconfConnector = LispDeviceNetconfConnector.createLispDeviceNetconfConnector();
37
38         final BindingAwareBroker.RpcRegistration<LfmNetconfConnectorService> rpcRegistration = getRpcRegistryDependency()
39                 .addRpcImplementation(LfmNetconfConnectorService.class, lnconfConnector);
40
41
42         // Wrap as AutoCloseable and close registrations to md-sal at close()
43         final class AutoCloseableNCC implements AutoCloseable {
44
45             @Override
46             public void close() throws Exception {
47                 rpcRegistration.close();
48                 lnconfConnector.close();
49                 log.info("Lisp netconf connector (instance {}) torn down.", this);
50             }
51         }
52
53         AutoCloseable ret = new AutoCloseableNCC();
54         log.info("Lisp netconf connector provider (instance {}) initialized.", ret);
55         return ret;
56
57     }
58
59
60 }