Bug 1112: Update toaster to use async best practices
[controller.git] / opendaylight / md-sal / samples / toaster-consumer / src / main / java / org / opendaylight / controller / config / yang / config / kitchen_service / impl / KitchenServiceModule.java
1 /**
2  * Generated file
3
4  * Generated from: yang module name: toaster-consumer-impl  yang module local name: toaster-consumer-impl
5  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6  * Generated at: Wed Feb 05 11:31:30 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.kitchen_service.impl;
11
12 import java.util.concurrent.Future;
13
14 import org.opendaylight.controller.sample.kitchen.api.EggsType;
15 import org.opendaylight.controller.sample.kitchen.api.KitchenService;
16 import org.opendaylight.controller.sample.kitchen.impl.KitchenServiceImpl;
17 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToastType;
18 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService;
19 import org.opendaylight.yangtools.concepts.Registration;
20 import org.opendaylight.yangtools.yang.binding.NotificationListener;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  *
27  */
28 public final class KitchenServiceModule extends AbstractKitchenServiceModule {
29     private static final Logger log = LoggerFactory.getLogger(KitchenServiceModule.class);
30
31     public KitchenServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
32         super(identifier, dependencyResolver);
33     }
34
35     public KitchenServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
36             final KitchenServiceModule oldModule, final java.lang.AutoCloseable oldInstance) {
37
38         super(identifier, dependencyResolver, oldModule, oldInstance);
39     }
40
41     @Override
42     protected void customValidation(){
43         // No need to validate dependencies, since all dependencies have mandatory true flag in yang
44         // config-subsystem will perform the validation
45     }
46
47     @Override
48     public java.lang.AutoCloseable createInstance() {
49         ToasterService toasterService = getRpcRegistryDependency().getRpcService(ToasterService.class);
50
51         final KitchenServiceImpl kitchenService = new KitchenServiceImpl(toasterService);
52
53         final Registration<NotificationListener> toasterListenerReg =
54                 getNotificationServiceDependency().registerNotificationListener( kitchenService );
55
56         final KitchenServiceRuntimeRegistration runtimeReg =
57                 getRootRuntimeBeanRegistratorWrapper().register( kitchenService );
58
59         final class AutoCloseableKitchenService implements KitchenService, AutoCloseable {
60
61             @Override
62             public void close() throws Exception {
63                 toasterListenerReg.close();
64                 runtimeReg.close();
65                 log.info("Toaster consumer (instance {}) torn down.", this);
66             }
67
68             @Override
69             public Future<RpcResult<Void>> makeBreakfast( final EggsType eggs,
70                                                           final Class<? extends ToastType> toast,
71                                                           final int toastDoneness ) {
72                 return kitchenService.makeBreakfast( eggs, toast, toastDoneness );
73             }
74         }
75
76         AutoCloseable ret = new AutoCloseableKitchenService();
77         log.info("KitchenService (instance {}) initialized.", ret );
78         return ret;
79     }
80 }