- public static Optional<TLSConfiguration> extractTLSConfiguration(BundleContext context) {
- Optional<InetSocketAddress> address = extractSomeNetconfAddress(context, InfixProp.tls);
- if (address.isPresent()) {
- String keystoreFileName = context.getProperty(NETCONF_TLS_KEYSTORE_PROP);
- File keystoreFile = new File(keystoreFileName);
- checkState(keystoreFile.exists() && keystoreFile.isFile() && keystoreFile.canRead(),
- "Keystore file %s does not exist or is not readable file", keystoreFileName);
- keystoreFile = keystoreFile.getAbsoluteFile();
- String keystorePassword = context.getProperty(NETCONF_TLS_KEYSTORE_PASSWORD_PROP);
- checkNotNull(keystoreFileName, "Property %s must be defined for tls netconf server",
- NETCONF_TLS_KEYSTORE_PROP);
- keystorePassword = keystorePassword != null ? keystorePassword : "";
- return Optional.of(new TLSConfiguration(address.get(), keystoreFile, keystorePassword));
- } else {
- return Optional.absent();
+ public static long extractTimeoutMillis(final BundleContext bundleContext) {
+ final String key = PREFIX_PROP + CONNECTION_TIMEOUT_MILLIS_PROP;
+ final String timeoutString = bundleContext.getProperty(key);
+ if (timeoutString == null || timeoutString.length() == 0) {
+ return DEFAULT_TIMEOUT_MILLIS;
+ }
+ try {
+ return Long.parseLong(timeoutString);
+ } catch (final NumberFormatException e) {
+ logger.warn("Cannot parse {} property: {}, using defaults", key, timeoutString, e);
+ return DEFAULT_TIMEOUT_MILLIS;