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 com.google.common.collect.ImmutableClassToInstanceMap;
11 import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
12 import org.opendaylight.controller.md.sal.binding.util.BindingContextUtils;
13 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
18 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
19 import org.opendaylight.controller.sal.binding.api.NotificationService;
20 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
21 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
22 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
23 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
24 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
25 import org.opendaylight.controller.sal.binding.api.mount.MountService;
26 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
27 import org.opendaylight.yangtools.concepts.Identifiable;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.concepts.Mutable;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.RpcService;
32 import org.osgi.framework.BundleContext;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import static com.google.common.base.Preconditions.checkState;
37 public class RootBindingAwareBroker implements //
39 Identifiable<String>, //
40 BindingAwareBroker, AutoCloseable,
43 private final static Logger LOG = LoggerFactory.getLogger(RootBindingAwareBroker.class);
45 RootSalInstance controllerRoot;
47 private final String identifier;
49 private RpcProviderRegistry rpcBroker;
51 private NotificationProviderService notificationBroker;
53 private DataProviderService dataBroker;
55 private MountPointManagerImpl mountManager;
57 public MountPointManagerImpl getMountManager() {
61 public void setMountManager(MountPointManagerImpl mountManager) {
62 this.mountManager = mountManager;
65 private ImmutableClassToInstanceMap<BindingAwareService> supportedConsumerServices;
67 private ImmutableClassToInstanceMap<BindingAwareService> supportedProviderServices;
69 public RootBindingAwareBroker(String instanceName) {
70 this.identifier = instanceName;
71 mountManager = new MountPointManagerImpl();
74 public String getIdentifier() {
78 public RootSalInstance getRoot() {
79 return controllerRoot;
82 public DataProviderService getDataBroker() {
83 return this.dataBroker;
86 public NotificationProviderService getNotificationBroker() {
87 return this.notificationBroker;
90 public RpcProviderRegistry getRpcProviderRegistry() {
91 return this.rpcBroker;
94 public RpcProviderRegistry getRpcBroker() {
98 public void setRpcBroker(RpcProviderRegistry rpcBroker) {
99 this.rpcBroker = rpcBroker;
102 public void setNotificationBroker(NotificationProviderService notificationBroker) {
103 this.notificationBroker = notificationBroker;
106 public void setDataBroker(DataProviderService dataBroker) {
107 this.dataBroker = dataBroker;
110 public void start() {
111 checkState(controllerRoot == null, "Binding Aware Broker was already started.");
112 LOG.info("Starting Binding Aware Broker: {}", identifier);
114 controllerRoot = new RootSalInstance(getRpcProviderRegistry(), getNotificationBroker(), getDataBroker());
117 supportedConsumerServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
118 .put(NotificationService.class, getRoot()) //
119 .put(DataBrokerService.class, getRoot()) //
120 .put(RpcConsumerRegistry.class, getRoot()) //
121 .put(MountService.class, mountManager).build();
123 supportedProviderServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
124 .putAll(supportedConsumerServices)
125 .put(NotificationProviderService.class, getRoot()) //
126 .put(DataProviderService.class, getRoot()) //
127 .put(RpcProviderRegistry.class, getRoot()) //
128 .put(MountProviderService.class, mountManager).build();
132 public ConsumerContext registerConsumer(BindingAwareConsumer consumer, BundleContext ctx) {
133 checkState(supportedConsumerServices != null, "Broker is not initialized.");
134 return BindingContextUtils.createConsumerContextAndInitialize(consumer, supportedConsumerServices);
138 public ProviderContext registerProvider(BindingAwareProvider provider, BundleContext ctx) {
139 checkState(supportedProviderServices != null, "Broker is not initialized.");
140 return BindingContextUtils.createProviderContextAndInitialize(provider, supportedProviderServices);
144 public void close() throws Exception {
145 // FIXME: Close all sessions
149 public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> type, T implementation)
150 throws IllegalStateException {
151 return getRoot().addRoutedRpcImplementation(type, implementation);
155 public <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> type, T implementation)
156 throws IllegalStateException {
157 return getRoot().addRpcImplementation(type, implementation);
161 public <T extends RpcService> T getRpcService(Class<T> module) {
162 return getRoot().getRpcService(module);
165 public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
167 return getRoot().registerRouteChangeListener(arg0);
171 public class RootSalInstance extends
172 AbstractBindingSalProviderInstance<DataProviderService, NotificationProviderService, RpcProviderRegistry> {
174 public RootSalInstance(RpcProviderRegistry rpcRegistry, NotificationProviderService notificationBroker,
175 DataProviderService dataBroker) {
176 super(rpcRegistry, notificationBroker, dataBroker);