List of usage examples for org.apache.commons.configuration Configuration getInt
int getInt(String key);
From source file:org.seedstack.hub.infra.vcs.ProxySelectorService.java
private void initializeProxiesFromConfiguration() { Configuration proxyConfig = application.getConfiguration().subset(PROXY); if (!proxyConfig.isEmpty()) { if (!proxyConfig.containsKey(TYPE)) { throw new ConfigurationException("Missing \"type\" in the proxy configuration."); }//from w w w.jav a 2 s .co m String type = proxyConfig.getString(TYPE); if (!proxyConfig.containsKey(HOST)) { throw new ConfigurationException("Missing \"url\" in the proxy configuration."); } String url = proxyConfig.getString(HOST); if (!proxyConfig.containsKey(PORT)) { throw new ConfigurationException("Missing \"port\" in the proxy configuration."); } int port = proxyConfig.getInt(PORT); String[] exclusionsConfig = proxyConfig.getStringArray(EXCLUSIONS); if (exclusionsConfig != null) { exclusions = Arrays.stream(exclusionsConfig).map(this::makePattern).collect(toList()); } proxy = Optional.of(new Proxy(Proxy.Type.valueOf(type), new InetSocketAddress(url, port))); } else { proxy = Optional.empty(); exclusions = new ArrayList<>(); } }
From source file:org.seedstack.seed.web.internal.ServerConfigFactory.java
public ServerConfig create(Configuration configuration, SslConfig sslConfig, SSLContext sslContext) { ServerConfig serverConfig = new ServerConfig(); if (configuration.containsKey("host")) { serverConfig.setHost(configuration.getString("host")); }/* w ww . ja v a 2 s .co m*/ if (configuration.containsKey("port")) { serverConfig.setPort(configuration.getInt("port")); } if (configuration.containsKey("context-path")) { serverConfig.setContextPath(configuration.getString("context-path")); } if (configuration.containsKey("https-enabled")) { serverConfig.setHttpsEnabled(configuration.getBoolean("https-enabled")); } if (configuration.containsKey("http2-enabled")) { serverConfig.setHttp2Enabled(configuration.getBoolean("http2-enabled")); } // Undertow configuration if (configuration.containsKey("buffer-size")) { serverConfig.setBufferSize(configuration.getInt("buffer-size")); } if (configuration.containsKey("buffers-per-region")) { serverConfig.setBuffersPerRegion(configuration.getInt("buffers-per-region")); } if (configuration.containsKey("io-threads")) { serverConfig.setIoThreads(configuration.getInt("io-threads")); } if (configuration.containsKey("worker-threads")) { serverConfig.setWorkerThreads(configuration.getInt("worker-threads")); } if (configuration.containsKey("direct-buffers")) { serverConfig.setDirectBuffers(configuration.getBoolean("direct-buffers")); } serverConfig.setSslConfig(sslConfig); serverConfig.setSslContext(sslContext); return serverConfig; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
private SolrClient buildLBSolrClient(Configuration solrClientConfiguration, String[] lbUrls) throws MalformedURLException { LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(lbUrls); if (solrClientConfiguration.containsKey(SolrConfigurationConstants.CONNECTION_TIMEOUT)) { lbHttpSolrClient.setConnectionTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.CONNECTION_TIMEOUT)); }/*from ww w . jav a 2s.c om*/ if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ALIVE_CHECK_INTERVAL)) { lbHttpSolrClient.setAliveCheckInterval( solrClientConfiguration.getInt(SolrConfigurationConstants.ALIVE_CHECK_INTERVAL)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.QUERY_PARAMS)) { lbHttpSolrClient.setQueryParams(Sets .newHashSet(solrClientConfiguration.getStringArray(SolrConfigurationConstants.QUERY_PARAMS))); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.SO_TIMEOUT)) { lbHttpSolrClient.setSoTimeout(solrClientConfiguration.getInt(SolrConfigurationConstants.SO_TIMEOUT)); } return lbHttpSolrClient; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
private SolrClient buildHttpSolrClient(Configuration solrClientConfiguration, String url) { HttpSolrClient httpSolrClient = new HttpSolrClient(url); if (solrClientConfiguration.containsKey(SolrConfigurationConstants.CONNECTION_TIMEOUT)) { httpSolrClient.setConnectionTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.CONNECTION_TIMEOUT)); }/* w w w .ja v a 2s .c om*/ if (solrClientConfiguration.containsKey(SolrConfigurationConstants.QUERY_PARAMS)) { httpSolrClient.setQueryParams(Sets .newHashSet(solrClientConfiguration.getStringArray(SolrConfigurationConstants.QUERY_PARAMS))); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.SO_TIMEOUT)) { httpSolrClient.setSoTimeout(solrClientConfiguration.getInt(SolrConfigurationConstants.SO_TIMEOUT)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ALLOW_COMPRESSION)) { httpSolrClient.setAllowCompression( solrClientConfiguration.getBoolean(SolrConfigurationConstants.ALLOW_COMPRESSION)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.MAX_CONNECTIONS_PER_HOST)) { httpSolrClient.setDefaultMaxConnectionsPerHost( solrClientConfiguration.getInt(SolrConfigurationConstants.MAX_CONNECTIONS_PER_HOST)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.FOLLOW_REDIRECTS)) { httpSolrClient.setFollowRedirects( solrClientConfiguration.getBoolean(SolrConfigurationConstants.FOLLOW_REDIRECTS)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.MAX_TOTAL_CONNECTIONS)) { httpSolrClient.setMaxTotalConnections( solrClientConfiguration.getInt(SolrConfigurationConstants.MAX_TOTAL_CONNECTIONS)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.USE_MULTI_PART_HOST)) { httpSolrClient.setUseMultiPartPost( solrClientConfiguration.getBoolean(SolrConfigurationConstants.USE_MULTI_PART_HOST)); } return httpSolrClient; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
private CloudSolrClient buildCloudSolrClient(Configuration solrClientConfiguration, String[] zooKeeperUrls) throws MalformedURLException { String[] lbUrls = solrClientConfiguration.getStringArray(SolrConfigurationConstants.LB_URLS); CloudSolrClient cloudSolrClient;/*ww w. j a v a 2 s. c o m*/ if (lbUrls != null && lbUrls.length > 0) { cloudSolrClient = new CloudSolrClient(zooKeeperUrls[0], new LBHttpSolrClient(lbUrls), solrClientConfiguration.getBoolean(SolrConfigurationConstants.UPDATE_TO_LEADERS, true)); } else { cloudSolrClient = new CloudSolrClient(Lists.newArrayList(zooKeeperUrls), solrClientConfiguration.getString(SolrConfigurationConstants.CHROOT)); } String defaultCollection = solrClientConfiguration.getString(SolrConfigurationConstants.DEFAULT_COLLECTION); if (defaultCollection != null && !defaultCollection.isEmpty()) { cloudSolrClient.setDefaultCollection(defaultCollection); } String idField = solrClientConfiguration.getString(SolrConfigurationConstants.ID_FIELD); if (idField != null && !idField.isEmpty()) { cloudSolrClient.setIdField(idField); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.COLLECTION_CACHE_TTL)) { cloudSolrClient.setCollectionCacheTTl( solrClientConfiguration.getInt(SolrConfigurationConstants.COLLECTION_CACHE_TTL)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)) { cloudSolrClient.setParallelCacheRefreshes( solrClientConfiguration.getInt(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_UPDATES)) { cloudSolrClient.setParallelUpdates( solrClientConfiguration.getBoolean(SolrConfigurationConstants.PARALLEL_UPDATES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)) { cloudSolrClient.setZkClientTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)) { cloudSolrClient.setZkConnectTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)); } return cloudSolrClient; }
From source file:org.topazproject.ambra.auth.web.AuthServletContextListener.java
public void contextInitialized(final ServletContextEvent event) { final ServletContext context = event.getServletContext(); Configuration conf = ConfigurationStore.getInstance().getConfiguration(); String url = conf.getString(PREF + "url"); final Properties dbProperties = new Properties(); dbProperties.setProperty("url", url); dbProperties.setProperty("user", conf.getString(PREF + "user")); dbProperties.setProperty("password", conf.getString(PREF + "password")); try {/*w w w . j a va 2 s.c o m*/ dbContext = DatabaseContext.createDatabaseContext(conf.getString(PREF + "driver"), dbProperties, conf.getInt(PREF + "initialSize"), conf.getInt(PREF + "maxActive"), conf.getString(PREF + "connectionValidationQuery")); } catch (final DatabaseException ex) { throw new Error("Failed to initialize the database context to '" + url + "'", ex); } final UserService userService = new UserService(dbContext, conf.getString(PREF + "usernameToGuidSql"), conf.getString(PREF + "guidToUsernameSql")); context.setAttribute(AuthConstants.USER_SERVICE, userService); }
From source file:org.ublog.benchmark.cassandra.DataStoreCassandra.java
public void initialize() throws Exception { this.keyspace = "Twitter"; Configuration conf = new PropertiesConfiguration("cassandra.properties"); String[] nodes = conf.getStringArray("node"); this.max_active_connections = conf.getInt("maxActiveConnections"); this.partitioner = conf.getString("partitioner"); this.inst = new String[nodes.length]; for (int i = 0; i < nodes.length; i++) { String[] split = nodes[i].split(":"); if (split.length == 2) { int port = new Integer(split[1]); this.inst[i] = InetAddress.getByName(split[0]).getHostName() + ":" + port; } else {// www. j av a 2 s . c om logger.error("Nodes configuration is wrong"); throw new ConfigurationException("Nodes must be in the format hostName:port"); } } String hosts = ""; int i = 0; for (String str : inst) { if (i < this.inst.length - 1) { hosts += str + ","; } else { hosts += str; } i++; } System.out.println("HOSTS: " + hosts); CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator(hosts); cassandraHostConfigurator.setMaxActive(this.max_active_connections); cassandraHostConfigurator.setMaxIdle(CassandraHost.DEFAULT_MAX_IDLE); cassandraHostConfigurator.setExhaustedPolicy(ExhaustedPolicy.WHEN_EXHAUSTED_BLOCK); cassandraHostConfigurator.setMaxWaitTimeWhenExhausted(CassandraHost.DEFAULT_MAX_WAITTIME_WHEN_EXHAUSTED); cassandraHostConfigurator.setTimestampResolution("MICROSECONDS"); System.out.println(cassandraHostConfigurator.toString()); this.connPool = CassandraClientPoolFactory.getInstance().createNew(cassandraHostConfigurator); }
From source file:org.ublog.benchmark.mysql.DataStoreMysql.java
public void initialize() throws Exception { Configuration config = new PropertiesConfiguration("mysql.properties"); String host = config.getString("host.name"); int port = config.getInt("host.port"); this.url = "jdbc:mysql://" + host + ":" + port + "/"; this.dbName = config.getString("dbName"); this.driver = "com.mysql.jdbc.Driver"; this.userName = config.getString("userName"); this.password = config.getString("password"); ///CREATE TABLES try {//from w ww . ja v a2 s . co m Class.forName(driver).newInstance(); DataSource ds_unpooled = DataSources.unpooledDataSource(url + dbName, userName, password); Map<String, Comparable> overrides = new HashMap<String, Comparable>(); overrides.put("maxStatements", "200"); //Stringified property values work overrides.put("maxPoolSize", new Integer(3)); //"boxed primitives" also work //create the PooledDataSource using the default configuration and our overrides this.pooled = DataSources.pooledDataSource(ds_unpooled, overrides); //The DataSource ds_pooled is now a fully configured and usable pooled DataSource, //with Statement caching enabled for a maximum of up to 200 statements and a maximum //of 50 Connections. java.sql.Connection conn = pooled.getConnection(); System.out.println("Connected to the database"); String users = "create table users (" + "userID VARCHAR(50) PRIMARY KEY, " + "name VARCHAR(50), " + "password VARCHAR(50), " + "following VARCHAR(500), " + "followers VARCHAR(500), " + "username VARCHAR(50), " + "lastTweet VARCHAR(50), " + "created VARCHAR(50) )" + "ENGINE=NDBCLUSTER"; String tweets = "create table tweets (" + "tweetID VARCHAR(50) PRIMARY KEY, " + "id VARCHAR(50), " + "text VARCHAR(50), " + "date VARCHAR(50), " + "user VARCHAR(50) )" + "ENGINE=NDBCLUSTER"; String friendsTimeLine = "create table friendsTimeLine (" + "tweetID VARCHAR(50)," + "userID VARCHAR(50), INDEX(userID)," + "date VARCHAR(50), " + "PRIMARY KEY (userID,tweetID)" + ")" + "ENGINE=NDBCLUSTER"; String tweetsTags = "create table tweetsTags(" + "tweetID VARCHAR(50) PRIMARY KEY, " + "topic VARCHAR(50), " + "user VARCHAR(50) )" + "ENGINE=NDBCLUSTER"; try { Statement stmt = conn.createStatement(); if (logger.isInfoEnabled()) logger.info("Creating table users"); stmt.executeUpdate(users); if (logger.isInfoEnabled()) logger.info("Creating table tweets"); stmt.executeUpdate(tweets); if (logger.isInfoEnabled()) logger.info("Creating table friendsTimeLine"); stmt.executeUpdate(friendsTimeLine); if (logger.isInfoEnabled()) logger.info("Creating table tweet's tags"); stmt.executeUpdate(tweetsTags); stmt.close(); conn.close(); } catch (SQLException ex) { logger.error("SQLException ", ex); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.ublog.benchmark.social.SocialBenchmark.java
@Override public void initialize(Configuration conf) throws ConfigurationException { this.initialTweetsFactor = conf.getDouble("benchmark.social.initialTweetsFactor"); Utils.MAX_MESSAGES_IN_TIMELINE = conf.getInt("benchmark.social.maximumMessagesTimeline"); Utils.MaxNTweets = conf.getInt("benchmark.social.maximumTweetsPerUser"); long seedNextOperation = conf.containsKey("benchmark.social.seedNextOperation") ? conf.getLong("benchmark.social.seedNextOperation") : System.nanoTime();//from w w w. j a v a 2 s . co m long seedOwner = conf.containsKey("benchmark.social.seedOwner") ? conf.getLong("benchmark.social.seedOwner") : System.nanoTime(); long seedTopic = conf.containsKey("benchmark.social.seedTopic") ? conf.getLong("benchmark.social.seedTopic") : System.nanoTime(); long seedStartFollow = conf.containsKey("benchmark.social.seedStartFollow") ? conf.getLong("benchmark.social.seedStartFollow") : System.nanoTime(); this.rndOp = new Random(seedNextOperation); this.rndOwner = new Random(seedOwner); this.rndTopic = new Random(seedTopic); this.rndStartFollow = new Random(seedStartFollow); this.probabilitySearchPerTopic = conf.getDouble("benchmark.social.probabilities.probabilitySearchPerTopic"); this.probabilitySearchPerOwner = conf.getDouble("benchmark.social.probabilities.probabilitySearchPerOwner"); this.probabilityGetRecentTweets = conf .getDouble("benchmark.social.probabilities.probabilityGetRecentTweets"); this.probabilityGetFriendsTimeline = conf .getDouble("benchmark.social.probabilities.probabilityGetFriendsTimeline"); this.probabilityStartFollowing = conf.getDouble("benchmark.social.probabilities.probabilityStartFollowing"); this.probabilityStopFollowing = conf.getDouble("benchmark.social.probabilities.probabilityStopFollowing"); if (this.probabilityGetFriendsTimeline + this.probabilityGetRecentTweets + this.probabilitySearchPerOwner + this.probabilitySearchPerTopic + this.probabilityStartFollowing + this.probabilityStopFollowing > 1) { logger.warn("The sum of all probabilities must be less or equal than 1."); throw new ConfigurationException("The sum of all probabilities must be less or equal than 1."); } String serverName = conf.getString("benchmark.server.name"); int serverPort = conf.getInt("benchmark.server.port"); this.remoteGraphServer = this.getRemoteGraphServer(serverName, serverPort); try { this.hasInitiated = this.remoteGraphServer.init(this.totalSize); } catch (RemoteException e) { e.printStackTrace(); } }
From source file:org.zaproxy.zap.extension.authentication.ExtensionAuthentication.java
@Override public void importContextData(Context ctx, Configuration config) throws ConfigurationException { ctx.setAuthenticationMethod(getAuthenticationMethodTypeForIdentifier( config.getInt(AuthenticationMethod.CONTEXT_CONFIG_AUTH_TYPE)) .createAuthenticationMethod(ctx.getIndex())); String str = config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDIN, ""); if (str.length() > 0) { ctx.getAuthenticationMethod().setLoggedInIndicatorPattern(str); }//from w ww. ja v a2 s . com str = config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDOUT, ""); if (str.length() > 0) { ctx.getAuthenticationMethod().setLoggedOutIndicatorPattern(str); } ctx.getAuthenticationMethod().getType().importData(config, ctx.getAuthenticationMethod()); }