List of usage examples for org.apache.commons.pool2.impl GenericObjectPoolConfig setMaxTotal
public void setMaxTotal(int maxTotal)
From source file:org.apache.flink.streaming.connectors.redis.common.container.RedisCommandsContainerBuilder.java
/** * Builds container for Redis Sentinel environment. * * @param jedisSentinelConfig configuration for JedisSentinel * @return container for Redis sentinel environment * @throws NullPointerException if jedisSentinelConfig is null *//*from ww w .java 2 s .c om*/ public static RedisCommandsContainer build(FlinkJedisSentinelConfig jedisSentinelConfig) { Preconditions.checkNotNull(jedisSentinelConfig, "Redis sentinel config should not be Null"); GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig(); genericObjectPoolConfig.setMaxIdle(jedisSentinelConfig.getMaxIdle()); genericObjectPoolConfig.setMaxTotal(jedisSentinelConfig.getMaxTotal()); genericObjectPoolConfig.setMinIdle(jedisSentinelConfig.getMinIdle()); JedisSentinelPool jedisSentinelPool = new JedisSentinelPool(jedisSentinelConfig.getMasterName(), jedisSentinelConfig.getSentinels(), genericObjectPoolConfig, jedisSentinelConfig.getConnectionTimeout(), jedisSentinelConfig.getSoTimeout(), jedisSentinelConfig.getPassword(), jedisSentinelConfig.getDatabase()); return new RedisContainer(jedisSentinelPool); }
From source file:org.apache.gobblin.hive.metastore.HiveMetaStoreBasedRegister.java
public HiveMetaStoreBasedRegister(State state, Optional<String> metastoreURI) throws IOException { super(state); this.optimizedChecks = state.getPropAsBoolean(this.OPTIMIZED_CHECK_ENABLED, true); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(this.props.getNumThreads()); config.setMaxIdle(this.props.getNumThreads()); this.clientPool = HiveMetastoreClientPool.get(this.props.getProperties(), metastoreURI); this.metricContext = GobblinMetricsRegistry.getInstance().getMetricContext(state, HiveMetaStoreBasedRegister.class, GobblinMetrics.getCustomTagsFromState(state)); this.eventSubmitter = new EventSubmitter.Builder(this.metricContext, "org.apache.gobblin.hive.HiveMetaStoreBasedRegister").build(); }
From source file:org.apache.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). */// w w w .j av a2 s . com 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); this.namespaceOverride = KafkaAvroReporterUtil.extractOverrideNamespace(props); this.switchTopicNames = PropertiesUtils.getPropAsBoolean(props, KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_SWITCH_NAME, KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_SWITCH_NAME_DEFAULT); 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:org.apache.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 ww . j a v a2s . c om 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); this.namespaceOverride = KafkaAvroReporterUtil.extractOverrideNamespace(props); 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); HttpClientFactory factory = new HttpClientFactory(); if (this.props.containsKey(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_SO_TIMEOUT)) { String soTimeout = this.props .getProperty(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_SO_TIMEOUT); factory.setSoTimeout(Integer.parseInt(soTimeout)); } if (this.props.containsKey(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_CONN_TIMEOUT)) { String connTimeout = this.props .getProperty(ConfigurationKeys.KAFKA_SCHEMA_REGISTRY_HTTPCLIENT_CONN_TIMEOUT); factory.setConnTimeout(Integer.parseInt(connTimeout)); } this.httpClientPool = new GenericObjectPool<>(factory, config); }
From source file:org.apache.ofbiz.entity.connection.DBCPConnectionFactory.java
public Connection getConnection(GenericHelperInfo helperInfo, JdbcElement abstractJdbc) throws SQLException, GenericEntityException { String cacheKey = helperInfo.getHelperFullName(); DebugManagedDataSource mds = dsCache.get(cacheKey); if (mds != null) { return TransactionUtil.getCursorConnection(helperInfo, mds.getConnection()); }//from www . ja v a 2 s . c o m if (!(abstractJdbc instanceof InlineJdbc)) { throw new GenericEntityConfException( "DBCP requires an <inline-jdbc> child element in the <datasource> element"); } InlineJdbc jdbcElement = (InlineJdbc) abstractJdbc; // connection properties TransactionManager txMgr = TransactionFactoryLoader.getInstance().getTransactionManager(); String driverName = jdbcElement.getJdbcDriver(); String jdbcUri = helperInfo.getOverrideJdbcUri(jdbcElement.getJdbcUri()); String jdbcUsername = helperInfo.getOverrideUsername(jdbcElement.getJdbcUsername()); String jdbcPassword = helperInfo.getOverridePassword(EntityConfig.getJdbcPassword(jdbcElement)); // pool settings int maxSize = jdbcElement.getPoolMaxsize(); int minSize = jdbcElement.getPoolMinsize(); int maxIdle = jdbcElement.getIdleMaxsize(); // maxIdle must be greater than pool-minsize maxIdle = maxIdle > minSize ? maxIdle : minSize; // load the driver Driver jdbcDriver; synchronized (DBCPConnectionFactory.class) { // Sync needed for MS SQL JDBC driver. See OFBIZ-5216. try { jdbcDriver = (Driver) Class .forName(driverName, true, Thread.currentThread().getContextClassLoader()).newInstance(); } catch (Exception e) { Debug.logError(e, module); throw new GenericEntityException(e.getMessage(), e); } } // connection factory properties Properties cfProps = new Properties(); cfProps.put("user", jdbcUsername); cfProps.put("password", jdbcPassword); // create the connection factory org.apache.commons.dbcp2.ConnectionFactory cf = new DriverConnectionFactory(jdbcDriver, jdbcUri, cfProps); // wrap it with a LocalXAConnectionFactory XAConnectionFactory xacf = new LocalXAConnectionFactory(txMgr, cf); // create the pool object factory PoolableConnectionFactory factory = new PoolableManagedConnectionFactory(xacf, null); factory.setValidationQuery(jdbcElement.getPoolJdbcTestStmt()); factory.setDefaultReadOnly(false); factory.setRollbackOnReturn(false); factory.setEnableAutoCommitOnReturn(false); String transIso = jdbcElement.getIsolationLevel(); if (!transIso.isEmpty()) { if ("Serializable".equals(transIso)) { factory.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); } else if ("RepeatableRead".equals(transIso)) { factory.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); } else if ("ReadUncommitted".equals(transIso)) { factory.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } else if ("ReadCommitted".equals(transIso)) { factory.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } else if ("None".equals(transIso)) { factory.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE); } } // configure the pool settings GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(maxSize); // settings for idle connections poolConfig.setMaxIdle(maxIdle); poolConfig.setMinIdle(minSize); poolConfig.setTimeBetweenEvictionRunsMillis(jdbcElement.getTimeBetweenEvictionRunsMillis()); poolConfig.setMinEvictableIdleTimeMillis(-1); // disabled in favour of setSoftMinEvictableIdleTimeMillis(...) poolConfig.setSoftMinEvictableIdleTimeMillis(jdbcElement.getSoftMinEvictableIdleTimeMillis()); poolConfig.setNumTestsPerEvictionRun(maxSize); // test all the idle connections // settings for when the pool is exhausted poolConfig.setBlockWhenExhausted(true); // the thread requesting the connection waits if no connection is available poolConfig.setMaxWaitMillis(jdbcElement.getPoolSleeptime()); // throw an exception if, after getPoolSleeptime() ms, no connection is available for the requesting thread // settings for the execution of the validation query poolConfig.setTestOnCreate(jdbcElement.getTestOnCreate()); poolConfig.setTestOnBorrow(jdbcElement.getTestOnBorrow()); poolConfig.setTestOnReturn(jdbcElement.getTestOnReturn()); poolConfig.setTestWhileIdle(jdbcElement.getTestWhileIdle()); GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(factory, poolConfig); factory.setPool(pool); mds = new DebugManagedDataSource(pool, xacf.getTransactionRegistry()); mds.setAccessToUnderlyingConnectionAllowed(true); // cache the pool dsCache.putIfAbsent(cacheKey, mds); mds = dsCache.get(cacheKey); return TransactionUtil.getCursorConnection(helperInfo, mds.getConnection()); }
From source file:org.apache.omid.tso.BatchPoolModule.java
@Provides @Singleton// w w w . jav a2s. c o m ObjectPool<Batch> getBatchPool() throws Exception { int poolSize = config.getNumConcurrentCTWriters(); int batchSize = config.getBatchSizePerCTWriter(); LOG.info("Pool Size (# of Batches) {}; Batch Size {}", poolSize, batchSize); LOG.info("Total Batch Size (Pool size * Batch Size): {}", poolSize * batchSize); GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(poolSize); config.setBlockWhenExhausted(true); GenericObjectPool<Batch> batchPool = new GenericObjectPool<>(new Batch.BatchFactory(batchSize), config); LOG.info("Pre-creating objects in the pool..."); // TODO There should be a better way to do this List<Batch> batches = new ArrayList<>(poolSize); for (int i = 0; i < poolSize; i++) { batches.add(batchPool.borrowObject()); } for (Batch batch : batches) { batchPool.returnObject(batch); } return batchPool; }
From source file:org.atmosphere.cpr.PoolableBroadcasterFactoryTest.java
@Test public void testImplementation() { assertNotNull(factory.poolableProvider()); assertNotNull(factory.poolableProvider().implementation()); assertEquals(factory.poolableProvider().implementation().getClass(), GenericObjectPool.class); GenericObjectPool nativePool = (GenericObjectPool) factory.poolableProvider().implementation(); assertTrue(nativePool.getLifo());/*from w w w .j av a2 s.c o m*/ GenericObjectPoolConfig c = new GenericObjectPoolConfig(); c.setMaxTotal(1); nativePool.setConfig(c); assertEquals(1, nativePool.getMaxTotal()); }
From source file:org.bigbluebutton.common2.redis.RedisAwareCommunicator.java
protected GenericObjectPoolConfig createPoolingConfig() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(32); config.setMaxIdle(8);//from www. j a va 2 s .c o m config.setMinIdle(1); config.setTestOnBorrow(true); config.setTestOnReturn(true); config.setTestWhileIdle(true); config.setNumTestsPerEvictionRun(12); config.setMaxWaitMillis(5000); config.setTimeBetweenEvictionRunsMillis(60000); config.setBlockWhenExhausted(true); return config; }
From source file:org.bigbluebutton.core.service.recorder.RedisDispatcher.java
public RedisDispatcher(String host, int port, String password, int keysExpiresInSec) { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(32); config.setMaxIdle(8);/*from w ww . j a v a2 s .c o m*/ config.setMinIdle(1); config.setTestOnBorrow(true); config.setTestOnReturn(true); config.setTestWhileIdle(true); config.setNumTestsPerEvictionRun(12); config.setMaxWaitMillis(5000); config.setTimeBetweenEvictionRunsMillis(60000); config.setBlockWhenExhausted(true); this.keysExpiresInSec = keysExpiresInSec; // Set the name of this client to be able to distinguish when doing // CLIENT LIST on redis-cli redisPool = new JedisPool(config, host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, "BbbAppsAkkaRec"); }
From source file:org.cloudgraph.hbase.connect.HBaseConnectionManager.java
private HBaseConnectionManager() { this.config = CloudGraphContext.instance().getConfig(); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal( this.config.getInt(CONNECTION_POOL_MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL)); if (this.config.get(CONNECTION_POOL_MAX_SIZE) != null) poolConfig.setMaxTotal(// ww w . j a v a2s . c om this.config.getInt(CONNECTION_POOL_MAX_SIZE, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL)); poolConfig .setMaxIdle(this.config.getInt(CONNECTION_POOL_MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE)); poolConfig .setMinIdle(this.config.getInt(CONNECTION_POOL_MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE)); if (this.config.get(CONNECTION_POOL_MIN_SIZE) != null) poolConfig.setMinIdle( this.config.getInt(CONNECTION_POOL_MIN_SIZE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE)); poolConfig.setLifo(this.config.getBoolean(CONNECTION_POOL_LIFO, GenericObjectPoolConfig.DEFAULT_LIFO)); poolConfig.setMaxWaitMillis(this.config.getLong(CONNECTION_POOL_MAX_WAIT_MILLIS, GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS)); // eviction poolConfig.setTimeBetweenEvictionRunsMillis( this.config.getLong(CONNECTION_POOL_TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS)); poolConfig.setEvictionPolicyClassName(this.config.get(CONNECTION_POOL_EVICTION_POLICY_CLASS_NAME, GenericObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME)); poolConfig.setMinEvictableIdleTimeMillis(this.config.getLong(CONNECTION_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS, GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); poolConfig.setSoftMinEvictableIdleTimeMillis( this.config.getLong(CONNECTION_POOL_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS)); poolConfig.setNumTestsPerEvictionRun(this.config.getInt(CONNECTION_POOL_NUM_TESTS_PER_EVICTION_RUN, GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN)); poolConfig.setTestOnCreate(this.config.getBoolean(CONNECTION_POOL_TEST_ON_CREATE, GenericObjectPoolConfig.DEFAULT_TEST_ON_CREATE)); poolConfig.setTestOnBorrow(this.config.getBoolean(CONNECTION_POOL_TEST_ON_BORROW, GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW)); poolConfig.setTestOnReturn(this.config.getBoolean(CONNECTION_POOL_TEST_ON_RETURN, GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN)); poolConfig.setTestWhileIdle(this.config.getBoolean(CONNECTION_POOL_TEST_WHILE_IDLE, GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE)); poolConfig.setBlockWhenExhausted(this.config.getBoolean(CONNECTION_POOL_BLOCK_WHEN_EXHAUSTED, GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED)); poolConfig.setJmxEnabled(this.config.getBoolean(CONNECTION_POOL_JMX_ENABLED, false)); poolConfig.setJmxNameBase( this.config.get(CONNECTION_POOL_JMX_NAME_BASE, GenericObjectPoolConfig.DEFAULT_JMX_NAME_BASE)); poolConfig.setJmxNamePrefix( this.config.get(CONNECTION_POOL_JMX_NAME_PREFIX, GenericObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX)); PooledConnectionFactory factory = new PooledConnectionFactory(this.config); this.pool = new GenericObjectPool<Connection>(factory, poolConfig); factory.setPool(pool); log.info("created connection pool[ " + "\n\tMaxTotal:\t\t" + poolConfig.getMaxTotal() + "\n\tMinIdle:\t\t" + poolConfig.getMinIdle() + "\n\tMaxIdle:\t\t" + poolConfig.getMaxIdle() + "\n\tLifo:\t\t" + poolConfig.getLifo() + "\n\tMaxWaitMillis:\t\t" + poolConfig.getMaxWaitMillis() + "\n\tTimeBetweenEvictionRunsMillis:\t\t" + poolConfig.getTimeBetweenEvictionRunsMillis() + "\n\tEvictionPolicyClassName:\t\t" + poolConfig.getEvictionPolicyClassName() + "\n\tMinEvictableIdleTimeMillis:\t\t" + poolConfig.getMinEvictableIdleTimeMillis() + "\n\tSoftMinEvictableIdleTimeMillis:\t\t" + poolConfig.getSoftMinEvictableIdleTimeMillis() + "\n\tNumTestsPerEvictionRun:\t\t" + poolConfig.getNumTestsPerEvictionRun() + "\n...]"); }