+
+ device.setClientConfig(getClientConfig(device));
+
+ device.setProcessingExecutor(getGlobalProcessingExecutor());
+
+ device.setEventExecutor(getEventExecutorDependency());
+ device.setDispatcher(getClientDispatcher() == null ? createDispatcher() : getClientDispatcherDependency());
+ device.setSchemaSourceProvider(getGlobalNetconfSchemaProvider(bundleContext));
+ device.setDataProviderService(dataProviderService);
+ getDomRegistryDependency().registerProvider(device, bundleContext);
+ device.start();
+ return device;
+ }
+
+ private ExecutorService getGlobalProcessingExecutor() {
+ return GLOBAL_PROCESSING_EXECUTOR == null ? Executors.newCachedThreadPool() : GLOBAL_PROCESSING_EXECUTOR;
+ }
+
+ private synchronized AbstractCachingSchemaSourceProvider<String, InputStream> getGlobalNetconfSchemaProvider(BundleContext bundleContext) {
+ if(GLOBAL_NETCONF_SOURCE_PROVIDER == null) {
+ String storageFile = "cache/schema";
+ // File directory = bundleContext.getDataFile(storageFile);
+ File directory = new File(storageFile);
+ SchemaSourceProvider<String> defaultProvider = SchemaSourceProviders.noopProvider();
+ GLOBAL_NETCONF_SOURCE_PROVIDER = FilesystemSchemaCachingProvider.createFromStringSourceProvider(defaultProvider, directory);
+ }
+ return GLOBAL_NETCONF_SOURCE_PROVIDER;
+ }
+
+ // FIXME BUG-944 remove backwards compatibility
+ /**
+ * @deprecated Use getClientDispatcherDependency method instead to retrieve injected dispatcher.
+ * This one creates new instance of NetconfClientDispatcher and will be removed in near future.
+ */
+ @Deprecated
+ private NetconfClientDispatcher createDispatcher() {
+ return new NetconfClientDispatcherImpl(getBossThreadGroupDependency(), getWorkerThreadGroupDependency(), new HashedWheelTimer());
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public NetconfClientConfiguration getClientConfig(final NetconfDevice device) {
+ InetSocketAddress socketAddress = getSocketAddress();
+ ReconnectStrategy strategy = getReconnectStrategy();
+ long clientConnectionTimeoutMillis = getConnectionTimeoutMillis();
+
+ return NetconfClientConfigurationBuilder.create()
+ .withAddress(socketAddress)
+ .withConnectionTimeoutMillis(clientConnectionTimeoutMillis)
+ .withReconnectStrategy(strategy)
+ .withSessionListener(new NetconfDeviceListener(device))
+ .withAuthHandler(new LoginPassword(getUsername(),getPassword()))
+ .withProtocol(getTcpOnly() ?
+ NetconfClientConfiguration.NetconfClientProtocol.TCP :
+ NetconfClientConfiguration.NetconfClientProtocol.SSH)
+ .build();
+ }
+
+ private ReconnectStrategy getReconnectStrategy() {
+ Long connectionAttempts;
+ if (getMaxConnectionAttempts() != null && getMaxConnectionAttempts() > 0) {
+ connectionAttempts = getMaxConnectionAttempts();
+ } else {
+ logger.trace("Setting {} on {} to infinity", maxConnectionAttemptsJmxAttribute, this);
+ connectionAttempts = null;
+ }
+ double sleepFactor = 1.0;
+ int minSleep = 1000;
+ Long maxSleep = null;
+ Long deadline = null;
+
+ return new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, getBetweenAttemptsTimeoutMillis(),
+ minSleep, sleepFactor, maxSleep, connectionAttempts, deadline);
+ }
+
+ private InetSocketAddress getSocketAddress() {