- Long connectionAttempts;
- if (getMaxConnectionAttempts() != null && getMaxConnectionAttempts() > 0) {
- connectionAttempts = getMaxConnectionAttempts();
- } else {
- logger.trace("Setting {} on {} to infinity", maxConnectionAttemptsJmxAttribute, this);
- connectionAttempts = null;
- }
- long clientConnectionTimeoutMillis = getConnectionTimeoutMillis();
- /*
- * Uncomment after Switch to IP Address
- if(getAddress().getIpv4Address() != null) {
- addressValue = getAddress().getIpv4Address().getValue();
- } else {
- addressValue = getAddress().getIpv6Address().getValue();
- }
- */
- double sleepFactor = 1.0;
- int minSleep = 1000;
- Long maxSleep = null;
- Long deadline = null;
- ReconnectStrategy strategy = new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, getBetweenAttemptsTimeoutMillis(),
- minSleep, sleepFactor, maxSleep, connectionAttempts, deadline);
-
- device.setReconnectStrategy(strategy);
-
- InetAddress addr = InetAddresses.forString(addressValue);
- InetSocketAddress socketAddress = new InetSocketAddress(addr , getPort().intValue());
-
-
- device.setProcessingExecutor(getGlobalProcessingExecutor());
-
- device.setSocketAddress(socketAddress);
- device.setEventExecutor(getEventExecutorDependency());
- device.setDispatcher(createDispatcher(clientConnectionTimeoutMillis));
- device.setSchemaSourceProvider(getGlobalNetconfSchemaProvider(bundleContext));
-
- getDomRegistryDependency().registerProvider(device, bundleContext);
- device.start();
- return device;
+ final ExecutorService globalProcessingExecutor = getProcessingExecutorDependency().getExecutor();
+
+ final Broker domBroker = getDomRegistryDependency();
+ final BindingAwareBroker bindingBroker = getBindingRegistryDependency();
+
+ final RemoteDeviceHandler<NetconfSessionCapabilities> salFacade
+ = new NetconfDeviceSalFacade(id, domBroker, bindingBroker, bundleContext, globalProcessingExecutor);
+ final NetconfDevice device =
+ NetconfDevice.createNetconfDevice(id, getGlobalNetconfSchemaProvider(), globalProcessingExecutor, salFacade);
+
+ final NetconfDeviceCommunicator listener = userCapabilities.isPresent() ?
+ new NetconfDeviceCommunicator(id, device, userCapabilities.get()) : new NetconfDeviceCommunicator(id, device);
+
+ final NetconfReconnectingClientConfiguration clientConfig = getClientConfig(listener);
+
+ final NetconfClientDispatcher dispatcher = getClientDispatcherDependency();
+ listener.initializeRemoteConnection(dispatcher, clientConfig);
+
+ return new AutoCloseable() {
+ @Override
+ public void close() throws Exception {
+ listener.close();
+ salFacade.close();
+ }
+ };