2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yang.config.concurrent_data_broker;
10 import org.opendaylight.controller.config.api.DependencyResolver;
11 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
13 import org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataBroker;
14 import org.osgi.framework.BundleContext;
16 public class DomConcurrentDataBrokerModule extends AbstractDomConcurrentDataBrokerModule {
17 private BundleContext bundleContext;
19 public DomConcurrentDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
20 super(identifier, dependencyResolver);
23 public DomConcurrentDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final DependencyResolver dependencyResolver, final DomConcurrentDataBrokerModule oldModule, final AutoCloseable oldInstance) {
24 super(identifier, dependencyResolver, oldModule, oldInstance);
28 public boolean canReuseInstance(AbstractDomConcurrentDataBrokerModule oldModule) {
33 public AutoCloseable createInstance() {
34 // The ConcurrentDOMDataBroker is provided via blueprint so wait for and return it here for
35 // backwards compatibility.
36 WaitingServiceTracker<DOMDataBroker> tracker = WaitingServiceTracker.create(
37 DOMDataBroker.class, bundleContext, "(type=default)");
38 DOMDataBroker delegate = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
39 return new ForwardingConcurrentDOMBroker(delegate, tracker);
42 public void setBundleContext(final BundleContext bundleContext) {
43 this.bundleContext = bundleContext;
46 private static class ForwardingConcurrentDOMBroker extends ForwardingDOMDataBroker implements AutoCloseable {
47 private final DOMDataBroker delegate;
48 private final AutoCloseable closeable;
50 ForwardingConcurrentDOMBroker(DOMDataBroker delegate, AutoCloseable closeable) {
51 this.delegate = delegate;
52 this.closeable = closeable;
56 protected DOMDataBroker delegate() {
61 public void close() throws Exception {
62 // We don't close the delegate as the life-cycle is controlled via blueprint.