List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxIdle
public void setMaxIdle(int maxIdle)
From source file:net.sheehantech.cherry.pool.PooledPushClient.java
@Override public void init() throws ConnectionFailedException { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); if (maxTotal != null) config.setMaxTotal(maxTotal);//w w w. j a v a 2s .c om if (maxIdle != null) config.setMaxIdle(maxIdle); if (minIdle != null) config.setMinIdle(minIdle); config.setTestOnBorrow(true); config.setTestWhileIdle(true); config.setBlockWhenExhausted(true); pool = new GenericObjectPool<PooledPushSocket>(new PooledPushSocketFactory(socketFactory, gateway, port), config); try { pool.preparePool(); } catch (Exception e) { throw (new ConnectionFailedException(e)); } logger.debug("Started new push socket pool with {} sockets", pool.getNumIdle()); }
From source file:gobblin.hive.HiveMetastoreClientPool.java
/** * Constructor for {@link HiveMetastoreClientPool}. * @deprecated It is recommended to use the static {@link #get} method instead. Use this constructor only if you * different pool configurations are required. *//*from www .j av a2 s . co m*/ @Deprecated public HiveMetastoreClientPool(Properties properties, Optional<String> metastoreURI) { this.hiveRegProps = new HiveRegProps(new State(properties)); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(this.hiveRegProps.getNumThreads()); config.setMaxIdle(this.hiveRegProps.getNumThreads()); this.factory = new HiveMetaStoreClientFactory(metastoreURI); this.pool = new GenericObjectPool<>(this.factory, config); this.hiveConf = this.factory.getHiveConf(); }
From source file:com.lambdaworks.redis.RedisConnectionPool.java
/** * Create a new connection pool/* w ww .j a va2s . c o m*/ * * @param redisConnectionProvider the connection provider * @param maxActive max active connections * @param maxIdle max idle connections * @param maxWait max wait time (ms) for a connection */ public RedisConnectionPool(RedisConnectionProvider<T> redisConnectionProvider, int maxActive, int maxIdle, long maxWait) { this.redisConnectionProvider = redisConnectionProvider; GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxIdle(maxIdle); config.setMaxTotal(maxActive); config.setMaxWaitMillis(maxWait); config.setTestOnBorrow(true); objectPool = new GenericObjectPool<>(createFactory(redisConnectionProvider), config); }
From source file:com.reydentx.core.client.MySQLClient.java
private void _initPool() { _clientFactory = new MySqlClientFactory(_url); _maxActive = 100;/*w w w . j a va2s.co m*/ _maxIdle = 10; _maxWaitTimeWhenExhausted = 5000L; GenericObjectPoolConfig poolConf = new GenericObjectPoolConfig(); poolConf.setMaxIdle(_maxIdle); poolConf.setMaxTotal(_maxActive); poolConf.setMaxWaitMillis(_maxWaitTimeWhenExhausted); _pool = new GenericObjectPool<Connection>(_clientFactory, poolConf); }
From source file:io.lettuce.core.support.AsyncConnectionPoolSupportTest.java
@Test public void asyncPoolShouldCloseConnectionsAboveMaxIdleSize() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxIdle(2); BoundedAsyncPool<StatefulRedisConnection<String, String>> pool = AsyncConnectionPoolSupport .createBoundedObjectPool(() -> client.connectAsync(StringCodec.ASCII, uri), CommonsPool2ConfigConverter.bounded(poolConfig)); borrowAndReturn(pool);//from w ww . j a v a 2s . c om borrowAndClose(pool); StatefulRedisConnection<String, String> c1 = pool.acquire().join(); StatefulRedisConnection<String, String> c2 = pool.acquire().join(); StatefulRedisConnection<String, String> c3 = pool.acquire().join(); assertThat(channels).hasSize(3); CompletableFuture.allOf(pool.release(c1), pool.release(c2), pool.release(c3)).join(); assertThat(channels).hasSize(2); pool.close(); assertThat(channels).isEmpty(); }
From source file:com.heliosapm.streams.collector.ds.AbstractDataSourceFactory.java
/** * Reads the generic object pool configuration from the passed JSONObject * @param jsonConfig The json configuration for the current data source * @return the pool config/* w w w.ja v a 2 s . c o m*/ */ protected GenericObjectPoolConfig getPoolConfig(final JsonNode jsonConfig) { if (jsonConfig == null) throw new IllegalArgumentException("The passed JSONObject was null"); final GenericObjectPoolConfig config = new GenericObjectPoolConfig(); if (jsonConfig.has("maxPoolSize")) config.setMaxTotal(jsonConfig.get("maxPoolSize").intValue()); if (jsonConfig.has("maxPoolIdle")) config.setMaxIdle(jsonConfig.get("maxPoolIdle").intValue()); if (jsonConfig.has("minPoolIdle")) config.setMinIdle(jsonConfig.get("minPoolIdle").intValue()); if (jsonConfig.has("registerMbeans")) config.setJmxEnabled(jsonConfig.get("registerMbeans").booleanValue()); if (jsonConfig.has("fair")) config.setFairness(jsonConfig.get("fair").booleanValue()); if (jsonConfig.has("lifo")) config.setLifo(jsonConfig.get("lifo").booleanValue()); if (jsonConfig.has("maxWait")) config.setMaxWaitMillis(jsonConfig.get("maxWait").longValue()); final boolean testWhileIdle; if (jsonConfig.has("testWhileIdle")) { testWhileIdle = jsonConfig.get("testWhileIdle").booleanValue(); } else { testWhileIdle = false; } if (testWhileIdle) { config.setTestWhileIdle(true); long testPeriod = 15000; if (jsonConfig.has("testPeriod")) { testPeriod = jsonConfig.get("testPeriod").longValue(); } config.setTimeBetweenEvictionRunsMillis(testPeriod); } else { config.setTestWhileIdle(false); } // ALWAYS test on borrow config.setTestOnBorrow(true); config.setTestOnCreate(true); config.setTestOnReturn(false); return config; }
From source file:gobblin.kafka.schemareg.LiKafkaSchemaRegistry.java
/** * @param props properties should contain property "kafka.schema.registry.url", and optionally * "kafka.schema.registry.max.cache.size" (default = 1000) and * "kafka.schema.registry.cache.expire.after.write.min" (default = 10). *//*from w w w . j a va2s. c om*/ public LiKafkaSchemaRegistry(Properties props) { Preconditions.checkArgument( props.containsKey(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_URL), String.format("Property %s not provided.", KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_URL)); this.url = props.getProperty(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_URL); int objPoolSize = Integer .parseInt(props.getProperty(ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_THREADS, "" + ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_DEFAULT_THREAD_COUNT)); LOG.info("Create HttpClient pool with size " + objPoolSize); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(objPoolSize); config.setMaxIdle(objPoolSize); this.httpClientPool = new GenericObjectPool<>(new HttpClientFactory(), config); }
From source file:com.streamsets.pipeline.stage.origin.sdcipctokafka.IpcToKafkaServlet.java
@Override public void init() throws ServletException { super.init(); int max = configs.maxConcurrentRequests; int minIdle = Math.max(1, configs.maxConcurrentRequests / 4); int maxIdle = configs.maxConcurrentRequests / 2; GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(max);//w ww.j a v a2 s. com poolConfig.setMinIdle(minIdle); poolConfig.setMaxIdle(maxIdle); LOG.debug("Creating Kafka producer pool with max '{}' minIdle '{}' maxIdle '{}'", max, minIdle, maxIdle); kafkaProducerPool = new GenericObjectPool<>(new SdcKafkaProducerPooledObjectFactory(configs), poolConfig); }
From source file:gobblin.metrics.kafka.KafkaAvroSchemaRegistry.java
/** * @param properties properties should contain property "kafka.schema.registry.url", and optionally * "kafka.schema.registry.max.cache.size" (default = 1000) and * "kafka.schema.registry.cache.expire.after.write.min" (default = 10). *///from w w w . j av a 2 s. co m public KafkaAvroSchemaRegistry(Properties props) { super(props); Preconditions.checkArgument(props.containsKey(KAFKA_SCHEMA_REGISTRY_URL), String.format("Property %s not provided.", KAFKA_SCHEMA_REGISTRY_URL)); this.url = props.getProperty(KAFKA_SCHEMA_REGISTRY_URL); int objPoolSize = Integer .parseInt(props.getProperty(ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_THREADS, "" + ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_DEFAULT_THREAD_COUNT)); LOG.info("Create HttpClient pool with size " + objPoolSize); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(objPoolSize); config.setMaxIdle(objPoolSize); this.httpClientPool = new GenericObjectPool<>(new HttpClientFactory(), config); }
From source file:com.streamsets.pipeline.stage.origin.ipctokafka.IpcToKafkaServlet.java
@Override public void init() throws ServletException { super.init(); int max = configs.maxConcurrentRequests; int minIdle = Math.max(1, configs.maxConcurrentRequests / 4); int maxIdle = configs.maxConcurrentRequests / 2; GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(max);/*from w ww . j a va 2 s. c o m*/ poolConfig.setMinIdle(minIdle); poolConfig.setMaxIdle(maxIdle); LOG.debug("Creating Kafka producer pool with max '{}' minIdle '{}' maxIdle '{}'", max, minIdle, maxIdle); kafkaProducerPool = new GenericObjectPool<>( new SdcKafkaProducerPooledObjectFactory(kafkaConfigBean.kafkaConfig, DataFormat.SDC_JSON), poolConfig); }