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.md.sal.dom.impl;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ClassToInstanceMap;
12 import com.google.common.collect.MutableClassToInstanceMap;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.controller.config.api.DependencyResolver;
16 import org.opendaylight.controller.config.api.ModuleIdentifier;
17 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
19 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
20 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
21 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
22 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
23 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
24 import org.opendaylight.controller.sal.core.api.BrokerService;
25 import org.opendaylight.controller.sal.core.api.model.SchemaService;
26 import org.opendaylight.controller.sal.dom.broker.BrokerImpl;
27 import org.osgi.framework.BundleContext;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
34 * @deprecated Replaced by blueprint wiring
37 public final class DomBrokerImplModule extends AbstractDomBrokerImplModule {
38 private static final Logger LOG = LoggerFactory.getLogger(DomBrokerImplModule.class);
40 private BundleContext bundleContext;
42 public DomBrokerImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
43 super(identifier, dependencyResolver);
46 public DomBrokerImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
47 final DomBrokerImplModule oldModule, final AutoCloseable oldInstance) {
48 super(identifier, dependencyResolver, oldModule, oldInstance);
52 public void validate() {
54 final long depth = getNotificationQueueDepth().getValue();
55 Preconditions.checkArgument(Long.lowestOneBit(depth) == Long.highestOneBit(depth),
56 "Queue depth %s is not power-of-two", depth);
60 @SuppressWarnings("checkstyle:IllegalCatch")
61 public AutoCloseable createInstance() {
62 // The services are provided via blueprint so retrieve then from the OSGi service registry for
63 // backwards compatibility.
65 final List<AutoCloseable> closeables = new ArrayList<>();
66 DOMNotificationService domNotificationService = newTracker(
67 DOMNotificationService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
69 DOMNotificationPublishService domNotificationPublishService = newTracker(
70 DOMNotificationPublishService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
72 DOMRpcService domRpcService = newTracker(
73 DOMRpcService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
75 DOMRpcProviderService domRpcProvider = newTracker(
76 DOMRpcProviderService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);
78 DOMMountPointService mountService = newTracker(DOMMountPointService.class, closeables)
79 .waitForService(WaitingServiceTracker.FIVE_MINUTES);
81 SchemaService globalSchemaService = newTracker(SchemaService.class, closeables)
82 .waitForService(WaitingServiceTracker.FIVE_MINUTES);
84 final DOMDataBroker dataBroker = getAsyncDataBrokerDependency();
86 final ClassToInstanceMap<BrokerService> services = MutableClassToInstanceMap.create();
88 services.putInstance(DOMNotificationService.class, domNotificationService);
89 services.putInstance(DOMNotificationPublishService.class, domNotificationPublishService);
91 final SchemaService schemaService = getSchemaServiceImpl(globalSchemaService);
92 services.putInstance(SchemaService.class, schemaService);
94 services.putInstance(DOMDataBroker.class, dataBroker);
96 services.putInstance(DOMRpcService.class, domRpcService);
97 services.putInstance(DOMRpcProviderService.class, domRpcProvider);
99 services.putInstance(DOMMountPointService.class, mountService);
101 BrokerImpl broker = new BrokerImpl(domRpcService, domRpcProvider, services);
102 broker.setDeactivator(() -> {
103 for (AutoCloseable ac : closeables) {
106 } catch (Exception e) {
107 LOG.warn("Exception while closing {}", ac, e);
115 private <T> WaitingServiceTracker<T> newTracker(Class<T> serviceInterface, List<AutoCloseable> closeables) {
116 WaitingServiceTracker<T> tracker = WaitingServiceTracker.create(serviceInterface, bundleContext);
117 closeables.add(tracker);
121 private SchemaService getSchemaServiceImpl(SchemaService globalSchemaService) {
122 final SchemaService schemaService;
123 if (getRootSchemaService() != null) {
124 schemaService = getRootSchemaServiceDependency();
126 schemaService = globalSchemaService;
128 return schemaService;
131 public void setBundleContext(final BundleContext bundleContext) {
132 this.bundleContext = bundleContext;