Merge "Fixed bug when Binding-Aware Data Change Listeners we're not triggered."
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / NetconfDeviceListener.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.connect.netconf;
9
10 import org.opendaylight.controller.netconf.api.NetconfMessage;
11 import org.opendaylight.controller.netconf.client.AbstractNetconfClientNotifySessionListener;
12 import org.opendaylight.controller.netconf.client.NetconfClientSession;
13 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
14 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
15
16 import com.google.common.base.Preconditions;
17
18 class NetconfDeviceListener extends AbstractNetconfClientNotifySessionListener {
19     private final NetconfDevice device;
20
21     public NetconfDeviceListener(final NetconfDevice device) {
22         this.device = Preconditions.checkNotNull(device);
23     }
24
25     /**
26      * Method intended to customize notification processing.
27      * 
28      * @param session
29      *            {@see
30      *            NetconfClientSessionListener#onMessage(NetconfClientSession,
31      *            NetconfMessage)}
32      * @param message
33      *            {@see
34      *            NetconfClientSessionListener#onMessage(NetconfClientSession,
35      *            NetconfMessage)}
36      */
37     @Override
38     public void onNotification(final NetconfClientSession session, final NetconfMessage message) {
39         this.device.logger.debug("Received NETCONF notification.", message);
40         CompositeNode domNotification = null;
41         if (message != null) {
42             domNotification = NetconfMapping.toNotificationNode(message, device.getSchemaContext());
43         }
44         if (domNotification != null) {
45             MountProvisionInstance _mountInstance = null;
46             if (this.device != null) {
47                 _mountInstance = this.device.getMountInstance();
48             }
49             if (_mountInstance != null) {
50                 _mountInstance.publish(domNotification);
51             }
52         }
53     }
54 }