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.sal.binding.impl;
10 import static com.google.common.base.Preconditions.checkState;
12 import com.google.common.collect.ImmutableClassToInstanceMap;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
16 import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
17 import org.opendaylight.controller.md.sal.binding.util.BindingContextUtils;
18 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
23 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
24 import org.opendaylight.controller.sal.binding.api.NotificationService;
25 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
26 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
27 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
28 import org.opendaylight.yangtools.concepts.Identifiable;
29 import org.opendaylight.yangtools.concepts.ListenerRegistration;
30 import org.opendaylight.yangtools.concepts.Mutable;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.binding.RpcService;
33 import org.osgi.framework.BundleContext;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 @Deprecated(forRemoval = true)
38 public class RootBindingAwareBroker implements Mutable, Identifiable<String>, BindingAwareBroker, AutoCloseable,
41 private static final Logger LOG = LoggerFactory.getLogger(RootBindingAwareBroker.class);
43 RootSalInstance controllerRoot;
45 private final String identifier;
47 private RpcProviderRegistry rpcBroker;
49 private NotificationProviderService notificationBroker;
51 private NotificationPublishService notificationPublishService;
53 private DataBroker dataBroker;
55 private ImmutableClassToInstanceMap<BindingAwareService> supportedConsumerServices;
57 private ImmutableClassToInstanceMap<BindingAwareService> supportedProviderServices;
59 private MountPointService mountService;
61 public RootBindingAwareBroker(final String instanceName) {
62 this.identifier = instanceName;
66 public String getIdentifier() {
70 public RootSalInstance getRoot() {
71 return controllerRoot;
74 public NotificationProviderService getNotificationBroker() {
75 return this.notificationBroker;
78 public NotificationPublishService getNotificationPublishService() {
79 return this.notificationPublishService;
82 public RpcProviderRegistry getRpcProviderRegistry() {
83 return this.rpcBroker;
86 public RpcProviderRegistry getRpcBroker() {
90 public MountPointService getMountService() {
94 public void setDataBroker(final DataBroker asyncDataBroker) {
95 dataBroker = asyncDataBroker;
98 public void setMountService(final MountPointService mount) {
99 this.mountService = mount;
102 public void setRpcBroker(final RpcProviderRegistry rpcBroker) {
103 this.rpcBroker = rpcBroker;
106 public void setNotificationBroker(final NotificationProviderService notificationBroker) {
107 this.notificationBroker = notificationBroker;
110 public void setNotificationPublishService(final NotificationPublishService notificationPublishService) {
111 this.notificationPublishService = notificationPublishService;
114 public void start() {
115 checkState(controllerRoot == null, "Binding Aware Broker was already started.");
116 LOG.info("Starting Binding Aware Broker: {}", identifier);
118 controllerRoot = new RootSalInstance(getRpcProviderRegistry(), getNotificationBroker());
120 final ImmutableClassToInstanceMap.Builder<BindingAwareService> consBuilder = ImmutableClassToInstanceMap
123 consBuilder.put(NotificationService.class, getRoot());
124 consBuilder.put(RpcConsumerRegistry.class, getRoot());
125 if (dataBroker != null) {
126 consBuilder.put(DataBroker.class, dataBroker);
128 consBuilder.put(MountPointService.class, mountService);
130 supportedConsumerServices = consBuilder.build();
131 final ImmutableClassToInstanceMap.Builder<BindingAwareService> provBuilder = ImmutableClassToInstanceMap
133 provBuilder.putAll(supportedConsumerServices).put(NotificationProviderService.class, getRoot())
134 .put(RpcProviderRegistry.class, getRoot());
135 if (notificationPublishService != null) {
136 provBuilder.put(NotificationPublishService.class, notificationPublishService);
139 supportedProviderServices = provBuilder.build();
143 public ConsumerContext registerConsumer(final BindingAwareConsumer consumer, final BundleContext ctx) {
144 return registerConsumer(consumer);
148 public ConsumerContext registerConsumer(final BindingAwareConsumer consumer) {
149 checkState(supportedConsumerServices != null, "Broker is not initialized.");
150 return BindingContextUtils.createConsumerContextAndInitialize(consumer, supportedConsumerServices);
154 public ProviderContext registerProvider(final BindingAwareProvider provider, final BundleContext ctx) {
155 return registerProvider(provider);
159 public ProviderContext registerProvider(final BindingAwareProvider provider) {
160 checkState(supportedProviderServices != null, "Broker is not initialized.");
161 return BindingContextUtils.createProviderContextAndInitialize(provider, supportedProviderServices);
165 public void close() {
166 // FIXME: Close all sessions
170 public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(final Class<T> type,
171 final T implementation) throws IllegalStateException {
172 return getRoot().addRoutedRpcImplementation(type, implementation);
176 public <T extends RpcService> RpcRegistration<T> addRpcImplementation(final Class<T> type, final T implementation)
177 throws IllegalStateException {
178 return getRoot().addRpcImplementation(type, implementation);
182 public <T extends RpcService> T getRpcService(final Class<T> module) {
183 return getRoot().getRpcService(module);
187 public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L>
188 registerRouteChangeListener(final L listener) {
189 return getRoot().registerRouteChangeListener(listener);
192 public static class RootSalInstance extends
193 AbstractBindingSalProviderInstance<NotificationProviderService, RpcProviderRegistry> {
195 public RootSalInstance(final RpcProviderRegistry rpcRegistry,
196 final NotificationProviderService notificationBroker) {
197 super(rpcRegistry, notificationBroker);