<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-common-util</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-binding-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
</dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.guicedee.services</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
+ </dependency>
</dependencies>
<scm>
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;
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
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
- odl:use-default-for-reference-types="true">
-
- <!-- Retrieves the RPC service for the ToasterService interface -->
- <odl:rpc-service id="toasterService" interface="org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService"/>
-
- <!-- Create the KitchenServiceImpl instance and inject the RPC service identified by "toasterService" -->
- <bean id="kitchenService" class="org.opendaylight.controller.sample.kitchen.impl.KitchenServiceImpl"
- init-method="register" destroy-method="unregister">
- <argument ref="toasterService"/>
- </bean>
-
- <!-- Register the KitchenServiceImpl to receive yang notifications -->
- <odl:notification-listener ref="kitchenService"/>
-
- <!-- Advertise the KitchenServiceImpl with the OSGi registry with the type property set to "default" . The
- type property is optional but can be used to distinguish this implementation from any other potential
- KitchenService implementations (if there were any). Clients consuming the KitchenService can pick the
- desired implementation via the particular type.
- -->
- <service ref="kitchenService" interface="org.opendaylight.controller.sample.kitchen.api.KitchenService"
- odl:type="default"/>
-</blueprint>