2 * Copyright (c) 2013 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.restconf.broker.impl;
10 import java.util.ArrayList;
11 import java.util.List;
14 import org.opendaylight.controller.sal.binding.api.NotificationListener;
15 import org.opendaylight.controller.sal.binding.api.NotificationService;
16 import org.opendaylight.controller.sal.restconf.broker.listeners.RemoteNotificationListener;
17 import org.opendaylight.controller.sal.restconf.broker.tools.RemoteStreamTools;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.QName;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.SalRemoteService;
20 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
23 import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo;
24 import org.opendaylight.yangtools.yang.binding.Notification;
26 public class NotificationServiceImpl implements NotificationService {
27 private final SalRemoteService salRemoteService;
28 private final RestconfClientContext restconfClientContext;
30 public NotificationServiceImpl(RestconfClientContext restconfClienetContext){
31 this.restconfClientContext = restconfClienetContext;
32 this.salRemoteService = this.restconfClientContext.getRpcServiceContext(SalRemoteService.class).getRpcService();
36 public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(Class<T> notificationType, NotificationListener<T> listener) {
37 //TODO implementation using sal-remote
38 List<QName> notifications = new ArrayList<QName>();
39 notifications.add(new QName(notificationType.toString()));
40 String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, notifications);
41 final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName);
42 RemoteNotificationListener<T> remoteNotificationListener = new RemoteNotificationListener<T>(listener);
44 final ListenerRegistration<?> listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName)))
45 .registerNotificationListener(remoteNotificationListener);
47 return new AbstractListenerRegistration<NotificationListener<T>>(listener) {
49 protected void removeRegistration() {
50 listenerRegistration.close();
56 public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
57 //TODO implementation using sal-remote
58 String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, null);
59 final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName);
60 return restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(listener);