Write failed node data on recovery to a file
[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 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
22 import org.opendaylight.controller.sample.kitchen.api.EggsType;
23 import org.opendaylight.controller.sample.kitchen.api.KitchenService;
24 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToastType;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.osgi.framework.BundleContext;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  *
32  */
33 public final class KitchenServiceModule extends AbstractKitchenServiceModule {
34     private static final Logger log = LoggerFactory.getLogger(KitchenServiceModule.class);
35
36     private BundleContext bundleContext;
37
38     public KitchenServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
39         super(identifier, dependencyResolver);
40     }
41
42     public KitchenServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
43             final KitchenServiceModule oldModule, final java.lang.AutoCloseable oldInstance) {
44
45         super(identifier, dependencyResolver, oldModule, oldInstance);
46     }
47
48     @Override
49     protected void customValidation(){
50         // No need to validate dependencies, since all dependencies have mandatory true flag in yang
51         // config-subsystem will perform the validation
52     }
53
54     @Override
55     public AutoCloseable createInstance() {
56         // The KitchenServiceImpl instance is created and advertised with the OSGi registry via blueprint
57         // so obtain it here so we can return it to the config system. It's possible the blueprint container
58         // hasn't been created yet so we busy wait 5 min for the service.
59         final WaitingServiceTracker<KitchenService> tracker = WaitingServiceTracker.create(
60                 KitchenService.class, bundleContext);
61         final KitchenService kitchenService = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
62
63         final class AutoCloseableKitchenService implements KitchenService, AutoCloseable {
64             @Override
65             public void close() {
66                 // We need to close the ServiceTracker however we don't want to close the actual
67                 // KitchenService instance because its life-cycle is controlled via blueprint.
68                 tracker.close();
69                 log.info("KitchenService (instance {}) closed.", kitchenService);
70             }
71
72             @Override
73             public Future<RpcResult<Void>> makeBreakfast(final EggsType eggs, final Class<? extends ToastType> toast,
74                     final int toastDoneness) {
75                 return kitchenService.makeBreakfast(eggs, toast, toastDoneness);
76             }
77         }
78
79         return new AutoCloseableKitchenService();
80     }
81
82     public void setBundleContext(BundleContext bundleContext) {
83         this.bundleContext = bundleContext;
84     }
85 }