REST API to fetch Node Property
[controller.git] / opendaylight / md-sal / samples / toaster-consumer / src / main / java / org / opendaylight / controller / sample / toaster / provider / impl / ToastConsumerImpl.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.controller.sample.toaster.provider.impl;
9
10 import java.util.concurrent.ExecutionException;
11
12 import org.opendaylight.controller.config.yang.config.toaster_consumer.impl.ToasterConsumerRuntimeMXBean;
13 import org.opendaylight.controller.sal.binding.api.NotificationListener;
14 import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer;
15 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.*;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class ToastConsumerImpl implements
21         ToastConsumer,
22         NotificationListener<ToastDone>,ToasterConsumerRuntimeMXBean {
23
24     private static final Logger log = LoggerFactory.getLogger(ToastConsumerImpl.class);
25
26     private ToasterService toaster;
27
28     public ToastConsumerImpl(ToasterService toaster) {
29         this.toaster = toaster;
30     }
31
32     @Override
33     public boolean createToast(Class<? extends ToastType> type, int doneness) {
34         MakeToastInputBuilder toastInput = new MakeToastInputBuilder();
35         toastInput.setToasterDoneness((long) doneness);
36         toastInput.setToasterToastType(type);
37
38         try {
39             RpcResult<Void> result = toaster.makeToast(toastInput.build()).get();
40
41             if (result.isSuccessful()) {
42                 log.trace("Toast was successfully finished");
43             } else {
44                 log.warn("Toast was not successfully finished");
45             }
46             return result.isSuccessful();
47         } catch (InterruptedException | ExecutionException e) {
48             log.warn("Error occurred during toast creation");
49         }
50         return false;
51
52     }
53
54     @Override
55     public void onNotification(ToastDone notification) {
56         log.trace("ToastDone Notification Received: {} ",notification.getToastStatus());
57     }
58
59     @Override
60     public Boolean makeHashBrownToast(Integer doneness) {
61         return createToast(HashBrown.class, doneness);
62     }
63 }