2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sample.toaster.provider.impl;
10 import java.util.concurrent.ExecutionException;
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;
20 public class ToastConsumerImpl implements
22 NotificationListener<ToastDone>,ToasterConsumerRuntimeMXBean {
24 private static final Logger log = LoggerFactory.getLogger(ToastConsumerImpl.class);
26 private ToasterService toaster;
28 public ToastConsumerImpl(ToasterService toaster) {
29 this.toaster = toaster;
33 public boolean createToast(Class<? extends ToastType> type, int doneness) {
34 MakeToastInputBuilder toastInput = new MakeToastInputBuilder();
35 toastInput.setToasterDoneness((long) doneness);
36 toastInput.setToasterToastType(type);
39 RpcResult<Void> result = toaster.makeToast(toastInput.build()).get();
41 if (result.isSuccessful()) {
42 log.trace("Toast was successfully finished");
44 log.warn("Toast was not successfully finished");
46 return result.isSuccessful();
47 } catch (InterruptedException | ExecutionException e) {
48 log.warn("Error occurred during toast creation");
55 public void onNotification(ToastDone notification) {
56 log.trace("ToastDone Notification Received: {} ",notification.getToastStatus());
60 public Boolean makeHashBrownToast(Integer doneness) {
61 return createToast(HashBrown.class, doneness);