BUG-693 Config module for netconf client dispatcher.
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / NetconfDevice.java
index aa5c6f40a9a4f827c88aa97d9a72551d6e8fd94f..e3f8649cd1e2bb22851a95b526872d88d770ad04 100644 (file)
@@ -21,6 +21,7 @@ import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.toF
 import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.toRpcMessage;
 import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.wrap;
 
+import com.google.common.base.Preconditions;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
 import java.net.URI;
@@ -38,6 +39,7 @@ import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
+import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
 import org.opendaylight.controller.sal.core.api.Provider;
@@ -121,6 +123,7 @@ public class NetconfDevice implements Provider, //
 
     private boolean rollbackSupported;
 
+    private NetconfClientConfiguration clientConfig;
 
     public NetconfDevice(String name) {
         this.name = name;
@@ -134,11 +137,12 @@ public class NetconfDevice implements Provider, //
         checkState(schemaSourceProvider != null, "Schema Source Provider must be set.");
         checkState(eventExecutor != null, "Event executor must be set.");
 
-        listener = new NetconfDeviceListener(this);
+        Preconditions.checkArgument(clientConfig.getSessionListener() instanceof NetconfDeviceListener);
+        listener = (NetconfDeviceListener) clientConfig.getSessionListener();
 
         logger.info("Starting NETCONF Client {} for address {}", name, socketAddress);
 
-        dispatcher.createClient(socketAddress, listener, reconnectStrategy);
+        dispatcher.createClient(clientConfig);
     }
 
     Optional<SchemaContext> getSchemaContext() {
@@ -464,6 +468,11 @@ public class NetconfDevice implements Provider, //
     public void setDispatcher(final NetconfClientDispatcher dispatcher) {
         this.dispatcher = dispatcher;
     }
+
+    public void setClientConfig(final NetconfClientConfiguration clientConfig) {
+        this.clientConfig = clientConfig;
+    }
+
 }
 
 class NetconfDeviceSchemaContextProvider {