From 0942727633b34b568e9a0c91716959a262a37600 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 8 Nov 2022 13:57:28 +0100 Subject: [PATCH] Migrate toaster-consumer to OSGi DS Use declarative services instead of blueprint and do not pull in the blueprint extension. JIRA: CONTROLLER-2003 Change-Id: I1c7987086c0469001a7e1ee5cd5e8f921b57f7a7 Signed-off-by: Samuel Schneider Signed-off-by: Robert Varga --- features/odl-toaster/pom.xml | 6 ---- .../md-sal/samples/toaster-consumer/pom.xml | 18 ++++++++++ .../kitchen/impl/KitchenServiceImpl.java | 34 ++++++++++++++++--- .../OSGI-INF/blueprint/toaster-consumer.xml | 25 -------------- 4 files changed, 47 insertions(+), 36 deletions(-) delete mode 100644 opendaylight/md-sal/samples/toaster-consumer/src/main/resources/OSGI-INF/blueprint/toaster-consumer.xml diff --git a/features/odl-toaster/pom.xml b/features/odl-toaster/pom.xml index 8576a00608..d568147dc1 100644 --- a/features/odl-toaster/pom.xml +++ b/features/odl-toaster/pom.xml @@ -32,12 +32,6 @@ xml features - - org.opendaylight.controller - odl-controller-blueprint - xml - features - org.opendaylight.controller.samples sample-toaster diff --git a/opendaylight/md-sal/samples/toaster-consumer/pom.xml b/opendaylight/md-sal/samples/toaster-consumer/pom.xml index 8fa0323528..b12c7e7805 100644 --- a/opendaylight/md-sal/samples/toaster-consumer/pom.xml +++ b/opendaylight/md-sal/samples/toaster-consumer/pom.xml @@ -21,10 +21,28 @@ org.opendaylight.controller sal-common-util + + org.opendaylight.mdsal + mdsal-binding-api + org.opendaylight.mdsal yang-binding + + jakarta.annotation + jakarta.annotation-api + true + + + org.osgi + org.osgi.service.component.annotations + + + com.guicedee.services + javax.inject + true + 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 4f245685aa..a40fe5e9ff 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 @@ -16,10 +16,15 @@ import com.google.common.util.concurrent.MoreExecutors; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; 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.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput; 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; @@ -30,30 +35,49 @@ import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120 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.ToasterService; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class KitchenServiceImpl extends AbstractMXBean +@Singleton +@Component(service = KitchenService.class, immediate = true) +public final class KitchenServiceImpl extends AbstractMXBean implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener { private static final Logger LOG = LoggerFactory.getLogger(KitchenServiceImpl.class); private static final MakeToastOutput EMPTY_MAKE_OUTPUT = new MakeToastOutputBuilder().build(); - private final ToasterService toaster; - private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); + private final ToasterService toaster; + private final Registration reg; private volatile boolean toasterOutOfBread; - public KitchenServiceImpl(final ToasterService toaster) { + @Inject + @Activate + public KitchenServiceImpl(@Reference final RpcConsumerRegistry rpcRegistry, + @Reference final NotificationService notifService) { super("KitchenService", "toaster-consumer", null); - this.toaster = toaster; + toaster = rpcRegistry.getRpcService(ToasterService.class); + reg = notifService.registerNotificationListener(this); + register(); + } + + @PreDestroy + @Deactivate + public void close() { + unregister(); + reg.close(); } @Override diff --git a/opendaylight/md-sal/samples/toaster-consumer/src/main/resources/OSGI-INF/blueprint/toaster-consumer.xml b/opendaylight/md-sal/samples/toaster-consumer/src/main/resources/OSGI-INF/blueprint/toaster-consumer.xml deleted file mode 100644 index 16e8f98d6a..0000000000 --- a/opendaylight/md-sal/samples/toaster-consumer/src/main/resources/OSGI-INF/blueprint/toaster-consumer.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - -- 2.36.6