1 package org.opendaylight.controller.sal.binding.impl;
3 import static com.google.common.base.Preconditions.checkState;
5 import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
6 import org.opendaylight.controller.md.sal.binding.util.BindingContextUtils;
7 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
8 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
9 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
10 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
12 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
13 import org.opendaylight.controller.sal.binding.api.NotificationService;
14 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
15 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
16 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
17 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
18 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
19 import org.opendaylight.controller.sal.binding.api.mount.MountService;
20 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
21 import org.opendaylight.yangtools.concepts.Identifiable;
22 import org.opendaylight.yangtools.concepts.ListenerRegistration;
23 import org.opendaylight.yangtools.concepts.Mutable;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.binding.RpcService;
26 import org.osgi.framework.BundleContext;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import com.google.common.collect.ImmutableClassToInstanceMap;
32 public class RootBindingAwareBroker implements //
34 Identifiable<String>, //
35 BindingAwareBroker, AutoCloseable,
38 private final static Logger LOG = LoggerFactory.getLogger(RootBindingAwareBroker.class);
40 RootSalInstance controllerRoot;
42 private final String identifier;
44 private RpcProviderRegistry rpcBroker;
46 private NotificationProviderService notificationBroker;
48 private DataProviderService dataBroker;
50 private MountPointManagerImpl mountManager;
52 public MountPointManagerImpl getMountManager() {
56 public void setMountManager(MountPointManagerImpl mountManager) {
57 this.mountManager = mountManager;
60 private ImmutableClassToInstanceMap<BindingAwareService> supportedConsumerServices;
62 private ImmutableClassToInstanceMap<BindingAwareService> supportedProviderServices;
64 public RootBindingAwareBroker(String instanceName) {
65 this.identifier = instanceName;
66 mountManager = new MountPointManagerImpl();
69 public String getIdentifier() {
73 public RootSalInstance getRoot() {
74 return controllerRoot;
77 public DataProviderService getDataBroker() {
78 return this.dataBroker;
81 public NotificationProviderService getNotificationBroker() {
82 return this.notificationBroker;
85 public RpcProviderRegistry getRpcProviderRegistry() {
86 return this.rpcBroker;
89 public RpcProviderRegistry getRpcBroker() {
93 public void setRpcBroker(RpcProviderRegistry rpcBroker) {
94 this.rpcBroker = rpcBroker;
97 public void setNotificationBroker(NotificationProviderService notificationBroker) {
98 this.notificationBroker = notificationBroker;
101 public void setDataBroker(DataProviderService dataBroker) {
102 this.dataBroker = dataBroker;
105 public void start() {
106 checkState(controllerRoot == null, "Binding Aware Broker was already started.");
107 LOG.info("Starting Binding Aware Broker: {}", identifier);
109 controllerRoot = new RootSalInstance(getRpcProviderRegistry(), getNotificationBroker(), getDataBroker());
112 supportedConsumerServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
113 .put(NotificationService.class, getRoot()) //
114 .put(DataBrokerService.class, getRoot()) //
115 .put(RpcConsumerRegistry.class, getRoot()) //
116 .put(MountService.class, mountManager).build();
118 supportedProviderServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
119 .putAll(supportedConsumerServices)
120 .put(NotificationProviderService.class, getRoot()) //
121 .put(DataProviderService.class, getRoot()) //
122 .put(RpcProviderRegistry.class, getRoot()) //
123 .put(MountProviderService.class, mountManager).build();
127 public ConsumerContext registerConsumer(BindingAwareConsumer consumer, BundleContext ctx) {
128 checkState(supportedConsumerServices != null, "Broker is not initialized.");
129 return BindingContextUtils.createConsumerContextAndInitialize(consumer, supportedConsumerServices);
133 public ProviderContext registerProvider(BindingAwareProvider provider, BundleContext ctx) {
134 checkState(supportedProviderServices != null, "Broker is not initialized.");
135 return BindingContextUtils.createProviderContextAndInitialize(provider, supportedProviderServices);
139 public void close() throws Exception {
140 // FIXME: Close all sessions
144 public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> type, T implementation)
145 throws IllegalStateException {
146 return getRoot().addRoutedRpcImplementation(type, implementation);
150 public <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> type, T implementation)
151 throws IllegalStateException {
152 return getRoot().addRpcImplementation(type, implementation);
156 public <T extends RpcService> T getRpcService(Class<T> module) {
157 return getRoot().getRpcService(module);
160 public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
162 return getRoot().registerRouteChangeListener(arg0);
166 public class RootSalInstance extends
167 AbstractBindingSalProviderInstance<DataProviderService, NotificationProviderService, RpcProviderRegistry> {
169 public RootSalInstance(RpcProviderRegistry rpcRegistry, NotificationProviderService notificationBroker,
170 DataProviderService dataBroker) {
171 super(rpcRegistry, notificationBroker, dataBroker);