Add missing license headers
[controller.git] / opendaylight / md-sal / samples / toaster-provider / src / main / java / org / opendaylight / controller / config / yang / config / toaster_provider / impl / ToasterProviderModule.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 /**
10 * Generated file
11
12 * Generated from: yang module name: toaster-provider-impl  yang module local name: toaster-provider-impl
13 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
14 * Generated at: Wed Feb 05 11:05:32 CET 2014
15 *
16 * Do not modify this file unless it is present under src/main directory
17 */
18 package org.opendaylight.controller.config.yang.config.toaster_provider.impl;
19
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
22 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
25 import org.opendaylight.controller.sample.toaster.provider.OpendaylightToaster;
26 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService;
27 import org.opendaylight.yangtools.concepts.ListenerRegistration;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32 *
33 */
34 public final class ToasterProviderModule extends
35         org.opendaylight.controller.config.yang.config.toaster_provider.impl.AbstractToasterProviderModule {
36     private static final Logger log = LoggerFactory.getLogger(ToasterProviderModule.class);
37
38     public ToasterProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
39             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
40         super(identifier, dependencyResolver);
41     }
42
43     public ToasterProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
44             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
45             final ToasterProviderModule oldModule, final java.lang.AutoCloseable oldInstance) {
46
47         super(identifier, dependencyResolver, oldModule, oldInstance);
48     }
49
50     @Override
51     protected void customValidation() {
52         // No need to validate dependencies, since all dependencies have
53         // mandatory true flag in yang
54         // config-subsystem will perform the validation for dependencies
55     }
56
57     @Override
58     public java.lang.AutoCloseable createInstance() {
59         final OpendaylightToaster opendaylightToaster = new OpendaylightToaster();
60
61         // Register to md-sal
62         opendaylightToaster.setNotificationProvider(getNotificationServiceDependency());
63
64         DataBroker dataBrokerService = getDataBrokerDependency();
65         opendaylightToaster.setDataProvider(dataBrokerService);
66
67         final ListenerRegistration<DataChangeListener> dataChangeListenerRegistration = dataBrokerService
68                 .registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, OpendaylightToaster.TOASTER_IID,
69                         opendaylightToaster, DataChangeScope.SUBTREE);
70
71         final BindingAwareBroker.RpcRegistration<ToasterService> rpcRegistration = getRpcRegistryDependency()
72                 .addRpcImplementation(ToasterService.class, opendaylightToaster);
73
74         // Register runtimeBean for toaster statistics via JMX
75         final ToasterProviderRuntimeRegistration runtimeReg = getRootRuntimeBeanRegistratorWrapper().register(
76                 opendaylightToaster);
77
78         // Wrap toaster as AutoCloseable and close registrations to md-sal at
79         // close()
80         final class AutoCloseableToaster implements AutoCloseable {
81
82             @Override
83             public void close() throws Exception {
84                 dataChangeListenerRegistration.close();
85                 rpcRegistration.close();
86                 runtimeReg.close();
87                 closeQuietly(opendaylightToaster);
88                 log.info("Toaster provider (instance {}) torn down.", this);
89             }
90
91             private void closeQuietly(final AutoCloseable resource) {
92                 try {
93                     resource.close();
94                 } catch (final Exception e) {
95                     log.debug("Ignoring exception while closing {}", resource, e);
96                 }
97             }
98         }
99
100         AutoCloseable ret = new AutoCloseableToaster();
101         log.info("Toaster provider (instance {}) initialized.", ret);
102         return ret;
103     }
104 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.