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.MountPoint;
16 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
20 import org.opendaylight.controller.sal.binding.api.NotificationListener;
21 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
22 import org.opendaylight.controller.sal.binding.api.NotificationService;
23 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
24 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
25 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
26 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
27 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
28 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
29 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
30 import org.opendaylight.yangtools.concepts.ListenerRegistration;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.binding.Notification;
34 import org.opendaylight.yangtools.yang.binding.RpcService;
37 public class HydrogenMountInstanceAdapter implements MountProviderInstance {
39 private final ClassToInstanceMap<BindingAwareService> services;
40 private final InstanceIdentifier<?> identifier;
43 public HydrogenMountInstanceAdapter(final MountPoint key) {
44 this.identifier = key.getIdentifier();
45 final ImmutableClassToInstanceMap.Builder<BindingAwareService> builder = ImmutableClassToInstanceMap.builder();
47 final Optional<org.opendaylight.controller.md.sal.binding.api.NotificationService> notificationService = key.getService(org.opendaylight.controller.md.sal.binding.api.NotificationService.class);
48 if(notificationService.isPresent()) {
49 builder.put(NotificationService.class, new HeliumNotificationServiceAdapter(notificationService.get()));
51 final Optional<RpcConsumerRegistry> rpcRegistry = key.getService(RpcConsumerRegistry.class);
52 if(rpcRegistry.isPresent()) {
53 builder.put(RpcConsumerRegistry.class, rpcRegistry.get());
55 services = builder.build();
59 private <T extends BindingAwareService> T service(final Class<T> service) {
60 final T potential = services.getInstance(service);
61 Preconditions.checkState(potential != null, "Service %s is not supported by mount point %s",service,this.getIdentifier());
66 public <T extends RpcService> T getRpcService(final Class<T> serviceInterface) {
67 return service(RpcConsumerRegistry.class).getRpcService(serviceInterface);
71 public InstanceIdentifier<?> getIdentifier() {
76 public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
77 final Class<T> notificationType, final NotificationListener<T> listener) {
78 return service(NotificationService.class).registerNotificationListener(notificationType, listener);
82 public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
83 final org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
84 return service(NotificationService.class).registerNotificationListener(listener);
88 public DataModificationTransaction beginTransaction() {
89 return service(DataBrokerService.class).beginTransaction();
93 public DataObject readConfigurationData(final InstanceIdentifier<? extends DataObject> path) {
94 return service(DataBrokerService.class).readConfigurationData(path);
98 public DataObject readOperationalData(final InstanceIdentifier<? extends DataObject> path) {
99 return service(DataBrokerService.class).readOperationalData(path);
103 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
104 final InstanceIdentifier<? extends DataObject> path, final DataChangeListener listener) {
105 return service(DataBrokerService.class).registerDataChangeListener(path,listener);
109 public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(final Class<T> serviceInterface,
110 final T implementation) throws IllegalStateException {
111 return service(RpcProviderRegistry.class).addRoutedRpcImplementation(serviceInterface, implementation);
115 public <T extends RpcService> RpcRegistration<T> addRpcImplementation(final Class<T> serviceInterface, final T implementation)
116 throws IllegalStateException {
117 return service(RpcProviderRegistry.class).addRpcImplementation(serviceInterface, implementation);
121 public void publish(final Notification notification) {
122 service(NotificationProviderService.class).publish(notification);
126 public void publish(final Notification notification, final ExecutorService executor) {
127 service(NotificationProviderService.class).publish(notification);
131 public ListenerRegistration<NotificationInterestListener> registerInterestListener(
132 final NotificationInterestListener interestListener) {
133 return service(NotificationProviderService.class).registerInterestListener(interestListener);
137 public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
139 return service(RpcProviderRegistry.class).registerRouteChangeListener(arg0);