Fix warnings/javadocs in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / config / yang / config / concurrent_data_broker / DomConcurrentDataBrokerModule.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.yang.config.concurrent_data_broker;
9
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;
16
17 public class DomConcurrentDataBrokerModule extends AbstractDomConcurrentDataBrokerModule {
18     private BundleContext bundleContext;
19
20     public DomConcurrentDataBrokerModule(final ModuleIdentifier identifier,
21             final DependencyResolver dependencyResolver) {
22         super(identifier, dependencyResolver);
23     }
24
25     public DomConcurrentDataBrokerModule(final ModuleIdentifier identifier,
26             final DependencyResolver dependencyResolver, final DomConcurrentDataBrokerModule oldModule,
27             final AutoCloseable oldInstance) {
28         super(identifier, dependencyResolver, oldModule, oldInstance);
29     }
30
31     @Override
32     public boolean canReuseInstance(AbstractDomConcurrentDataBrokerModule oldModule) {
33         return true;
34     }
35
36     @Override
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);
44     }
45
46     public void setBundleContext(final BundleContext bundleContext) {
47         this.bundleContext = bundleContext;
48     }
49
50     private static class ForwardingConcurrentDOMBroker extends ForwardingDOMDataBroker implements AutoCloseable {
51         private final DOMDataBroker delegate;
52         private final AutoCloseable closeable;
53
54         ForwardingConcurrentDOMBroker(DOMDataBroker delegate, AutoCloseable closeable) {
55             this.delegate = delegate;
56             this.closeable = closeable;
57         }
58
59         @Override
60         protected DOMDataBroker delegate() {
61             return delegate;
62         }
63
64         @Override
65         public void close() throws Exception {
66             // We don't close the delegate as the life-cycle is controlled via blueprint.
67             closeable.close();
68         }
69     }
70 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.