2 * Copyright (c) 2015 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.md.sal.binding.compat;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ClassToInstanceMap;
13 import com.google.common.collect.ImmutableClassToInstanceMap;
14 import java.util.concurrent.ExecutorService;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
17 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
21 import org.opendaylight.controller.sal.binding.api.NotificationListener;
22 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
23 import org.opendaylight.controller.sal.binding.api.NotificationService;
24 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
25 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
26 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
27 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
28 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
29 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
30 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
31 import org.opendaylight.yangtools.concepts.ListenerRegistration;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.binding.Notification;
35 import org.opendaylight.yangtools.yang.binding.RpcService;
38 public class HydrogenMountInstanceAdapter implements MountProviderInstance {
40 private final ClassToInstanceMap<BindingAwareService> services;
41 private final InstanceIdentifier<?> identifier;
44 public HydrogenMountInstanceAdapter(final MountPoint key) {
45 this.identifier = key.getIdentifier();
46 final ImmutableClassToInstanceMap.Builder<BindingAwareService> builder = ImmutableClassToInstanceMap.builder();
48 final Optional<DataBroker> dataBroker = key.getService(DataBroker.class);
49 if(dataBroker.isPresent()) {
50 builder.put(DataBrokerService.class, new HydrogenDataBrokerAdapter(dataBroker.get()));
52 final Optional<org.opendaylight.controller.md.sal.binding.api.NotificationService> notificationService = key.getService(org.opendaylight.controller.md.sal.binding.api.NotificationService.class);
53 if(notificationService.isPresent()) {
54 builder.put(NotificationService.class, new HeliumNotificationServiceAdapter(notificationService.get()));
56 final Optional<RpcConsumerRegistry> rpcRegistry = key.getService(RpcConsumerRegistry.class);
57 if(rpcRegistry.isPresent()) {
58 builder.put(RpcConsumerRegistry.class, rpcRegistry.get());
60 services = builder.build();
64 private <T extends BindingAwareService> T service(final Class<T> service) {
65 final T potential = services.getInstance(service);
66 Preconditions.checkState(potential != null, "Service %s is not supported by mount point %s",service,this.getIdentifier());
71 public <T extends RpcService> T getRpcService(final Class<T> serviceInterface) {
72 return service(RpcConsumerRegistry.class).getRpcService(serviceInterface);
76 public InstanceIdentifier<?> getIdentifier() {
81 public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
82 final Class<T> notificationType, final NotificationListener<T> listener) {
83 return service(NotificationService.class).registerNotificationListener(notificationType, listener);
87 public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
88 final org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
89 return service(NotificationService.class).registerNotificationListener(listener);
93 public DataModificationTransaction beginTransaction() {
94 return service(DataBrokerService.class).beginTransaction();
98 public DataObject readConfigurationData(final InstanceIdentifier<? extends DataObject> path) {
99 return service(DataBrokerService.class).readConfigurationData(path);
103 public DataObject readOperationalData(final InstanceIdentifier<? extends DataObject> path) {
104 return service(DataBrokerService.class).readOperationalData(path);
108 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
109 final InstanceIdentifier<? extends DataObject> path, final DataChangeListener listener) {
110 return service(DataBrokerService.class).registerDataChangeListener(path,listener);
114 public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(final Class<T> serviceInterface,
115 final T implementation) throws IllegalStateException {
116 return service(RpcProviderRegistry.class).addRoutedRpcImplementation(serviceInterface, implementation);
120 public <T extends RpcService> RpcRegistration<T> addRpcImplementation(final Class<T> serviceInterface, final T implementation)
121 throws IllegalStateException {
122 return service(RpcProviderRegistry.class).addRpcImplementation(serviceInterface, implementation);
126 public void publish(final Notification notification) {
127 service(NotificationProviderService.class).publish(notification);
131 public void publish(final Notification notification, final ExecutorService executor) {
132 service(NotificationProviderService.class).publish(notification);
136 public ListenerRegistration<NotificationInterestListener> registerInterestListener(
137 final NotificationInterestListener interestListener) {
138 return service(NotificationProviderService.class).registerInterestListener(interestListener);
142 public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
144 return service(RpcProviderRegistry.class).registerRouteChangeListener(arg0);