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