X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfDeviceListener.java;h=13cd5dbcf03a185ce99a5631684696bf74ef3ab5;hp=69fe4aa1904e57ac83512400eaf6a3688a8da3ea;hb=f08d2774c06e55e377191b027ec9131921977e70;hpb=6fd408a04fe4a3611843e2246ece6d7c34b76903 diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java index 69fe4aa190..13cd5dbcf0 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java @@ -7,61 +7,19 @@ */ package org.opendaylight.controller.sal.connect.netconf; -import com.google.common.base.Objects; - -import io.netty.util.concurrent.EventExecutor; -import io.netty.util.concurrent.Promise; - -import java.util.List; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.locks.ReentrantLock; - -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Functions.Function0; import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.client.AbstractNetconfClientNotifySessionListener; import org.opendaylight.controller.netconf.client.NetconfClientSession; -import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; -import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; -import org.opendaylight.controller.sal.connect.netconf.NetconfDevice; -import org.opendaylight.controller.sal.connect.netconf.NetconfMapping; import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.w3c.dom.Document; - -@SuppressWarnings("all") -class NetconfDeviceListener extends NetconfClientSessionListener { - private final NetconfDevice device; - private final EventExecutor eventExecutor; - - public NetconfDeviceListener(final NetconfDevice device, final EventExecutor eventExecutor) { - this.device = device; - this.eventExecutor = eventExecutor; - } - private Promise messagePromise; - private ConcurrentMap> promisedMessages; +import com.google.common.base.Preconditions; - private final ReentrantLock promiseLock = new ReentrantLock(); +class NetconfDeviceListener extends AbstractNetconfClientNotifySessionListener { + private final NetconfDevice device; - public void onMessage(final NetconfClientSession session, final NetconfMessage message) { - if (isNotification(message)) { - this.onNotification(session, message); - } else { - try { - this.promiseLock.lock(); - boolean _notEquals = (!Objects.equal(this.messagePromise, null)); - if (_notEquals) { - this.device.logger.debug("Setting promised reply {} with message {}", this.messagePromise, message); - this.messagePromise.setSuccess(message); - this.messagePromise = null; - } - } finally { - this.promiseLock.unlock(); - } - } + public NetconfDeviceListener(final NetconfDevice device) { + this.device = Preconditions.checkNotNull(device); } /** @@ -76,6 +34,7 @@ class NetconfDeviceListener extends NetconfClientSessionListener { * NetconfClientSessionListener#onMessage(NetconfClientSession, * NetconfMessage)} */ + @Override public void onNotification(final NetconfClientSession session, final NetconfMessage message) { this.device.logger.debug("Received NETCONF notification.", message); CompositeNode domNotification = null; @@ -92,65 +51,4 @@ class NetconfDeviceListener extends NetconfClientSessionListener { } } } - - private static CompositeNode getNotificationBody(final CompositeNode node) { - List> _children = node.getChildren(); - for (final Node child : _children) { - if ((child instanceof CompositeNode)) { - return ((CompositeNode) child); - } - } - return null; - } - - public NetconfMessage getLastMessage(final int attempts, final int attemptMsDelay) throws InterruptedException { - final Promise promise = this.promiseReply(); - this.device.logger.debug("Waiting for reply {}", promise); - int _plus = (attempts * attemptMsDelay); - final boolean messageAvailable = promise.await(_plus); - if (messageAvailable) { - try { - try { - return promise.get(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } catch (final Throwable _t) { - if (_t instanceof ExecutionException) { - final ExecutionException e = (ExecutionException) _t; - IllegalStateException _illegalStateException = new IllegalStateException(e); - throw _illegalStateException; - } else { - throw Exceptions.sneakyThrow(_t); - } - } - } - String _plus_1 = ("Unsuccessful after " + Integer.valueOf(attempts)); - String _plus_2 = (_plus_1 + " attempts."); - IllegalStateException _illegalStateException_1 = new IllegalStateException(_plus_2); - throw _illegalStateException_1; - } - - public synchronized Promise promiseReply() { - this.device.logger.debug("Promising reply."); - this.promiseLock.lock(); - try { - boolean _equals = Objects.equal(this.messagePromise, null); - if (_equals) { - Promise _newPromise = this.eventExecutor. newPromise(); - this.messagePromise = _newPromise; - return this.messagePromise; - } - return this.messagePromise; - } finally { - this.promiseLock.unlock(); - } - } - - public boolean isNotification(final NetconfMessage message) { - Document _document = message.getDocument(); - final XmlElement xmle = XmlElement.fromDomDocument(_document); - String _name = xmle.getName(); - return XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME.equals(_name); - } }