X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Ftoaster-consumer%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fconfig%2Fkitchen_service%2Fimpl%2FKitchenServiceModule.java;h=65fba77fb647553b26d4c10a0c80e4fe753d88a3;hp=8d67fb4ed09371394dc10cc9b9d8105f860d16db;hb=dceb9db7853dabfbd4abdfb3d886a79871097831;hpb=6d73d16b194435ea1ea783a37d1b51fc1f558a1f diff --git a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/config/yang/config/kitchen_service/impl/KitchenServiceModule.java b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/config/yang/config/kitchen_service/impl/KitchenServiceModule.java index 8d67fb4ed0..65fba77fb6 100644 --- a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/config/yang/config/kitchen_service/impl/KitchenServiceModule.java +++ b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/config/yang/config/kitchen_service/impl/KitchenServiceModule.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014, 2015 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + /** * Generated file @@ -10,15 +18,12 @@ package org.opendaylight.controller.config.yang.config.kitchen_service.impl; import java.util.concurrent.Future; - +import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker; import org.opendaylight.controller.sample.kitchen.api.EggsType; import org.opendaylight.controller.sample.kitchen.api.KitchenService; -import org.opendaylight.controller.sample.kitchen.impl.KitchenServiceImpl; 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.ToasterService; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.NotificationListener; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,6 +33,8 @@ import org.slf4j.LoggerFactory; public final class KitchenServiceModule extends AbstractKitchenServiceModule { private static final Logger log = LoggerFactory.getLogger(KitchenServiceModule.class); + private BundleContext bundleContext; + public KitchenServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } @@ -45,36 +52,34 @@ public final class KitchenServiceModule extends AbstractKitchenServiceModule { } @Override - public java.lang.AutoCloseable createInstance() { - ToasterService toasterService = getRpcRegistryDependency().getRpcService(ToasterService.class); - - final KitchenServiceImpl kitchenService = new KitchenServiceImpl(toasterService); - - final ListenerRegistration toasterListenerReg = - getNotificationServiceDependency().registerNotificationListener( kitchenService ); - - final KitchenServiceRuntimeRegistration runtimeReg = - getRootRuntimeBeanRegistratorWrapper().register( kitchenService ); + public AutoCloseable createInstance() { + // The KitchenServiceImpl instance is created and advertised with the OSGi registry via blueprint + // so obtain it here so we can return it to the config system. It's possible the blueprint container + // hasn't been created yet so we busy wait 5 min for the service. + final WaitingServiceTracker tracker = WaitingServiceTracker.create( + KitchenService.class, bundleContext); + final KitchenService kitchenService = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); final class AutoCloseableKitchenService implements KitchenService, AutoCloseable { - @Override - public void close() throws Exception { - toasterListenerReg.close(); - runtimeReg.close(); - log.info("Toaster consumer (instance {}) torn down.", this); + public void close() { + // We need to close the ServiceTracker however we don't want to close the actual + // KitchenService instance because its life-cycle is controlled via blueprint. + tracker.close(); + log.info("KitchenService (instance {}) closed.", kitchenService); } @Override - public Future> makeBreakfast( final EggsType eggs, - final Class toast, - final int toastDoneness ) { - return kitchenService.makeBreakfast( eggs, toast, toastDoneness ); + public Future> makeBreakfast(final EggsType eggs, final Class toast, + final int toastDoneness) { + return kitchenService.makeBreakfast(eggs, toast, toastDoneness); } } - AutoCloseable ret = new AutoCloseableKitchenService(); - log.info("KitchenService (instance {}) initialized.", ret ); - return ret; + return new AutoCloseableKitchenService(); + } + + public void setBundleContext(BundleContext bundleContext) { + this.bundleContext = bundleContext; } }