List of usage examples for org.apache.commons.configuration Configuration getInt
int getInt(String key);
From source file:org.apache.tamaya.format.CommonsConfigPropertySource.java
public CommonsConfigPropertySource(String name, Configuration commonsConfig) { commonsConfig = Objects.requireNonNull(commonsConfig); this.name = Objects.requireNonNull(name); try {// w ww . ja v a 2s. c o m this.ordinal = commonsConfig.getInt(PropertySource.TAMAYA_ORDINAL); } catch (Exception e) { this.ordinal = 0; } }
From source file:org.apache.tinkerpop.gremlin.driver.Settings.java
/** * Read configuration from a file into a new {@link Settings} object. */// w w w. j av a2 s. c om 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("trustCertChainFile")) cpSettings.trustCertChainFile = connectionPoolConf.getString("trustCertChainFile"); 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("maxContentLength")) cpSettings.maxContentLength = connectionPoolConf.getInt("maxContentLength"); if (connectionPoolConf.containsKey("reconnectInterval")) cpSettings.reconnectInterval = connectionPoolConf.getInt("reconnectInterval"); if (connectionPoolConf.containsKey("reconnectInitialDelay")) cpSettings.reconnectInitialDelay = connectionPoolConf.getInt("reconnectInitialDelay"); if (connectionPoolConf.containsKey("resultIterationBatchSize")) cpSettings.resultIterationBatchSize = connectionPoolConf.getInt("resultIterationBatchSize"); if (connectionPoolConf.containsKey("keepAliveInterval")) cpSettings.keepAliveInterval = connectionPoolConf.getLong("keepAliveInterval"); settings.connectionPool = cpSettings; } return settings; }
From source file:org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy.java
public static VertexProgramStrategy create(final Configuration configuration) { try {//from w w w .j a va 2 s .co m final VertexProgramStrategy.Builder builder = VertexProgramStrategy.build(); for (final String key : (List<String>) IteratorUtils.asList(configuration.getKeys())) { if (key.equals(GRAPH_COMPUTER)) builder.graphComputer((Class) Class.forName(configuration.getString(key))); else if (key.equals(WORKERS)) builder.workers(configuration.getInt(key)); else if (key.equals(PERSIST)) builder.persist(GraphComputer.Persist.valueOf(configuration.getString(key))); else if (key.equals(RESULT)) builder.result(GraphComputer.ResultGraph.valueOf(configuration.getString(key))); else if (key.equals(VERTICES)) builder.vertices((Traversal) configuration.getProperty(key)); else if (key.equals(EDGES)) builder.edges((Traversal) configuration.getProperty(key)); else builder.configure(key, configuration.getProperty(key)); } return builder.create(); } catch (final ClassNotFoundException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldLoadSystemProperties() { System.setProperty("blah.aa", "1"); System.setProperty("blah.b", "true"); System.setProperty("blah.c", "three"); System.setProperty("bleep.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", false); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("blah.aa")); assertTrue(configuration.getBoolean("blah.b")); assertEquals("three", configuration.getProperty("blah.c")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); System.clearProperty("blah.aa"); System.clearProperty("blah.b"); System.clearProperty("blah.c"); System.clearProperty("bleep.d"); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldTrimSystemPropertyPrefixes() { System.setProperty("blah.a", "1"); System.setProperty("blah.bbb", "true"); System.setProperty("blah.c", "three"); System.setProperty("bleep.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", true); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("a")); assertTrue(configuration.getBoolean("bbb")); assertEquals("three", configuration.getProperty("c")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); System.clearProperty("blah.a"); System.clearProperty("blah.bbb"); System.clearProperty("blah.c"); System.clearProperty("bleep.d"); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldTrimSystemPropertyPrefixesAndNoMore() { System.setProperty("blah.a.x", "1"); System.setProperty("blah.b.y", "true"); System.setProperty("blah.cc.zzz", "three"); System.setProperty("bleep.d.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", true); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("a.x")); assertTrue(configuration.getBoolean("b.y")); assertEquals("three", configuration.getProperty("cc.zzz")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); assertFalse(configuration.containsKey("d.d") || configuration.containsKey("bleep.d.d")); System.clearProperty("blah.a.x"); System.clearProperty("blah.b.y"); System.clearProperty("blah.cc.zzz"); System.clearProperty("bleep.d.d"); }
From source file:org.apache.whirr.service.solr.SolrClusterActionHandler.java
@Override protected void beforeBootstrap(ClusterActionEvent event) throws IOException { Configuration config = getConfiguration(event.getClusterSpec(), SOLR_DEFAULT_CONFIG); // Validate the config int jettyPort = config.getInt(SOLR_JETTY_PORT); int jettyStopPort = config.getInt(SOLR_JETTY_STOP_PORT); if (jettyPort == 0) { throw new IllegalArgumentException("Must specify Jetty's port! (" + SOLR_JETTY_PORT + ")"); }//from w w w .j a va 2s.c o m if (jettyStopPort == 0) { throw new IllegalArgumentException("Must specify Jetty's stop port! (" + SOLR_JETTY_STOP_PORT + ")"); } if (jettyPort == jettyStopPort) { throw new IllegalArgumentException("Jetty's port and the stop port must be different"); } String solrConfigTarballUrl = config.getString(SOLR_CONFIG_TARBALL_URL); if (StringUtils.isBlank(solrConfigTarballUrl)) { throw new IllegalArgumentException( "Must specify Solr config tarball! (" + SOLR_CONFIG_TARBALL_URL + ")"); } String solrTarball = config.getString(SOLR_TARBALL_URL); if (!solrTarball.matches("^.*apache-solr-.*(tgz|tar\\.gz)$")) { throw new IllegalArgumentException("Must specify a Solr tarball"); } // Call the installers addStatement(event, call(getInstallFunction(config, "java", "install_openjdk"))); addStatement(event, call("install_tarball")); String installFunc = getInstallFunction(config, getRole(), "install_" + getRole()); LOG.info("Installing Solr"); addStatement(event, call(installFunc, solrTarball, SOLR_HOME)); }
From source file:org.apache.whirr.service.solr.SolrClusterActionHandler.java
@Override protected void beforeConfigure(ClusterActionEvent event) throws IOException { LOG.info("Configure Solr"); ClusterSpec clusterSpec = event.getClusterSpec(); Configuration config = getConfiguration(clusterSpec, SOLR_DEFAULT_CONFIG); int jettyPort = config.getInt(SOLR_JETTY_PORT); // Open up Jetty port event.getFirewallManager().addRule(Rule.create().destination(role(SOLR_ROLE)).port(jettyPort)); }
From source file:org.apache.whirr.service.solr.SolrClusterActionHandler.java
@Override protected void beforeStart(ClusterActionEvent event) throws IOException { ClusterSpec clusterSpec = event.getClusterSpec(); Configuration config = getConfiguration(clusterSpec, SOLR_DEFAULT_CONFIG); String solrConfigTarballUrl = prepareRemoteFileUrl(event, config.getString(SOLR_CONFIG_TARBALL_URL)); LOG.info("Preparing solr config tarball url {}", solrConfigTarballUrl); addStatement(event, call("install_tarball_no_md5", solrConfigTarballUrl, SOLR_HOME)); int jettyPort = config.getInt(SOLR_JETTY_PORT); int jettyStopPort = config.getInt(SOLR_JETTY_STOP_PORT); String startFunc = getStartFunction(config, getRole(), "start_" + getRole()); LOG.info("Starting up Solr"); addStatement(event,//w w w . j ava 2s . co m call(startFunc, String.valueOf(jettyPort), String.valueOf(jettyStopPort), safeSecretString(config.getString(SOLR_JETTY_STOP_SECRET)), SOLR_HOME, SOLR_HOME + "/example/start.jar", config.getString(SOLR_JAVA_OPTS, ""))); }
From source file:org.apache.whirr.service.solr.SolrClusterActionHandler.java
@Override protected void afterStart(ClusterActionEvent event) throws IOException { ClusterSpec clusterSpec = event.getClusterSpec(); Cluster cluster = event.getCluster(); Configuration config = getConfiguration(clusterSpec, SOLR_DEFAULT_CONFIG); int jettyPort = config.getInt(SOLR_JETTY_PORT); LOG.info("Completed configuration of {}", clusterSpec.getClusterName()); LOG.info("Solr Hosts: {}", getHosts(cluster.getInstancesMatching(role(SOLR_ROLE)), jettyPort)); }