X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfClientSessionNegotiator.java;h=cbbee1f65508353b117bbd21db22b523b4244694;hp=971ea39ade5b6fb57d07a041f999ec18890528df;hb=d313c1a52799705222817dfcaeb2b6ab2a6f9146;hpb=8a60e7caa7a442c67e69ff9a42c438f80e41f107 diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java index 971ea39ade..cbbee1f655 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java @@ -8,6 +8,9 @@ package org.opendaylight.controller.netconf.client; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -48,17 +51,17 @@ public class NetconfClientSessionNegotiator extends private static final String EXI_1_0_CAPABILITY_MARKER = "exi:1.0"; - protected NetconfClientSessionNegotiator(NetconfClientSessionPreferences sessionPreferences, - Promise promise, - Channel channel, - Timer timer, - NetconfClientSessionListener sessionListener, - long connectionTimeoutMillis) { + protected NetconfClientSessionNegotiator(final NetconfClientSessionPreferences sessionPreferences, + final Promise promise, + final Channel channel, + final Timer timer, + final NetconfClientSessionListener sessionListener, + final long connectionTimeoutMillis) { super(sessionPreferences, promise, channel, timer, sessionListener, connectionTimeoutMillis); } @Override - protected void handleMessage(NetconfHelloMessage netconfMessage) throws NetconfDocumentedException { + protected void handleMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException { final NetconfClientSession session = getSessionForHelloMessage(netconfMessage); replaceHelloMessageInboundHandler(session); @@ -68,8 +71,8 @@ public class NetconfClientSessionNegotiator extends logger.debug("Netconf session {} should use exi.", session); NetconfStartExiMessage startExiMessage = (NetconfStartExiMessage) sessionPreferences.getStartExiMessage(); tryToInitiateExi(session, startExiMessage); - // Exi is not supported, release session immediately } else { + // Exi is not supported, release session immediately logger.debug("Netconf session {} isn't capable of using exi.", session); negotiationSuccessful(session); } @@ -98,7 +101,7 @@ public class NetconfClientSessionNegotiator extends }); } - private boolean shouldUseExi(NetconfHelloMessage helloMsg) { + private boolean shouldUseExi(final NetconfHelloMessage helloMsg) { return containsExi10Capability(helloMsg.getDocument()) && containsExi10Capability(sessionPreferences.getHelloMessage().getDocument()); } @@ -113,8 +116,9 @@ public class NetconfClientSessionNegotiator extends return false; } - private long extractSessionId(Document doc) { + private long extractSessionId(final Document doc) { final Node sessionIdNode = (Node) XmlUtil.evaluateXPath(sessionIdXPath, doc, XPathConstants.NODE); + Preconditions.checkState(sessionIdNode != null, ""); String textContent = sessionIdNode.getTextContent(); if (textContent == null || textContent.equals("")) { throw new IllegalStateException("Session id not received from server"); @@ -124,10 +128,14 @@ public class NetconfClientSessionNegotiator extends } @Override - protected NetconfClientSession getSession(NetconfClientSessionListener sessionListener, Channel channel, - NetconfHelloMessage message) throws NetconfDocumentedException { + protected NetconfClientSession getSession(final NetconfClientSessionListener sessionListener, final Channel channel, + final NetconfHelloMessage message) throws NetconfDocumentedException { long sessionId = extractSessionId(message.getDocument()); - Collection capabilities = NetconfMessageUtil.extractCapabilitiesFromHello(message.getDocument()); + + // Copy here is important: it disconnects the strings from the document + Collection capabilities = ImmutableList.copyOf(NetconfMessageUtil.extractCapabilitiesFromHello(message.getDocument())); + + // FIXME: scalability: we could instantiate a cache to share the same collections return new NetconfClientSession(sessionListener, channel, sessionId, capabilities); } @@ -138,15 +146,15 @@ public class NetconfClientSessionNegotiator extends private static final String EXI_CONFIRMED_HANDLER = "exiConfirmedHandler"; private final NetconfClientSession session; - private NetconfStartExiMessage startExiMessage; + private final NetconfStartExiMessage startExiMessage; - ExiConfirmationInboundHandler(NetconfClientSession session, final NetconfStartExiMessage startExiMessage) { + ExiConfirmationInboundHandler(final NetconfClientSession session, final NetconfStartExiMessage startExiMessage) { this.session = session; this.startExiMessage = startExiMessage; } @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { ctx.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER); NetconfMessage netconfMessage = (NetconfMessage) msg;