1 package org.opendaylight.controller.sample.kitchen.impl;
3 import java.util.concurrent.ExecutionException;
5 import org.opendaylight.controller.config.yang.config.kitchen_service.impl.KitchenServiceRuntimeMXBean;
6 import org.opendaylight.controller.sample.kitchen.api.EggsType;
7 import org.opendaylight.controller.sample.kitchen.api.KitchenService;
8 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder;
9 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToastType;
10 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterListener;
11 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterOutOfBread;
12 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestocked;
13 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService;
14 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
15 import org.opendaylight.yangtools.yang.common.RpcResult;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener {
21 private static final Logger log = LoggerFactory.getLogger( KitchenServiceImpl.class );
23 private final ToasterService toaster;
25 private volatile boolean toasterOutOfBread;
27 public KitchenServiceImpl(ToasterService toaster) {
28 this.toaster = toaster;
32 public boolean makeBreakfast( EggsType eggs, Class<? extends ToastType> toast, int toastDoneness ) {
34 if( toasterOutOfBread )
36 log.info( "We're out of toast but we can make eggs" );
40 // Access the ToasterService to make the toast.
41 // We don't actually make the eggs for this example - sorry.
42 MakeToastInputBuilder toastInput = new MakeToastInputBuilder();
43 toastInput.setToasterDoneness( (long) toastDoneness);
44 toastInput.setToasterToastType( toast );
47 RpcResult<Void> result = toaster.makeToast( toastInput.build() ).get();
49 if( result.isSuccessful() ) {
50 log.info( "makeToast succeeded" );
52 log.warn( "makeToast failed: " + result.getErrors() );
55 return result.isSuccessful();
56 } catch( InterruptedException | ExecutionException e ) {
57 log.warn( "Error occurred during toast creation" );
63 public Boolean makeScrambledWithWheat() {
64 return makeBreakfast( EggsType.SCRAMBLED, WheatBread.class, 2 );
68 * Implemented from the ToasterListener interface.
71 public void onToasterOutOfBread( ToasterOutOfBread notification ) {
72 log.info( "ToasterOutOfBread notification" );
73 toasterOutOfBread = true;
77 * Implemented from the ToasterListener interface.
80 public void onToasterRestocked( ToasterRestocked notification ) {
81 log.info( "ToasterRestocked notification - amountOfBread: " + notification.getAmountOfBread() );
82 toasterOutOfBread = false;