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.ModuleIdentifier;
12 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
14 import org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataBroker;
15 import org.osgi.framework.BundleContext;
17 public class DomConcurrentDataBrokerModule extends AbstractDomConcurrentDataBrokerModule {
18 private BundleContext bundleContext;
20 public DomConcurrentDataBrokerModule(final ModuleIdentifier identifier,
21 final DependencyResolver dependencyResolver) {
22 super(identifier, dependencyResolver);
25 public DomConcurrentDataBrokerModule(final ModuleIdentifier identifier,
26 final DependencyResolver dependencyResolver, final DomConcurrentDataBrokerModule oldModule,
27 final AutoCloseable oldInstance) {
28 super(identifier, dependencyResolver, oldModule, oldInstance);
32 public boolean canReuseInstance(AbstractDomConcurrentDataBrokerModule oldModule) {
37 public AutoCloseable createInstance() {
38 // The ConcurrentDOMDataBroker is provided via blueprint so wait for and return it here for
39 // backwards compatibility.
40 WaitingServiceTracker<DOMDataBroker> tracker = WaitingServiceTracker.create(
41 DOMDataBroker.class, bundleContext, "(type=default)");
42 DOMDataBroker delegate = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
43 return new ForwardingConcurrentDOMBroker(delegate, tracker);
46 public void setBundleContext(final BundleContext bundleContext) {
47 this.bundleContext = bundleContext;
50 private static class ForwardingConcurrentDOMBroker extends ForwardingDOMDataBroker implements AutoCloseable {
51 private final DOMDataBroker delegate;
52 private final AutoCloseable closeable;
54 ForwardingConcurrentDOMBroker(DOMDataBroker delegate, AutoCloseable closeable) {
55 this.delegate = delegate;
56 this.closeable = closeable;
60 protected DOMDataBroker delegate() {
65 public void close() throws Exception {
66 // We don't close the delegate as the life-cycle is controlled via blueprint.