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 org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
13 import org.opendaylight.controller.md.sal.binding.util.BindingContextUtils;
14 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
19 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
20 import org.opendaylight.controller.sal.binding.api.NotificationService;
21 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
22 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
23 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
24 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
25 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
26 import org.opendaylight.controller.sal.binding.api.mount.MountService;
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 import com.google.common.collect.ImmutableClassToInstanceMap;
39 public class RootBindingAwareBroker implements //
41 Identifiable<String>, //
42 BindingAwareBroker, AutoCloseable,
45 private final static Logger LOG = LoggerFactory.getLogger(RootBindingAwareBroker.class);
47 RootSalInstance controllerRoot;
49 private final String identifier;
51 private RpcProviderRegistry rpcBroker;
53 private NotificationProviderService notificationBroker;
55 private DataProviderService dataBroker;
57 private MountPointManagerImpl mountManager;
59 public MountPointManagerImpl getMountManager() {
63 public void setMountManager(MountPointManagerImpl mountManager) {
64 this.mountManager = mountManager;
67 private ImmutableClassToInstanceMap<BindingAwareService> supportedConsumerServices;
69 private ImmutableClassToInstanceMap<BindingAwareService> supportedProviderServices;
71 public RootBindingAwareBroker(String instanceName) {
72 this.identifier = instanceName;
73 mountManager = new MountPointManagerImpl();
76 public String getIdentifier() {
80 public RootSalInstance getRoot() {
81 return controllerRoot;
84 public DataProviderService getDataBroker() {
85 return this.dataBroker;
88 public NotificationProviderService getNotificationBroker() {
89 return this.notificationBroker;
92 public RpcProviderRegistry getRpcProviderRegistry() {
93 return this.rpcBroker;
96 public RpcProviderRegistry getRpcBroker() {
100 public void setRpcBroker(RpcProviderRegistry rpcBroker) {
101 this.rpcBroker = rpcBroker;
104 public void setNotificationBroker(NotificationProviderService notificationBroker) {
105 this.notificationBroker = notificationBroker;
108 public void setDataBroker(DataProviderService dataBroker) {
109 this.dataBroker = dataBroker;
112 public void start() {
113 checkState(controllerRoot == null, "Binding Aware Broker was already started.");
114 LOG.info("Starting Binding Aware Broker: {}", identifier);
116 controllerRoot = new RootSalInstance(getRpcProviderRegistry(), getNotificationBroker(), getDataBroker());
119 supportedConsumerServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
120 .put(NotificationService.class, getRoot()) //
121 .put(DataBrokerService.class, getRoot()) //
122 .put(RpcConsumerRegistry.class, getRoot()) //
123 .put(MountService.class, mountManager).build();
125 supportedProviderServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
126 .putAll(supportedConsumerServices)
127 .put(NotificationProviderService.class, getRoot()) //
128 .put(DataProviderService.class, getRoot()) //
129 .put(RpcProviderRegistry.class, getRoot()) //
130 .put(MountProviderService.class, mountManager).build();
134 public ConsumerContext registerConsumer(BindingAwareConsumer consumer, BundleContext ctx) {
135 checkState(supportedConsumerServices != null, "Broker is not initialized.");
136 return BindingContextUtils.createConsumerContextAndInitialize(consumer, supportedConsumerServices);
140 public ProviderContext registerProvider(BindingAwareProvider provider, BundleContext ctx) {
141 checkState(supportedProviderServices != null, "Broker is not initialized.");
142 return BindingContextUtils.createProviderContextAndInitialize(provider, supportedProviderServices);
146 public void close() throws Exception {
147 // FIXME: Close all sessions
151 public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> type, T implementation)
152 throws IllegalStateException {
153 return getRoot().addRoutedRpcImplementation(type, implementation);
157 public <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> type, T implementation)
158 throws IllegalStateException {
159 return getRoot().addRpcImplementation(type, implementation);
163 public <T extends RpcService> T getRpcService(Class<T> module) {
164 return getRoot().getRpcService(module);
167 public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
169 return getRoot().registerRouteChangeListener(arg0);
173 public class RootSalInstance extends
174 AbstractBindingSalProviderInstance<DataProviderService, NotificationProviderService, RpcProviderRegistry> {
176 public RootSalInstance(RpcProviderRegistry rpcRegistry, NotificationProviderService notificationBroker,
177 DataProviderService dataBroker) {
178 super(rpcRegistry, notificationBroker, dataBroker);