+
+ public NetconfReconnectingClientConfiguration getClientConfig(final NetconfDeviceCommunicator listener) {
+ final InetSocketAddress socketAddress = getSocketAddress();
+ final ReconnectStrategy strategy = getReconnectStrategy();
+ final long clientConnectionTimeoutMillis = getConnectionTimeoutMillis();
+
+ return NetconfReconnectingClientConfigurationBuilder.create()
+ .withAddress(socketAddress)
+ .withConnectionTimeoutMillis(clientConnectionTimeoutMillis)
+ .withReconnectStrategy(strategy)
+ .withSessionListener(listener)
+ .withAuthHandler(new LoginPassword(getUsername(),getPassword()))
+ .withProtocol(getTcpOnly() ?
+ NetconfClientConfiguration.NetconfClientProtocol.TCP :
+ NetconfClientConfiguration.NetconfClientProtocol.SSH)
+ .withConnectStrategyFactory(new ReconnectStrategyFactory() {
+ @Override
+ public ReconnectStrategy createReconnectStrategy() {
+ return getReconnectStrategy();
+ }
+ })
+ .build();
+ }
+
+ private ReconnectStrategy getReconnectStrategy() {
+ final Long connectionAttempts;
+ if (getMaxConnectionAttempts() != null && getMaxConnectionAttempts() > 0) {
+ connectionAttempts = getMaxConnectionAttempts();
+ } else {
+ logger.trace("Setting {} on {} to infinity", maxConnectionAttemptsJmxAttribute, this);
+ connectionAttempts = null;
+ }
+ final double sleepFactor = getSleepFactor().doubleValue();
+ final int minSleep = getBetweenAttemptsTimeoutMillis();
+ final Long maxSleep = null;
+ final Long deadline = null;
+
+ return new TimedReconnectStrategy(getEventExecutorDependency(), getBetweenAttemptsTimeoutMillis(),
+ minSleep, sleepFactor, maxSleep, connectionAttempts, deadline);
+ }
+
+ private InetSocketAddress getSocketAddress() {
+ if(getAddress().getDomainName() != null) {
+ return new InetSocketAddress(getAddress().getDomainName().getValue(), getPort().getValue());
+ } else {
+ final IpAddress ipAddress = getAddress().getIpAddress();
+ final String ip = ipAddress.getIpv4Address() != null ? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue();
+ return new InetSocketAddress(ip, getPort().getValue());
+ }
+ }