Java Code Examples for org.apache.commons.pool2.impl.GenericObjectPoolConfig#setJmxEnabled()

The following examples show how to use org.apache.commons.pool2.impl.GenericObjectPoolConfig#setJmxEnabled() . 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 File: DefaultSessionPool.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
public DefaultSessionPool(final ConnectionService connect, final X509TrustManager trust, final X509KeyManager key,
                          final VaultRegistry registry, final Cache<Path> cache, final TranscriptListener transcript,
                          final Host bookmark) {
    this.connect = connect;
    this.registry = registry;
    this.cache = cache;
    this.bookmark = bookmark;
    this.transcript = transcript;
    final GenericObjectPoolConfig<Session> configuration = new GenericObjectPoolConfig<Session>();
    configuration.setJmxEnabled(false);
    configuration.setEvictionPolicyClassName(CustomPoolEvictionPolicy.class.getName());
    configuration.setBlockWhenExhausted(true);
    configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL);
    this.pool = new GenericObjectPool<Session>(new PooledSessionFactory(connect, trust, key, cache, bookmark, registry), configuration);
    final AbandonedConfig abandon = new AbandonedConfig();
    abandon.setUseUsageTracking(true);
    this.pool.setAbandonedConfig(abandon);
}
 
Example 2
Source File: BasicDataSource.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a connection pool for this datasource. This method only exists so subclasses can replace the
 * implementation class.
 * <p>
 * This implementation configures all pool properties other than timeBetweenEvictionRunsMillis. Setting that
 * property is deferred to {@link #startPoolMaintenance()}, since setting timeBetweenEvictionRunsMillis to a
 * positive value causes {@link GenericObjectPool}'s eviction timer to be started.
 * </p>
 *
 * @param factory The factory to use to create new connections for this pool.
 */
protected void createConnectionPool(final PoolableConnectionFactory factory) {
    // Create an object pool to contain our active connections
    final GenericObjectPoolConfig<PoolableConnection> config = new GenericObjectPoolConfig<>();
    updateJmxName(config);
    // Disable JMX on the underlying pool if the DS is not registered:
    config.setJmxEnabled(registeredJmxObjectName != null);
    final GenericObjectPool<PoolableConnection> gop = createObjectPool(factory, config, abandonedConfig);
    gop.setMaxTotal(maxTotal);
    gop.setMaxIdle(maxIdle);
    gop.setMinIdle(minIdle);
    gop.setMaxWaitMillis(maxWaitMillis);
    gop.setTestOnCreate(testOnCreate);
    gop.setTestOnBorrow(testOnBorrow);
    gop.setTestOnReturn(testOnReturn);
    gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    gop.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
    gop.setTestWhileIdle(testWhileIdle);
    gop.setLifo(lifo);
    gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
    gop.setEvictionPolicyClassName(evictionPolicyClassName);
    factory.setPool(gop);
    connectionPool = gop;
}
 
Example 3
Source File: BaseTest.java    From lite-pool with Apache License 2.0 5 votes vote down vote up
public GenericObjectPool<TestObject> createCommonsPool2(int minimum, int maximum, long timeout) {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(maximum);
    config.setMinIdle(minimum);
    config.setMaxIdle(minimum);
    config.setFairness(false);
    config.setJmxEnabled(false);
    config.setBlockWhenExhausted(true);
    config.setTestOnBorrow(false);
    config.setMaxWaitMillis(timeout);
    config.setTestOnCreate(false);
    config.setTestOnReturn(false);
    config.setTestWhileIdle(false);
    return new GenericObjectPool<>( new CommonsPool2Factory(), config);
}
 
Example 4
Source File: RedisStandaloneBuilder.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 构造函数package访问域,package外直接构造实例;
 *
 * @param appId
 */
RedisStandaloneBuilder(final long appId) {
    this.appId = appId;
    poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL * 3);
    poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 2);
    poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE);
    poolConfig.setJmxEnabled(true);
    poolConfig.setJmxNamePrefix("jedis-pool");
}
 
Example 5
Source File: RedisSentinelBuilder.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 构造函数package访问域,package外不能直接构造实例;
 *
 * @param appId
 */
RedisSentinelBuilder(final long appId) {
    this.appId = appId;
    poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL * 3);
    poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 2);
    poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE);
    poolConfig.setMaxWaitMillis(1000L);
    poolConfig.setJmxNamePrefix("jedis-sentinel-pool");
    poolConfig.setJmxEnabled(true);
}
 
Example 6
Source File: RedisClusterBuilder.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 构造函数package访问域,package外不能直接构造实例;
 *
 * @param appId
 */
RedisClusterBuilder(final long appId) {
    this.appId = appId;
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL * 5);
    poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 2);
    poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE);
    //JedisPool.borrowObject最大等待时间
    poolConfig.setMaxWaitMillis(1000L);
    poolConfig.setJmxNamePrefix("jedis-pool");
    poolConfig.setJmxEnabled(true);
    this.jedisPoolConfig = poolConfig;
}
 
Example 7
Source File: RedisStandaloneTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
    public void testStandaloneExample() {
        long appId = 10122;
        JedisPool jedisPool = null;

        // 使用默认配置
//        jedisPool = ClientBuilder.redisStandalone(appId).build();

        /**
         * 使用自定义配置
         */
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 3);
        poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE * 2);
        poolConfig.setJmxEnabled(true);
        poolConfig.setMaxWaitMillis(3000);

        jedisPool = ClientBuilder.redisStandalone(appId)
                .setPoolConfig(poolConfig)
                .setTimeout(2000)
                .build();

        Jedis jedis = jedisPool.getResource();
        jedis.setnx("key2", "5");
        assertEquals("10", jedis.incrBy("key2", 5));
        jedis.close();
    }
 
Example 8
Source File: RedisClusterTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
private GenericObjectPoolConfig getPoolConfig() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(GenericObjectPoolConfig.DEFAULT_MAX_TOTAL * 20);
    poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 20);
    poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 10);
    // JedisPool.borrowObject最大等待时间
    poolConfig.setMaxWaitMillis(1000L);
    poolConfig.setJmxNamePrefix("jedis-pool");
    poolConfig.setJmxEnabled(true);
    return poolConfig;
}
 
Example 9
Source File: RedisSentinelTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
    public void testSentinelExample() {
        JedisSentinelPool sentinelPool = null;

        // 使用默认配置
//        sentinelPool = ClientBuilder.redisSentinel(appId).build();

        /**
         * 自定义配置
         */
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 3);
        poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE * 2);
        poolConfig.setJmxEnabled(true);
        poolConfig.setMaxWaitMillis(3000);

        sentinelPool = ClientBuilder.redisSentinel(appId)
                .setPoolConfig(poolConfig)
                .setConnectionTimeout(2000)
                .setSoTimeout(1000)
                .build();

        Jedis jedis = sentinelPool.getResource();
        jedis.set("key1", "1");
        assertEquals("2", jedis.incr("key1"));
        jedis.close();
    }
 
Example 10
Source File: XpipeNettyClientKeyedObjectPool.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
private static GenericObjectPoolConfig createDefaultConfig(int maxPerKey) {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setJmxEnabled(false);
    config.setMaxTotal(maxPerKey);
    config.setBlockWhenExhausted(false);
    return config;
}
 
Example 11
Source File: SvnObjectPools.java    From proctor with 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 12
Source File: XpipeNettyClientPool.java    From x-pipe with Apache License 2.0 4 votes vote down vote up
private static GenericObjectPoolConfig createDefaultPoolConfig() {
	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setJmxEnabled(false);
	return config;
}
 
Example 13
Source File: DefaultRedisModuleCfg.java    From ymate-platform-v2 with Apache License 2.0 4 votes vote down vote up
private RedisDataSourceCfgMeta __doParserDataSourceCfgMeta(String dsName, Map<String, String> dataSourceCfgs) throws Exception {
    IConfigReader _dataSourceCfg = MapSafeConfigReader.bind(dataSourceCfgs);
    //
    IRedis.ConnectionType _connectionType;
    try {
        _connectionType = IRedis.ConnectionType.valueOf(_dataSourceCfg.getString(CONNECTION_TYPE, IConfig.DEFAULT_STR).toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new UnsupportedOperationException("Redis connection type unsupported.");
    }
    String _masterServerName = _dataSourceCfg.getString(MASTER_SERVER_NAME, IConfig.DEFAULT_STR);
    List<ServerMeta> _servers = new ArrayList<ServerMeta>();
    String[] _serverNames = StringUtils.split(_dataSourceCfg.getString(SERVER_NAME_LIST, IConfig.DEFAULT_STR), "|");
    if (_serverNames != null) {
        for (String _serverName : _serverNames) {
            IConfigReader _serverCfg = MapSafeConfigReader.bind(_dataSourceCfg.getMap("server." + _serverName + "."));
            if (!_serverCfg.toMap().isEmpty()) {
                ServerMeta _servMeta = new ServerMeta();
                _servMeta.setName(_serverName);
                _servMeta.setHost(_serverCfg.getString(HOST, "localhost"));
                _servMeta.setPort(_serverCfg.getInt(PORT, 6379));
                _servMeta.setTimeout(_serverCfg.getInt(TIMEOUT, 2000));
                _servMeta.setSocketTimeout(_serverCfg.getInt(SOCKET_TIMEOUT, 2000));
                _servMeta.setMaxAttempts(_serverCfg.getInt(MAX_ATTEMPTS, 3));
                _servMeta.setWeight(_serverCfg.getInt(WEIGHT, 1));
                _servMeta.setDatabase(_serverCfg.getInt(DATABASE, 0));
                _servMeta.setClientName(_serverCfg.getString(CLIENT_NAME));
                _servMeta.setPassword(_serverCfg.getString(PASSWORD));
                //
                boolean _isPwdEncrypted = _dataSourceCfg.getBoolean(PASSWORD_ENCRYPTED);
                //
                if (_isPwdEncrypted && StringUtils.isNotBlank(_servMeta.getPassword())) {
                    IPasswordProcessor _proc = _serverCfg.getClassImpl(PASSWORD_CLASS, IPasswordProcessor.class);
                    if (_proc == null) {
                        _proc = __owner.getConfig().getDefaultPasswordClass().newInstance();
                    }
                    if (_proc != null) {
                        _servMeta.setPassword(_proc.decrypt(_servMeta.getPassword()));
                    }
                }
                //
                _servers.add(_servMeta);
            }
        }
    }
    //
    GenericObjectPoolConfig _poolConfig = new GenericObjectPoolConfig();
    IConfigReader _poolCfg = MapSafeConfigReader.bind(_dataSourceCfg.getMap("pool."));
    if (!_poolCfg.toMap().isEmpty()) {
        _poolConfig.setMinIdle(_poolCfg.getInt(MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE));
        _poolConfig.setMaxIdle(_poolCfg.getInt(MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE));
        _poolConfig.setMaxTotal(_poolCfg.getInt(MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL));
        _poolConfig.setBlockWhenExhausted(_poolCfg.getBoolean(BLOCK_WHEN_EXHAUSTED, GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED));
        _poolConfig.setFairness(_poolCfg.getBoolean(FAIRNESS, GenericObjectPoolConfig.DEFAULT_FAIRNESS));
        _poolConfig.setJmxEnabled(_poolCfg.getBoolean(JMX_ENABLE, GenericObjectPoolConfig.DEFAULT_JMX_ENABLE));
        _poolConfig.setJmxNameBase(_poolCfg.getString(JMX_NAME_BASE, GenericObjectPoolConfig.DEFAULT_JMX_NAME_BASE));
        _poolConfig.setJmxNamePrefix(_poolCfg.getString(JMX_NAME_PREFIX, GenericObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX));
        _poolConfig.setEvictionPolicyClassName(_poolCfg.getString(EVICTION_POLICY_CLASS_NAME, GenericObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME));
        _poolConfig.setLifo(_poolCfg.getBoolean(LIFO, GenericObjectPoolConfig.DEFAULT_LIFO));
        _poolConfig.setMaxWaitMillis(_poolCfg.getLong(MAX_WAIT_MILLIS, GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS));
        _poolConfig.setMinEvictableIdleTimeMillis(_poolCfg.getLong(MIN_EVICTABLE_IDLE_TIME_MILLIS, GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
        _poolConfig.setSoftMinEvictableIdleTimeMillis(_poolCfg.getLong(SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
        _poolConfig.setTestOnBorrow(_poolCfg.getBoolean(TEST_ON_BORROW, GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW));
        _poolConfig.setTestOnReturn(_poolCfg.getBoolean(TEST_ON_RETURN, GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN));
        _poolConfig.setTestOnCreate(_poolCfg.getBoolean(TEST_ON_CREATE, GenericObjectPoolConfig.DEFAULT_TEST_ON_CREATE));
        _poolConfig.setTestWhileIdle(_poolCfg.getBoolean(TEST_WHILE_IDLE, GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE));
        _poolConfig.setNumTestsPerEvictionRun(_poolCfg.getInt(NUM_TESTS_PER_EVICTION_RUN, GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN));
        _poolConfig.setTimeBetweenEvictionRunsMillis(_poolCfg.getLong(TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
    }
    return new RedisDataSourceCfgMeta(dsName, _connectionType, _masterServerName, _servers, _poolConfig);
}