Java Code Examples for org.apache.commons.pool2.impl.GenericObjectPoolConfig

The following examples show how to use org.apache.commons.pool2.impl.GenericObjectPoolConfig. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: x-pipe   Source File: AbstractTestMode.java    License: Apache License 2.0 6 votes vote down vote up
public AbstractTestMode(HostPort master, List<HostPort> slaves, int producerThreadNum, int producerIntervalMicro, int msgSize, long maxKeys) {
    this.master = master;
    this.slaves = slaves;
    this.producerThreadNum = producerThreadNum;
    this.producerIntervalMicro = producerIntervalMicro;
    this.maxKeys = maxKeys;

    producerThreadPool = Executors.newScheduledThreadPool(producerThreadNum,
            XpipeThreadFactory.create("ProducerThreadPool"));
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(producerThreadNum * 3);
    dataPool = new GenericObjectPool<>(new BytesFactory(msgSize), config);
    consumerThreadPool = Executors.newFixedThreadPool(slaves.size() * 2 + 1, XpipeThreadFactory.create("ConsumerThreadPool"));
    qpsCheckThreadPool = Executors.newScheduledThreadPool(1, XpipeThreadFactory.create("QpsCheckThreadPool"));

    masterPool = getJedisPool(master.getHost(), master.getPort(), producerThreadNum * 2, producerThreadNum);
    beginSend = new DelayManager(qpsCheckThreadPool, "beginsend", master.toString(), TIME_TOO_LONG_TO_LOG_MILLI, false);
    slaves.forEach((slave) -> allDelays.put(slave, new DelayManager(qpsCheckThreadPool, "delay", String.format("%s.%d.%d.%d", slave.getHost(), slave.getPort(), producerThreadNum, producerIntervalMicro), TIME_TOO_LONG_TO_LOG_MILLI)));
    slaves.forEach((slave) -> slavePools.put(slave, getJedisPool(slave.getHost(), slave.getPort(), 2, 2)));

}
 
Example 2
Source Project: cuba   Source File: KryoSerialization.java    License: Apache License 2.0 6 votes vote down vote up
protected void initPool() {
    // assume that application context is already initialized
    Configuration configuration = AppBeans.get(Configuration.NAME);
    config = configuration.getConfig(KryoSerializationConfig.class);

    int poolSize = config.getMaxPoolSize();
    GenericObjectPoolConfig<Kryo> poolConfig = new GenericObjectPoolConfig<>();
    poolConfig.setMaxIdle(poolSize);
    poolConfig.setMaxTotal(poolSize);
    poolConfig.setMaxWaitMillis(config.getMaxBorrowWaitMillis());

    String jmxName = "kryo-" + AppContext.getProperty("cuba.webContextName");
    poolConfig.setJmxNamePrefix(jmxName);

    PooledObjectFactory<Kryo> factory = new KryoObjectFactory(this);
    pool = new GenericObjectPool<>(factory, poolConfig);
    log.debug("Kryo context pool created");
}
 
Example 3
Source Project: pepper-metrics   Source File: PjedisPool.java    License: Apache License 2.0 6 votes vote down vote up
public PjedisPool(final String host) {
  URI uri = URI.create(host);
  if (JedisURIHelper.isValid(uri)) {
    String h = uri.getHost();
    int port = uri.getPort();
    String password = JedisURIHelper.getPassword(uri);
    int database = JedisURIHelper.getDBIndex(uri);
    boolean ssl = uri.getScheme().equals("rediss");
    this.internalPool = new GenericObjectPool<Jedis>(new PjedisFactory(h, port,
        Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null,
          ssl, null, null, null), new GenericObjectPoolConfig());
  } else {
    this.internalPool = new GenericObjectPool<Jedis>(new PjedisFactory(host,
        Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
        Protocol.DEFAULT_DATABASE, null, false, null, null, null), new GenericObjectPoolConfig());
  }
}
 
Example 4
Source Project: commons-pool   Source File: BaseTestProxiedObjectPool.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    log = new StringWriter();

    final PrintWriter pw = new PrintWriter(log);
    final AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setLogAbandoned(true);
    abandonedConfig.setRemoveAbandonedOnBorrow(true);
    abandonedConfig.setUseUsageTracking(true);
    abandonedConfig.setRemoveAbandonedTimeout(ABANDONED_TIMEOUT_SECS);
    abandonedConfig.setLogWriter(pw);

    final GenericObjectPoolConfig<TestObject> config = new GenericObjectPoolConfig<>();
    config.setMaxTotal(3);

    final PooledObjectFactory<TestObject> factory = new TestObjectFactory();

    @SuppressWarnings("resource")
    final ObjectPool<TestObject> innerPool =
            new GenericObjectPool<>(factory, config, abandonedConfig);

    pool = new ProxiedObjectPool<>(innerPool, getproxySource());
}
 
Example 5
Source Project: Thunder   Source File: ObjectPoolFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static GenericObjectPoolConfig createFSTObjectPoolConfig() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    try {
        config.setMaxTotal(ThunderConstant.CPUS * properties.getInteger(ThunderConstant.FST_OBJECT_POOL_MAX_TOTAL_ATTRIBUTE_NAME));
        config.setMaxIdle(ThunderConstant.CPUS * properties.getInteger(ThunderConstant.FST_OBJECT_POOL_MAX_IDLE_ATTRIBUTE_NAME));
        config.setMinIdle(ThunderConstant.CPUS * properties.getInteger(ThunderConstant.FST_OBJECT_POOL_MIN_IDLE_ATTRIBUTE_NAME));
        config.setMaxWaitMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_MAX_WAIT_MILLIS_ATTRIBUTE_NAME));
        config.setTimeBetweenEvictionRunsMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_TIME_BETWEEN_EVICTION_RUN_MILLIS_ATTRIBUTE_NAME));
        config.setMinEvictableIdleTimeMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS_ATTRIBUTE_NAME));
        config.setSoftMinEvictableIdleTimeMillis(properties.getLong(ThunderConstant.FST_OBJECT_POOL_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS_ATTRIBUTE_NAME));
        config.setBlockWhenExhausted(properties.getBoolean(ThunderConstant.FST_OBJECT_POOL_BLOCK_WHEN_EXHAUSTED_ATTRIBUTE_NAME));
        config.setLifo(properties.getBoolean(ThunderConstant.FST_OBJECT_POOL_LIFO_ATTRIBUTE_NAME));
        config.setFairness(properties.getBoolean(ThunderConstant.FST_OBJECT_POOL_FAIRNESS_ATTRIBUTE_NAME));
        config.setTestOnBorrow(false);
        config.setTestOnReturn(false);
        config.setTestOnCreate(false);
        config.setTestWhileIdle(false);
        config.setNumTestsPerEvictionRun(-1);
    } catch (Exception e) {
        throw new IllegalArgumentException("Properties maybe isn't initialized");
    }

    return config;
}
 
Example 6
Source Project: cachecloud   Source File: JedisClusterConnectionHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void initializeSlotsCache(Set<HostAndPort> startNodes, GenericObjectPoolConfig poolConfig) {
  for (HostAndPort hostAndPort : startNodes) {
    Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort());
    try {
      cache.discoverClusterNodesAndSlots(jedis);
      break;
    } catch (JedisConnectionException e) {
      // try next nodes
    } finally {
      if (jedis != null) {
        jedis.close();
      }
    }
  }

  for (HostAndPort node : startNodes) {
    cache.setNodeIfNotExist(node);
  }
}
 
Example 7
@Override
protected void useBundleClasses() throws Exception
{
    new LdapNetworkConnection().close();
    new SaslGssApiRequest();
    new Krb5LoginConfiguration();
    new AddFuture( new LdapNetworkConnection(), 2 );
    new LdapConnectionTemplate( new LdapConnectionPool( new DefaultPoolableLdapConnectionFactory(
        new LdapConnectionConfig() ) ) );
    FilterBuilder.and( FilterBuilder.not( FilterBuilder.contains( "cn", "a", "b" ) ) ).toString();

    // Test for DIRAPI-239
    PooledObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(
        new LdapConnectionConfig() );
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    LdapConnectionPool ldapConnectionPool = new LdapConnectionPool( factory, config );
    ldapConnectionPool.getLdapApiService();
    ldapConnectionPool.getTestOnBorrow();
    ldapConnectionPool.close();
}
 
Example 8
Source Project: dubbo-plus   Source File: GenerateEhCacheDefaultConfig.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IllegalAccessException {
    CacheManager manager = CacheManager.create();
    Configuration configuration = manager.getConfiguration();
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    Object object= poolConfig;
    Field[] fields = object.getClass().getDeclaredFields();
    String prefix="cache.ehcache.";
    for(Field field:fields){
       field.setAccessible(true);
        Method method = getSetMethod(object.getClass(),field);
        if(method!=null&& CacheConfig.checkIsBasicType(field.getType())){
            System.out.println("#默认值"+field.get(object));
            System.out.println(prefix+field.getName());
        }
    }
}
 
Example 9
Source Project: spring-analysis-note   Source File: CommonsPool2TargetSource.java    License: MIT License 5 votes vote down vote up
/**
 * Subclasses can override this if they want to return a specific Commons pool.
 * They should apply any configuration properties to the pool here.
 * <p>Default is a GenericObjectPool instance with the given pool size.
 * @return an empty Commons {@code ObjectPool}.
 * @see GenericObjectPool
 * @see #setMaxSize
 */
protected ObjectPool createObjectPool() {
	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setMaxTotal(getMaxSize());
	config.setMaxIdle(getMaxIdle());
	config.setMinIdle(getMinIdle());
	config.setMaxWaitMillis(getMaxWait());
	config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
	config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
	config.setBlockWhenExhausted(isBlockWhenExhausted());
	return new GenericObjectPool(this, config);
}
 
Example 10
Source Project: proctor   Source File: SvnObjectPools.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> ObjectPool<T> createObjectPool(final PooledObjectFactory<T> factory) {
    final GenericObjectPoolConfig objectPoolConfig = new GenericObjectPoolConfig();
    objectPoolConfig.setMinEvictableIdleTimeMillis(TimeUnit.HOURS.toMillis(1)); // arbitrary, but positive so objects do get evicted
    objectPoolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES.toMillis(10)); // arbitrary, but positive so objects do get evicted
    objectPoolConfig.setJmxEnabled(false);
    objectPoolConfig.setBlockWhenExhausted(false);
    objectPoolConfig.setMaxTotal(-1); // uncapped number of objects in the pool
    final AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setRemoveAbandonedOnBorrow(true);
    abandonedConfig.setRemoveAbandonedTimeout((int) TimeUnit.MINUTES.toSeconds(30));
    return new GenericObjectPool<T>(factory, objectPoolConfig, abandonedConfig);
}
 
Example 11
Source Project: jframe   Source File: Mqttv3ClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
public void init(InputStream file) throws Exception {
    MqttClientConf props = new MqttClientConf();
    props.init(file);

    String[] ids = props.getGroupIds();
    clnt = new HashMap<>(ids.length, 1);
    for (String id : ids) {
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        config.setMaxTotal(props.getConfInt(id, MqttClientConf.F_pool_maxTotal, "100"));
        config.setMaxIdle(props.getConfInt(id, MqttClientConf.F_pool_maxIdle, "10"));
        config.setMinIdle(props.getConfInt(id, MqttClientConf.F_pool_minIdle, "1"));
        clnt.put(id, new GenericObjectPool<IMqttAsyncClient>(new MqttAsyncClientFactory(id, props), config));
    }
}
 
Example 12
Source Project: java-redis-client   Source File: TracingJedisCluster.java    License: Apache License 2.0 5 votes vote down vote up
public TracingJedisCluster(HostAndPort node, int connectionTimeout, int soTimeout,
    int maxAttempts,
    String password, GenericObjectPoolConfig poolConfig,
    TracingConfiguration tracingConfiguration) {
  super(node, connectionTimeout, soTimeout, maxAttempts, password, poolConfig);
  this.helper = new TracingHelper(tracingConfiguration);
}
 
Example 13
private void configurePool(LettuceClientConfigurationBuilder clientConfiguration, PooledServiceConnectorConfig config) {
	if (config.getPoolConfig() != null) {
		GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
		BeanWrapper target = new BeanWrapperImpl(poolConfig);
		BeanWrapper source = new BeanWrapperImpl(config.getPoolConfig());
		Util.setCorrespondingProperties(target, source);

		((LettucePoolingClientConfigurationBuilder) clientConfiguration).poolConfig(poolConfig);
	}
}
 
Example 14
Source Project: kork   Source File: RedisClientConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean("previousJedisCluster")
@ConditionalOnProperty(value = "redis.previous-cluster-enabled")
public JedisCluster previousJedisCluster(
    GenericObjectPoolConfig objectPoolConfig, ClientConfigurationWrapper config) {
  URI cx = URI.create(config.connectionPrevious);
  return getJedisCluster(objectPoolConfig, config, cx);
}
 
Example 15
Source Project: java-redis-client   Source File: TracingJedisPool.java    License: Apache License 2.0 5 votes vote down vote up
public TracingJedisPool(final GenericObjectPoolConfig poolConfig, final String host,
    final int port, final int timeout,
    final String password, final int database, final String clientName,
    TracingConfiguration tracingConfiguration) {
  this(poolConfig, host, port, timeout, timeout, password, database, clientName, false,
      null, null, null, tracingConfiguration);
}
 
Example 16
Source Project: commons-dbcp   Source File: BasicDataSource.java    License: Apache License 2.0 5 votes vote down vote up
private void updateJmxName(final GenericObjectPoolConfig<?> config) {
    if (registeredJmxObjectName == null) {
        return;
    }
    final StringBuilder base = new StringBuilder(registeredJmxObjectName.toString());
    base.append(Constants.JMX_CONNECTION_POOL_BASE_EXT);
    config.setJmxNameBase(base.toString());
    config.setJmxNamePrefix(Constants.JMX_CONNECTION_POOL_PREFIX);
}
 
Example 17
Source Project: game-server   Source File: JedisManager.java    License: MIT License 5 votes vote down vote up
public JedisManager(JedisClusterConfig config) {
	HashSet<HostAndPort> jedisClusterNodes = new HashSet<>();
	config.getNodes().forEach(node -> {
		if (node == null) {
			return;
		}
		try {
			if (node.getIp() != null && node.getIp().length() > 5) {
				jedisClusterNodes.add(new HostAndPort(node.getIp(), node.getPort()));
			}
		} catch (Exception e) {
			LOGGER.error(node.toString(), e);
		}
	});
	GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
	poolConfig.setMaxTotal(config.getPoolMaxTotal());
	poolConfig.setMaxIdle(config.getPoolMaxIdle());
	poolConfig.setMaxWaitMillis(config.getMaxWaitMillis());
	poolConfig.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis());
	poolConfig.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis());
	poolConfig.setSoftMinEvictableIdleTimeMillis(config.getSoftMinEvictableIdleTimeMillis());
	poolConfig.setTestOnBorrow(config.isTestOnBorrow());
	poolConfig.setTestWhileIdle(config.isTestWhileIdle());
	poolConfig.setTestOnReturn(config.isTestOnReturn());
	jedisCluster = new JedisCluster(jedisClusterNodes, config.getConnectionTimeout(), config.getSoTimeout(),
			config.getMaxRedirections(), poolConfig);
}
 
Example 18
Source Project: java-redis-client   Source File: TracingJedisPool.java    License: Apache License 2.0 5 votes vote down vote up
public TracingJedisPool(final GenericObjectPoolConfig poolConfig, final URI uri,
    final SSLSocketFactory sslSocketFactory,
    final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier,
    TracingConfiguration tracingConfiguration) {
  super(poolConfig, uri, sslSocketFactory, sslParameters, hostnameVerifier);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example 19
public ProtostuffSerializePool(final int maxTotal, final int minIdle, final long maxWaitMillis, final long minEvictableIdleTimeMillis) {
    protostuffPool = new GenericObjectPool<>(new ProtostuffSerializeFactory());
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(maxTotal);
    config.setMinIdle(minIdle);
    config.setMaxWaitMillis(maxWaitMillis);
    config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    protostuffPool.setConfig(config);
}
 
Example 20
Source Project: cachecloud   Source File: JedisPoolTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");

  Jedis jedis = pool.getResource();
  try {
    jedis.set("hello", "jedis");
    Transaction t = jedis.multi();
    t.set("hello", "world");
  } finally {
    jedis.close();
  }

  Jedis jedis2 = pool.getResource();
  try {
    assertTrue(jedis == jedis2);
    assertEquals("jedis", jedis2.get("hello"));
  } finally {
    jedis2.close();
  }

  pool.destroy();
  assertTrue(pool.isClosed());
}
 
Example 21
Source Project: java-redis-client   Source File: TracingJedisPool.java    License: Apache License 2.0 5 votes vote down vote up
public TracingJedisPool(final GenericObjectPoolConfig poolConfig, final String host,
    final int port,
    final int timeout, final String password, final boolean ssl,
    final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
    final HostnameVerifier hostnameVerifier, TracingConfiguration tracingConfiguration) {
  super(poolConfig, host, port, timeout, password, ssl, sslSocketFactory, sslParameters,
      hostnameVerifier);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example 22
public TracingJedisSentinelPool(TracingConfiguration tracingConfiguration, String masterName,
    Set<String> sentinels,
    final GenericObjectPoolConfig poolConfig) {
  super(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, null,
      Protocol.DEFAULT_DATABASE);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example 23
public void initPool(final GenericObjectPoolConfig poolConfig, PooledObjectFactory<T> factory) {

    if (this.internalPool != null) {
      try {
        closeInternalPool();
      } catch (Exception e) {
      }
    }

    this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
  }
 
Example 24
Source Project: AutoLoadCache   Source File: DataLoaderFactory.java    License: Apache License 2.0 5 votes vote down vote up
private DataLoaderFactory() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1024);
    config.setMaxIdle(50);
    config.setMinIdle(8);
    // 当Pool中没有对象时不等待,而是直接new个新的
    config.setBlockWhenExhausted(false);

    AbandonedConfig abandonConfig = new AbandonedConfig();
    abandonConfig.setRemoveAbandonedTimeout(300);
    abandonConfig.setRemoveAbandonedOnBorrow(true);
    abandonConfig.setRemoveAbandonedOnMaintenance(true);
    factory = new GenericObjectPool<DataLoader>(this, config, abandonConfig);
}
 
Example 25
Source Project: pepper-metrics   Source File: PjedisPool.java    License: Apache License 2.0 5 votes vote down vote up
public PjedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port,
                 int timeout, final String password, final int database, final String clientName,
                 final boolean ssl, final SSLSocketFactory sslSocketFactory,
                 final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
  this(poolConfig, host, port, timeout, timeout, password, database, clientName, ssl,
          sslSocketFactory, sslParameters, hostnameVerifier);
}
 
Example 26
Source Project: migration-tool   Source File: SerConnInstance.java    License: Apache License 2.0 5 votes vote down vote up
private void init_pool_config() {
	config = new GenericObjectPoolConfig();
	config.setLifo(Config.getBoolean("lifo"));
	config.setMaxTotal(Config.getInt("maxTotal"));
	config.setMaxIdle(Config.getInt("maxIdle"));
	config.setMaxWaitMillis(Config.getLong("maxWait"));
	config.setMinEvictableIdleTimeMillis(Config.getLong("minEvictableIdleTimeMillis"));
	config.setMinIdle(Config.getInt("minIdle"));
	config.setNumTestsPerEvictionRun(Config.getInt("numTestsPerEvictionRun"));
	config.setTestOnBorrow(Config.getBoolean("testOnBorrow"));
	config.setTestOnReturn(Config.getBoolean("testOnReturn"));
	config.setTestWhileIdle(Config.getBoolean("testWhileIdle"));
	config.setTimeBetweenEvictionRunsMillis(Config.getLong("timeBetweenEvictionRunsMillis"));
}
 
Example 27
Source Project: MtgDesktopCompanion   Source File: DBCPPool.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initDefault() {
	setProperty("defaultAutoCommit",TRUE);
	setProperty("cacheState",TRUE);
	setProperty("lifo",String.valueOf(BaseObjectPoolConfig.DEFAULT_LIFO));
	setProperty("maxTotal",String.valueOf(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL));
	setProperty("maxIdle",String.valueOf(GenericObjectPoolConfig.DEFAULT_MAX_IDLE));
	setProperty("minIdle",String.valueOf(GenericObjectPoolConfig.DEFAULT_MIN_IDLE));
	setProperty("initialSize","3");
	setProperty("maxWaitMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS));
	setProperty("poolPreparedStatements",FALSE);
	setProperty("maxOpenPreparedStatements",String.valueOf(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL));
	setProperty("timeBetweenEvictionRunsMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
	setProperty("numTestsPerEvictionRun",String.valueOf(BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN));
	setProperty("minEvictableIdleTimeMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
	setProperty("softMinEvictableIdleTimeMILLIS",String.valueOf(BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
	setProperty("evictionPolicyClassName",String.valueOf(BaseObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME));
	setProperty("testWhileIdle",FALSE);
	setProperty("validationQuery","");
	setProperty("validationQueryTimeoutSeconds","-1");
	setProperty("accessToUnderlyingConnectionAllowed",FALSE);
	setProperty("maxConnLifetimeMILLIS","-1");
	setProperty("logExpiredConnections",TRUE);
	setProperty("jmxName","org.magic.api:type=Pool,name="+getName());
	setProperty("autoCommitOnReturn",TRUE);
	setProperty("rollbackOnReturn",TRUE);
	setProperty("defaultAutoCommit",TRUE);
	setProperty("defaultReadOnly",FALSE);
	setProperty("defaultQueryTimeoutSeconds","");
	setProperty("cacheState",TRUE);
	setProperty("testOnCreate",FALSE);
	setProperty("testOnBorrow",TRUE);
	setProperty("testOnReturn",FALSE);
	setProperty("fastFailValidation",FALSE);
}
 
Example 28
/**
 * Subclasses can override this if they want to return a specific Commons pool.
 * They should apply any configuration properties to the pool here.
 * <p>Default is a GenericObjectPool instance with the given pool size.
 * @return an empty Commons {@code ObjectPool}.
 * @see GenericObjectPool
 * @see #setMaxSize
 */
protected ObjectPool createObjectPool() {
	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setMaxTotal(getMaxSize());
	config.setMaxIdle(getMaxIdle());
	config.setMinIdle(getMinIdle());
	config.setMaxWaitMillis(getMaxWait());
	config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
	config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
	config.setBlockWhenExhausted(isBlockWhenExhausted());
	return new GenericObjectPool(this, config);
}
 
Example 29
Source Project: athenz   Source File: DataSourceFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPoolConfigZeroValues() {
   
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "0");
    
    GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
    assertNotNull(config);
    
    // MaxTotal and MaxIdle are set to -1 if the value is 0
    assertEquals(config.getMaxTotal(), -1);
    assertEquals(config.getMaxIdle(), -1);
    assertEquals(config.getMinIdle(), 0);
    assertEquals(config.getMaxWaitMillis(), 0);
    assertEquals(config.getMinEvictableIdleTimeMillis(), 0);
    assertEquals(config.getTimeBetweenEvictionRunsMillis(), 0);
    assertTrue(config.getTestWhileIdle());
    assertTrue(config.getTestOnBorrow());
    
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL);
}
 
Example 30
private GenericObjectPoolConfig getPoolConfig(Pool properties) {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(properties.getMaxActive());
    config.setMaxIdle(properties.getMaxIdle());
    config.setMinIdle(properties.getMinIdle());
    if (properties.getMaxWait() != null) {
        config.setMaxWaitMillis(properties.getMaxWait().toMillis());
    }
    return config;
}