Refactor Additional header for netconf hello message.
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / NetconfServerSessionNegotiatorFactory.java
index 3c14d5124f395f54182ce125e1a9bed4ccf03d93..e052f61cc97dd7dce5a1e048f8f7f9938667df09 100644 (file)
@@ -12,11 +12,11 @@ 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.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;
@@ -31,7 +31,7 @@ import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpression;
 import java.io.InputStream;
 
-public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory {
+public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfHelloMessage, NetconfServerSession, NetconfServerSessionListener> {
 
     public static final String SERVER_HELLO_XML_LOCATION = "/server_hello.xml";
 
@@ -40,12 +40,14 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
     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() {
@@ -57,14 +59,14 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
     }
 
     @Override
-    public SessionNegotiator getSessionNegotiator(SessionListenerFactory sessionListenerFactory, Channel channel,
-            Promise promise) {
+    public SessionNegotiator<NetconfServerSession> getSessionNegotiator(SessionListenerFactory<NetconfServerSessionListener> sessionListenerFactory, Channel channel,
+            Promise<NetconfServerSession> 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
@@ -72,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
@@ -91,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);
     }
 }