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
9 package org.opendaylight.controller.sal.connect.netconf.sal;
11 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath;
13 import com.google.common.collect.HashMultimap;
14 import com.google.common.collect.Lists;
15 import com.google.common.collect.Multimap;
16 import java.util.Collection;
17 import javax.annotation.Nonnull;
18 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
19 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
20 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25 class NetconfDeviceNotificationService implements DOMNotificationService {
27 private final Multimap<SchemaPath, DOMNotificationListener> listeners = HashMultimap.create();
29 // Notification publish is very simple and hijacks the thread of the caller
30 // TODO shouldnt we reuse the implementation for notification router from sal-broker-impl ?
31 public synchronized void publishNotification(final ContainerNode notification) {
32 final SchemaPath schemaPath = toPath(notification.getNodeType());
33 for (final DOMNotificationListener domNotificationListener : listeners.get(schemaPath)) {
34 domNotificationListener.onNotification(new DOMNotification() {
37 public SchemaPath getType() {
43 public ContainerNode getBody() {
51 public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(@Nonnull final T listener, @Nonnull final Collection<SchemaPath> types) {
52 for (final SchemaPath type : types) {
53 listeners.put(type, listener);
56 // FIXME this should invoke create-subscription rpc on the remote device for a given notification
58 return new ListenerRegistration<T>() {
61 for (final SchemaPath type : types) {
62 listeners.remove(type, listener);
67 public T getInstance() {
74 public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(@Nonnull final T listener, final SchemaPath... types) {
75 return registerNotificationListener(listener, Lists.newArrayList(types));