Bug 809: Enhancements to the toaster example
[controller.git] / opendaylight / md-sal / samples / toaster-provider / src / main / java / org / opendaylight / controller / config / yang / config / toaster_provider / impl / ToasterProviderModule.java
1 /**
2 * Generated file
3
4 * Generated from: yang module name: toaster-provider-impl  yang module local name: toaster-provider-impl
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Wed Feb 05 11:05:32 CET 2014
7 *
8 * Do not modify this file unless it is present under src/main directory
9 */
10 package org.opendaylight.controller.config.yang.config.toaster_provider.impl;
11
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
13 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
14 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
15 import org.opendaylight.controller.sample.toaster.provider.OpendaylightToaster;
16 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22 *
23 */
24 public final class ToasterProviderModule extends org.opendaylight.controller.config.yang.config.toaster_provider.impl.AbstractToasterProviderModule
25  {
26     private static final Logger log = LoggerFactory.getLogger(ToasterProviderModule.class);
27
28     public ToasterProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
29         super(identifier, dependencyResolver);
30     }
31
32     public ToasterProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
33             ToasterProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
34
35         super(identifier, dependencyResolver, oldModule, oldInstance);
36     }
37
38     @Override
39     protected void customValidation() {
40         // No need to validate dependencies, since all dependencies have mandatory true flag in yang
41         // config-subsystem will perform the validation for dependencies
42     }
43
44     @Override
45     public java.lang.AutoCloseable createInstance() {
46         final OpendaylightToaster opendaylightToaster = new OpendaylightToaster();
47
48         // Register to md-sal
49         opendaylightToaster.setNotificationProvider(getNotificationServiceDependency());
50
51         DataProviderService dataBrokerService = getDataBrokerDependency();
52         opendaylightToaster.setDataProvider(dataBrokerService);
53
54         final ListenerRegistration<DataChangeListener> dataChangeListenerRegistration =
55                 dataBrokerService.registerDataChangeListener( OpendaylightToaster.TOASTER_IID, opendaylightToaster );
56
57         final BindingAwareBroker.RpcRegistration<ToasterService> rpcRegistration = getRpcRegistryDependency()
58                 .addRpcImplementation(ToasterService.class, opendaylightToaster);
59
60         // Register runtimeBean for toaster statistics via JMX
61         final ToasterProviderRuntimeRegistration runtimeReg = getRootRuntimeBeanRegistratorWrapper().register(
62                 opendaylightToaster);
63
64         // Wrap toaster as AutoCloseable and close registrations to md-sal at
65         // close()
66         final class AutoCloseableToaster implements AutoCloseable {
67
68             @Override
69             public void close() throws Exception {
70                 dataChangeListenerRegistration.close();
71                 rpcRegistration.close();
72                 runtimeReg.close();
73                 opendaylightToaster.close();
74                 log.info("Toaster provider (instance {}) torn down.", this);
75             }
76         }
77
78         AutoCloseable ret = new AutoCloseableToaster();
79         log.info("Toaster provider (instance {}) initialized.", ret);
80         return ret;
81     }
82 }

©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.