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.mount.MountProviderInstance;
26 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
27 import org.opendaylight.yangtools.concepts.ListenerRegistration;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.Notification;
30 import org.opendaylight.yangtools.yang.binding.RpcService;
33 public class HydrogenMountInstanceAdapter implements MountProviderInstance {
35 private final ClassToInstanceMap<BindingAwareService> services;
36 private final InstanceIdentifier<?> identifier;
39 public HydrogenMountInstanceAdapter(final MountPoint key) {
40 this.identifier = key.getIdentifier();
41 final ImmutableClassToInstanceMap.Builder<BindingAwareService> builder = ImmutableClassToInstanceMap.builder();
43 final Optional<org.opendaylight.controller.md.sal.binding.api.NotificationService> notificationService = key.getService(org.opendaylight.controller.md.sal.binding.api.NotificationService.class);
44 if(notificationService.isPresent()) {
45 builder.put(NotificationService.class, new HeliumNotificationServiceAdapter(notificationService.get()));
47 final Optional<RpcConsumerRegistry> rpcRegistry = key.getService(RpcConsumerRegistry.class);
48 if(rpcRegistry.isPresent()) {
49 builder.put(RpcConsumerRegistry.class, rpcRegistry.get());
51 services = builder.build();
55 private <T extends BindingAwareService> T service(final Class<T> service) {
56 final T potential = services.getInstance(service);
57 Preconditions.checkState(potential != null, "Service %s is not supported by mount point %s",service,this.getIdentifier());
62 public <T extends RpcService> T getRpcService(final Class<T> serviceInterface) {
63 return service(RpcConsumerRegistry.class).getRpcService(serviceInterface);
67 public InstanceIdentifier<?> getIdentifier() {
72 public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
73 final Class<T> notificationType, final NotificationListener<T> listener) {
74 return service(NotificationService.class).registerNotificationListener(notificationType, listener);
78 public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
79 final org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
80 return service(NotificationService.class).registerNotificationListener(listener);
84 public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(final Class<T> serviceInterface,
85 final T implementation) throws IllegalStateException {
86 return service(RpcProviderRegistry.class).addRoutedRpcImplementation(serviceInterface, implementation);
90 public <T extends RpcService> RpcRegistration<T> addRpcImplementation(final Class<T> serviceInterface, final T implementation)
91 throws IllegalStateException {
92 return service(RpcProviderRegistry.class).addRpcImplementation(serviceInterface, implementation);
96 public void publish(final Notification notification) {
97 service(NotificationProviderService.class).publish(notification);
101 public void publish(final Notification notification, final ExecutorService executor) {
102 service(NotificationProviderService.class).publish(notification);
106 public ListenerRegistration<NotificationInterestListener> registerInterestListener(
107 final NotificationInterestListener interestListener) {
108 return service(NotificationProviderService.class).registerInterestListener(interestListener);
112 public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
114 return service(RpcProviderRegistry.class).registerRouteChangeListener(arg0);