X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Ftoaster-consumer%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsample%2Fkitchen%2Fimpl%2FKitchenServiceImpl.java;h=306efc5e63dd613b335f935ca168f4bd8a1fd0fa;hb=HEAD;hp=1401363a70ecd4162ce06440fa4cb9ff36408af7;hpb=4740dd36abb5edd89d97257b20bd84cfc2ac8685;p=controller.git diff --git a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java index 1401363a70..b67de11367 100644 --- a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java +++ b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java @@ -13,6 +13,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import java.util.List; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -24,13 +25,13 @@ import org.opendaylight.controller.sample.kitchen.api.EggsType; import org.opendaylight.controller.sample.kitchen.api.KitchenService; import org.opendaylight.controller.sample.kitchen.api.KitchenServiceRuntimeMXBean; import org.opendaylight.mdsal.binding.api.NotificationService; -import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry; +import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener; +import org.opendaylight.mdsal.binding.api.RpcService; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToast; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastOutput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastOutputBuilder; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToastType; -import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterListener; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterOutOfBread; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestocked; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread; @@ -50,9 +51,7 @@ import org.slf4j.LoggerFactory; @Singleton @Component(service = KitchenService.class, immediate = true) -public final class KitchenServiceImpl extends AbstractMXBean - implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener { - +public final class KitchenServiceImpl extends AbstractMXBean implements KitchenService, KitchenServiceRuntimeMXBean { private static final Logger LOG = LoggerFactory.getLogger(KitchenServiceImpl.class); private static final MakeToastOutput EMPTY_MAKE_OUTPUT = new MakeToastOutputBuilder().build(); @@ -64,11 +63,19 @@ public final class KitchenServiceImpl extends AbstractMXBean @Inject @Activate - public KitchenServiceImpl(@Reference final RpcConsumerRegistry rpcRegistry, + public KitchenServiceImpl(@Reference final RpcService rpcService, @Reference final NotificationService notifService) { super("KitchenService", "toaster-consumer", null); - makeToast = rpcRegistry.getRpc(MakeToast.class); - reg = notifService.registerNotificationListener(this); + makeToast = rpcService.getRpc(MakeToast.class); + reg = notifService.registerCompositeListener(new CompositeListener(Set.of( + new CompositeListener.Component<>(ToasterOutOfBread.class, notification -> { + LOG.info("ToasterOutOfBread notification"); + toasterOutOfBread = true; + }), + new CompositeListener.Component<>(ToasterRestocked.class, notification -> { + LOG.info("ToasterRestocked notification - amountOfBread: {}", notification.getAmountOfBread()); + toasterOutOfBread = false; + })))); register(); } @@ -151,22 +158,4 @@ public final class KitchenServiceImpl extends AbstractMXBean return Boolean.FALSE; } - - /** - * Implemented from the ToasterListener interface. - */ - @Override - public void onToasterOutOfBread(final ToasterOutOfBread notification) { - LOG.info("ToasterOutOfBread notification"); - toasterOutOfBread = true; - } - - /** - * Implemented from the ToasterListener interface. - */ - @Override - public void onToasterRestocked(final ToasterRestocked notification) { - LOG.info("ToasterRestocked notification - amountOfBread: {}", notification.getAmountOfBread()); - toasterOutOfBread = false; - } }