From d41e14ac3f1db5312f38bed7b5469973cd27030c Mon Sep 17 00:00:00 2001 From: Robert Gallas Date: Tue, 12 Nov 2013 12:07:18 +0100 Subject: [PATCH] Enabling notification from netconf client Extending NetconfClientSessionListener to enable notifications Change-Id: I6190afef686cb51aea9961fbd5cb43ebf1669a0d Signed-off-by: Robert Gallas --- ...actNetconfClientNotifySessionListener.java | 54 +++++++++++++++++++ .../netconf/util/xml/XmlNetconfConstants.java | 2 + 2 files changed, 56 insertions(+) create mode 100644 opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java new file mode 100644 index 0000000000..48109d1353 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.client; + +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; + +/** + * Class extending {@link NetconfClientSessionListener} to provide notification capability. + */ +public abstract class AbstractNetconfClientNotifySessionListener extends NetconfClientSessionListener { + /* + * Maybe some capabilities could be expressed as internal NetconfClientSessionListener handlers. + * It would enable NetconfClient functionality to be extended by using namespace handlers. + * So far let just enable notification capability by extending and let parent class intact. + */ + + /** + * As class purpose is to provide notification capability to session listener + * onMessage method is not allowed to be further overridden. + * {@see #onNotification(NetconfClientSession, NetconfMessage)} + * + * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} + * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} + */ + @Override + public final synchronized void onMessage(NetconfClientSession session, NetconfMessage message) { + if (isNotification(message)) { + onNotification(session, message); + } else { + super.onMessage(session, message); + } + } + + /** + * Method intended to customize notification processing. + * + * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} + * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} + */ + public abstract void onNotification(NetconfClientSession session, NetconfMessage message); + + private boolean isNotification(NetconfMessage message) { + XmlElement xmle = XmlElement.fromDomDocument(message.getDocument()); + return XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME.equals(xmle.getName()) ; + } +} diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlNetconfConstants.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlNetconfConstants.java index 3e862faa7b..2a900e052b 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlNetconfConstants.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlNetconfConstants.java @@ -31,6 +31,8 @@ public class XmlNetconfConstants { public static final String RPC_REPLY_KEY = "rpc-reply"; public static final String RPC_ERROR = "rpc-error"; public static final String NAME_KEY = "name"; + public static final String NOTIFICATION_ELEMENT_NAME = "notification"; + // // public static final String RFC4741_TARGET_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0"; -- 2.36.6