X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2FNetconfServerSessionNegotiatorFactory.java;h=e052f61cc97dd7dce5a1e048f8f7f9938667df09;hb=9070e358923aca6229137d46f9cae7ff458204dd;hp=e74723032d247888c65b22c1eed7d9b62a543d71;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java index e74723032d..e052f61cc9 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java @@ -8,14 +8,15 @@ package org.opendaylight.controller.netconf.impl; +import com.google.common.base.Preconditions; import io.netty.channel.Channel; import io.netty.util.Timer; import io.netty.util.concurrent.Promise; -import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences; import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener; -import org.opendaylight.controller.netconf.impl.util.NetconfUtil; +import org.opendaylight.controller.netconf.util.NetconfUtil; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil; import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; @@ -28,36 +29,44 @@ import org.w3c.dom.Node; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; +import java.io.InputStream; -public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory { +public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory { + + public static final String SERVER_HELLO_XML_LOCATION = "/server_hello.xml"; private final Timer timer; private static final Document helloMessageTemplate = loadHelloMessageTemplate(); private final SessionIdProvider idProvider; private final NetconfOperationServiceFactoryListener factoriesListener; + private final long connectionTimeoutMillis; public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationServiceFactoryListener factoriesListener, - SessionIdProvider idProvider) { + SessionIdProvider idProvider, long connectionTimeoutMillis) { this.timer = timer; this.factoriesListener = factoriesListener; this.idProvider = idProvider; + this.connectionTimeoutMillis = connectionTimeoutMillis; } private static Document loadHelloMessageTemplate() { - return NetconfUtil.createMessage( - NetconfServerSessionNegotiatorFactory.class.getResourceAsStream("/server_hello.xml")).getDocument(); + InputStream resourceAsStream = NetconfServerSessionNegotiatorFactory.class + .getResourceAsStream(SERVER_HELLO_XML_LOCATION); + Preconditions.checkNotNull(resourceAsStream, "Unable to load server hello message blueprint from %s", + SERVER_HELLO_XML_LOCATION); + return NetconfUtil.createMessage(resourceAsStream).getDocument(); } @Override - public SessionNegotiator getSessionNegotiator(SessionListenerFactory sessionListenerFactory, Channel channel, - Promise promise) { + public SessionNegotiator getSessionNegotiator(SessionListenerFactory sessionListenerFactory, Channel channel, + Promise promise) { long sessionId = idProvider.getNextSessionId(); NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences(createHelloMessage(sessionId), sessionId); return new NetconfServerSessionNegotiator(proposal, promise, channel, timer, - sessionListenerFactory.getSessionListener()); + sessionListenerFactory.getSessionListener(), connectionTimeoutMillis); } private static final XPathExpression sessionIdXPath = XMLNetconfUtil @@ -65,7 +74,7 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF private static final XPathExpression capabilitiesXPath = XMLNetconfUtil .compileXPath("/netconf:hello/netconf:capabilities"); - private NetconfMessage createHelloMessage(long sessionId) { + private NetconfHelloMessage createHelloMessage(long sessionId) { Document helloMessageTemplate = getHelloTemplateClone(); // change session ID @@ -84,10 +93,10 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF capabilityElement.setTextContent(capability); capabilitiesElement.appendChild(capabilityElement); } - return new NetconfMessage(helloMessageTemplate); + return new NetconfHelloMessage(helloMessageTemplate); } private synchronized Document getHelloTemplateClone() { - return (Document) this.helloMessageTemplate.cloneNode(true); + return (Document) helloMessageTemplate.cloneNode(true); } }