BUG-459 Remove deprecated NetconfClient class.
[controller.git] / opendaylight / netconf / netconf-client / src / main / java / org / opendaylight / controller / netconf / client / NetconfClientSessionNegotiatorFactory.java
index abfbdd526c5f7bb6796c7c0273060e7b91aa8933..cff214401c0ff2ac8a24548adda3e44c8a4f186b 100644 (file)
@@ -17,6 +17,8 @@ import java.io.InputStream;
 
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfSessionPreferences;
+import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
+import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.opendaylight.protocol.framework.SessionNegotiator;
@@ -26,15 +28,16 @@ import org.xml.sax.SAXException;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
-public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory {
+public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfMessage, NetconfClientSession, NetconfClientSessionListener> {
 
+    private final Optional<NetconfHelloMessageAdditionalHeader> additionalHeader;
+    private final long connectionTimeoutMillis;
     private final Timer timer;
 
-    private final Optional<String> additionalHeader;
-
-    public NetconfClientSessionNegotiatorFactory(Timer timer, Optional<String> additionalHeader) {
-        this.timer = timer;
+    public NetconfClientSessionNegotiatorFactory(Timer timer, Optional<NetconfHelloMessageAdditionalHeader> additionalHeader, long connectionTimeoutMillis) {
+        this.timer = Preconditions.checkNotNull(timer);
         this.additionalHeader = additionalHeader;
+        this.connectionTimeoutMillis = connectionTimeoutMillis;
     }
 
     private static NetconfMessage loadHelloMessageTemplate() {
@@ -48,16 +51,19 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF
     }
 
     @Override
-    public SessionNegotiator getSessionNegotiator(SessionListenerFactory sessionListenerFactory, Channel channel,
-            Promise promise) {
+    public SessionNegotiator<NetconfClientSession> getSessionNegotiator(SessionListenerFactory<NetconfClientSessionListener> sessionListenerFactory, Channel channel,
+            Promise<NetconfClientSession> promise) {
         // Hello message needs to be recreated every time
         NetconfMessage helloMessage = loadHelloMessageTemplate();
+
         if(this.additionalHeader.isPresent()) {
-            helloMessage = new NetconfMessage(helloMessage.getDocument(), additionalHeader.get());
+            helloMessage = new NetconfHelloMessage(helloMessage.getDocument(), additionalHeader.get());
+        } else {
+            helloMessage = new NetconfHelloMessage(helloMessage.getDocument());
         }
+
         NetconfSessionPreferences proposal = new NetconfSessionPreferences(helloMessage);
         return new NetconfClientSessionNegotiator(proposal, promise, channel, timer,
-                sessionListenerFactory.getSessionListener());
+                sessionListenerFactory.getSessionListener(), connectionTimeoutMillis);
     }
-
 }