- private void initDependencies() {
- domRegistry = getDomRegistryDependency();
- clientDispatcher = getClientDispatcherDependency();
- bindingRegistry = getBindingRegistryDependency();
- processingExecutor = getProcessingExecutorDependency();
- eventExecutor = getEventExecutorDependency();
-
- if(getKeepaliveExecutor() == null) {
- LOG.warn("Keepalive executor missing. Using default instance for now, the configuration needs to be updated");
-
- // Instantiate the default executor, now we know its necessary
- if(DEFAULT_KEEPALIVE_EXECUTOR == null) {
- DEFAULT_KEEPALIVE_EXECUTOR = Executors.newScheduledThreadPool(2, new ThreadFactory() {
- @Override
- public Thread newThread(final Runnable r) {
- final Thread thread = new Thread(r);
- thread.setName("netconf-southound-keepalives-" + thread.getId());
- thread.setDaemon(true);
- return thread;
- }
- });
- }
- } else {
- keepaliveExecutor = getKeepaliveExecutorDependency();
- }
- }
-
- private boolean shouldSendKeepalive() {
- return getKeepaliveDelay() > 0;
- }
-
- private Optional<NetconfSessionPreferences> getUserCapabilities() {
- if(getYangModuleCapabilities() == null) {
- return Optional.absent();
- }
-
- final List<String> capabilities = getYangModuleCapabilities().getCapability();
- if(capabilities == null || capabilities.isEmpty()) {
- return Optional.absent();
- }
-
- final NetconfSessionPreferences parsedOverrideCapabilities = NetconfSessionPreferences.fromStrings(capabilities);
- JmxAttributeValidationException.checkCondition(
- parsedOverrideCapabilities.getNonModuleCaps().isEmpty(),
- "Capabilities to override can only contain module based capabilities, non-module capabilities will be retrieved from the device," +
- " configured non-module capabilities: " + parsedOverrideCapabilities.getNonModuleCaps(),
- yangModuleCapabilitiesJmxAttribute);
-
- return Optional.of(parsedOverrideCapabilities);
- }
-
- public NetconfReconnectingClientConfiguration getClientConfig(final NetconfDeviceCommunicator listener) {
- final InetSocketAddress socketAddress = getSocketAddress();
- final long clientConnectionTimeoutMillis = getConnectionTimeoutMillis();
-
- final ReconnectStrategyFactory sf = new TimedReconnectStrategyFactory(eventExecutor,
- getMaxConnectionAttempts(), getBetweenAttemptsTimeoutMillis(), getSleepFactor());
- final ReconnectStrategy strategy = sf.createReconnectStrategy();
-
- return NetconfReconnectingClientConfigurationBuilder.create()
- .withAddress(socketAddress)
- .withConnectionTimeoutMillis(clientConnectionTimeoutMillis)
- .withReconnectStrategy(strategy)
- .withAuthHandler(new LoginPassword(getUsername(), getPassword()))
- .withProtocol(getTcpOnly() ?
- NetconfClientConfiguration.NetconfClientProtocol.TCP :
- NetconfClientConfiguration.NetconfClientProtocol.SSH)
- .withConnectStrategyFactory(sf)
- .withSessionListener(listener)
- .build();
- }
-
- private static final class SalConnectorCloseable implements AutoCloseable {
- private final RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
- private final List<SchemaSourceRegistration<YangTextSchemaSource>> registeredYangLibSources;
- private final NetconfDeviceCommunicator listener;
-
- public SalConnectorCloseable(final NetconfDeviceCommunicator listener,
- final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
- final List<SchemaSourceRegistration<YangTextSchemaSource>> registeredYangLibSources) {
- this.listener = listener;
- this.salFacade = salFacade;
- this.registeredYangLibSources = registeredYangLibSources;
- }
-
- @Override
- public void close() {
- for (SchemaSourceRegistration<YangTextSchemaSource> registeredYangLibSource : registeredYangLibSources) {
- registeredYangLibSource.close();
- }
- listener.close();
- salFacade.close();
- }
- }
-
- private static final class TimedReconnectStrategyFactory implements ReconnectStrategyFactory {
- private final Long connectionAttempts;
- private final EventExecutor executor;
- private final double sleepFactor;
- private final int minSleep;
-
- TimedReconnectStrategyFactory(final EventExecutor executor, final Long maxConnectionAttempts, final int minSleep, final BigDecimal sleepFactor) {
- if (maxConnectionAttempts != null && maxConnectionAttempts > 0) {
- connectionAttempts = maxConnectionAttempts;
- } else {
- LOG.trace("Setting {} on {} to infinity", maxConnectionAttemptsJmxAttribute, this);
- connectionAttempts = null;
- }