Settings { public static Settings from(final Configuration conf) { final Settings settings = new Settings(); if (conf.containsKey("port")) settings.port = conf.getInt("port"); if (conf.containsKey("nioPoolSize")) settings.nioPoolSize = conf.getInt("nioPoolSize"); if (conf.containsKey("workerPoolSize")) settings.workerPoolSize = conf.getInt("workerPoolSize"); if (conf.containsKey("username")) settings.username = conf.getString("username"); if (conf.containsKey("password")) settings.password = conf.getString("password"); if (conf.containsKey("jaasEntry")) settings.jaasEntry = conf.getString("jaasEntry"); if (conf.containsKey("protocol")) settings.protocol = conf.getString("protocol"); if (conf.containsKey("hosts")) settings.hosts = conf.getList("hosts").stream().map(Object::toString).collect(Collectors.toList()); if (conf.containsKey("serializer.className")) { final SerializerSettings serializerSettings = new SerializerSettings(); final Configuration serializerConf = conf.subset("serializer"); if (serializerConf.containsKey("className")) serializerSettings.className = serializerConf.getString("className"); final Configuration serializerConfigConf = conf.subset("serializer.config"); if (IteratorUtils.count(serializerConfigConf.getKeys()) > 0) { final Map<String,Object> m = new HashMap<>(); serializerConfigConf.getKeys().forEachRemaining(name -> m.put(name, serializerConfigConf.getProperty(name))); serializerSettings.config = m; } settings.serializer = serializerSettings; } final Configuration connectionPoolConf = conf.subset("connectionPool"); if (IteratorUtils.count(connectionPoolConf.getKeys()) > 0) { final ConnectionPoolSettings cpSettings = new ConnectionPoolSettings(); if (connectionPoolConf.containsKey("channelizer")) cpSettings.channelizer = connectionPoolConf.getString("channelizer"); if (connectionPoolConf.containsKey("enableSsl")) cpSettings.enableSsl = connectionPoolConf.getBoolean("enableSsl"); if (connectionPoolConf.containsKey("keyStore")) cpSettings.keyStore = connectionPoolConf.getString("keyStore"); if (connectionPoolConf.containsKey("keyStorePassword")) cpSettings.keyStorePassword = connectionPoolConf.getString("keyStorePassword"); if (connectionPoolConf.containsKey("keyStoreType")) cpSettings.keyStoreType = connectionPoolConf.getString("keyStoreType"); if (connectionPoolConf.containsKey("trustStore")) cpSettings.trustStore = connectionPoolConf.getString("trustStore"); if (connectionPoolConf.containsKey("trustStorePassword")) cpSettings.trustStorePassword = connectionPoolConf.getString("trustStorePassword"); if (connectionPoolConf.containsKey("trustStoreType")) cpSettings.trustStoreType = connectionPoolConf.getString("trustStoreType"); if (connectionPoolConf.containsKey("sslEnabledProtocols")) cpSettings.sslEnabledProtocols = connectionPoolConf.getList("sslEnabledProtocols").stream().map(Object::toString) .collect(Collectors.toList()); if (connectionPoolConf.containsKey("sslCipherSuites")) cpSettings.sslCipherSuites = connectionPoolConf.getList("sslCipherSuites").stream().map(Object::toString) .collect(Collectors.toList()); if (connectionPoolConf.containsKey("sslSkipCertValidation")) cpSettings.sslSkipCertValidation = connectionPoolConf.getBoolean("sslSkipCertValidation"); if (connectionPoolConf.containsKey("minSize")) cpSettings.minSize = connectionPoolConf.getInt("minSize"); if (connectionPoolConf.containsKey("maxSize")) cpSettings.maxSize = connectionPoolConf.getInt("maxSize"); if (connectionPoolConf.containsKey("minSimultaneousUsagePerConnection")) cpSettings.minSimultaneousUsagePerConnection = connectionPoolConf.getInt("minSimultaneousUsagePerConnection"); if (connectionPoolConf.containsKey("maxSimultaneousUsagePerConnection")) cpSettings.maxSimultaneousUsagePerConnection = connectionPoolConf.getInt("maxSimultaneousUsagePerConnection"); if (connectionPoolConf.containsKey("maxInProcessPerConnection")) cpSettings.maxInProcessPerConnection = connectionPoolConf.getInt("maxInProcessPerConnection"); if (connectionPoolConf.containsKey("minInProcessPerConnection")) cpSettings.minInProcessPerConnection = connectionPoolConf.getInt("minInProcessPerConnection"); if (connectionPoolConf.containsKey("maxWaitForConnection")) cpSettings.maxWaitForConnection = connectionPoolConf.getInt("maxWaitForConnection"); if (connectionPoolConf.containsKey("maxWaitForClose")) cpSettings.maxWaitForClose = connectionPoolConf.getInt("maxWaitForClose"); if (connectionPoolConf.containsKey("maxContentLength")) cpSettings.maxContentLength = connectionPoolConf.getInt("maxContentLength"); if (connectionPoolConf.containsKey("reconnectInterval")) cpSettings.reconnectInterval = connectionPoolConf.getInt("reconnectInterval"); if (connectionPoolConf.containsKey("resultIterationBatchSize")) cpSettings.resultIterationBatchSize = connectionPoolConf.getInt("resultIterationBatchSize"); if (connectionPoolConf.containsKey("keepAliveInterval")) cpSettings.keepAliveInterval = connectionPoolConf.getLong("keepAliveInterval"); if (connectionPoolConf.containsKey("validationRequest")) cpSettings.validationRequest = connectionPoolConf.getString("validationRequest"); settings.connectionPool = cpSettings; } return settings; }  static Settings read(final InputStream stream); static Settings from(final Configuration conf); public int port; public String path; public List<String> hosts; public SerializerSettings serializer; public ConnectionPoolSettings connectionPool; public int nioPoolSize; public int workerPoolSize; public String username; public String password; public String jaasEntry; public String protocol; }
@Test public void shouldCreateFromConfiguration() { final Configuration conf = new BaseConfiguration(); conf.setProperty("port", 8000); conf.setProperty("nioPoolSize", 16); conf.setProperty("workerPoolSize", 32); conf.setProperty("username", "user1"); conf.setProperty("password", "password1"); conf.setProperty("jaasEntry", "JaasIt"); conf.setProperty("protocol", "protocol0"); conf.setProperty("hosts", Arrays.asList("255.0.0.1", "255.0.0.2", "255.0.0.3")); conf.setProperty("serializer.className", "my.serializers.MySerializer"); conf.setProperty("serializer.config.any", "thing"); conf.setProperty("connectionPool.enableSsl", true); conf.setProperty("connectionPool.keyStore", "server.jks"); conf.setProperty("connectionPool.keyStorePassword", "password2"); conf.setProperty("connectionPool.keyStoreType", "pkcs12"); conf.setProperty("connectionPool.trustStore", "trust.jks"); conf.setProperty("connectionPool.trustStorePassword", "password3"); conf.setProperty("connectionPool.trustStoreType", "jks"); conf.setProperty("connectionPool.sslEnabledProtocols", Arrays.asList("TLSv1.1","TLSv1.2")); conf.setProperty("connectionPool.sslCipherSuites", Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384")); conf.setProperty("connectionPool.sslSkipCertValidation", true); conf.setProperty("connectionPool.minSize", 100); conf.setProperty("connectionPool.maxSize", 200); conf.setProperty("connectionPool.minSimultaneousUsagePerConnection", 300); conf.setProperty("connectionPool.maxSimultaneousUsagePerConnection", 400); conf.setProperty("connectionPool.maxInProcessPerConnection", 500); conf.setProperty("connectionPool.minInProcessPerConnection", 600); conf.setProperty("connectionPool.maxWaitForConnection", 700); conf.setProperty("connectionPool.maxContentLength", 800); conf.setProperty("connectionPool.reconnectInterval", 900); conf.setProperty("connectionPool.resultIterationBatchSize", 1100); conf.setProperty("connectionPool.channelizer", "channelizer0"); conf.setProperty("connectionPool.validationRequest", "g.inject()"); final Settings settings = Settings.from(conf); assertEquals(8000, settings.port); assertEquals(16, settings.nioPoolSize); assertEquals(32, settings.workerPoolSize); assertEquals("user1", settings.username); assertEquals("password1", settings.password); assertEquals("JaasIt", settings.jaasEntry); assertEquals("protocol0", settings.protocol); assertEquals(Arrays.asList("255.0.0.1", "255.0.0.2", "255.0.0.3"), settings.hosts); assertEquals("my.serializers.MySerializer", settings.serializer.className); assertEquals("thing", settings.serializer.config.get("any")); assertThat(settings.connectionPool.enableSsl, is(true)); assertEquals("server.jks", settings.connectionPool.keyStore); assertEquals("password2", settings.connectionPool.keyStorePassword); assertEquals("pkcs12", settings.connectionPool.keyStoreType); assertEquals("trust.jks", settings.connectionPool.trustStore); assertEquals("password3", settings.connectionPool.trustStorePassword); assertEquals("jks", settings.connectionPool.trustStoreType); assertEquals(Arrays.asList("TLSv1.1","TLSv1.2"), settings.connectionPool.sslEnabledProtocols); assertEquals(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"), settings.connectionPool.sslCipherSuites); assertThat(settings.connectionPool.sslSkipCertValidation, is(true)); assertEquals(100, settings.connectionPool.minSize); assertEquals(200, settings.connectionPool.maxSize); assertEquals(300, settings.connectionPool.minSimultaneousUsagePerConnection); assertEquals(400, settings.connectionPool.maxSimultaneousUsagePerConnection); assertEquals(500, settings.connectionPool.maxInProcessPerConnection); assertEquals(600, settings.connectionPool.minInProcessPerConnection); assertEquals(700, settings.connectionPool.maxWaitForConnection); assertEquals(800, settings.connectionPool.maxContentLength); assertEquals(900, settings.connectionPool.reconnectInterval); assertEquals(1100, settings.connectionPool.resultIterationBatchSize); assertEquals("channelizer0", settings.connectionPool.channelizer); assertEquals("g.inject()", settings.connectionPool.validationRequest); }