Search in sources :

Example 76 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project atmosphere by Atmosphere.

the class PoolableBroadcasterFactoryTest method testImplementation.

@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());
    GenericObjectPoolConfig c = new GenericObjectPoolConfig();
    c.setMaxTotal(1);
    nativePool.setConfig(c);
    assertEquals(1, nativePool.getMaxTotal());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Test(org.testng.annotations.Test)

Example 77 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project bigbluebutton by bigbluebutton.

the class MessageSender method start.

public void start() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(32);
    config.setMaxIdle(8);
    config.setMinIdle(1);
    config.setTestOnBorrow(true);
    config.setTestOnReturn(true);
    config.setTestWhileIdle(true);
    config.setNumTestsPerEvictionRun(12);
    config.setMaxWaitMillis(5000);
    config.setTimeBetweenEvictionRunsMillis(60000);
    config.setBlockWhenExhausted(true);
    // 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, "BbbWebPub");
    log.info("Redis message publisher starting!");
    try {
        sendMessage = true;
        Runnable messageSender = new Runnable() {

            public void run() {
                while (sendMessage) {
                    try {
                        MessageToSend msg = messages.take();
                        publish(msg.getChannel(), msg.getMessage());
                    } catch (InterruptedException e) {
                        log.warn("Failed to get message from queue.");
                    }
                }
            }
        };
        msgSenderExec.execute(messageSender);
    } catch (Exception e) {
        log.error("Error subscribing to channels: " + e.getMessage());
    }
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool)

Example 78 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project Hotchpotch by carryxyh.

the class RedisService method init.

public void init() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxIdle(this.getMaxIdle());
    config.setMinIdle(this.getMinIdle());
    config.setMaxTotal(this.getMaxTotal());
    config.setMaxWaitMillis(this.getMaxWaitMillis());
    config.setTestOnBorrow(this.isTestOnBorrow());
    pool = new JedisPool(config, ip, port, Protocol.DEFAULT_TIMEOUT, null, database);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            pool.destroy();
        }
    });
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool)

Example 79 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project duangframework by tcrct.

the class JedisClusterPoolUtils method createJedisPool.

/**
 * 建立连接池 真实环境,一般把配置参数缺抽取出来。
 */
private static void createJedisPool() {
    try {
        String[] ipArray = getClusterIps();
        if (ToolsKit.isEmpty(ipArray)) {
            throw new EmptyNullException("ipArray is null");
        }
        // 只给集群里一个实例就可以
        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        for (int i = 0; i < ipArray.length; i++) {
            String[] items = ipArray[i].split(":");
            jedisClusterNodes.add(new HostAndPort(items[0], Integer.parseInt(items[1])));
        }
        // 配置信息
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        config.setMaxTotal(10000);
        config.setMaxIdle(500);
        config.setMinIdle(100);
        config.setMaxWaitMillis(5000);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        jedisCluster = new JedisCluster(jedisClusterNodes, config);
        if (null != jedisCluster) {
            logger.warn("Connent Redis Cluster:  " + ToolsKit.toJsonString(jedisClusterNodes) + " is Success...");
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("初始化 redis 出错啦...");
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) JedisCluster(redis.clients.jedis.JedisCluster) IOException(java.io.IOException) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) HashSet(java.util.HashSet)

Example 80 with GenericObjectPoolConfig

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project mlib by myshzzx.

the class ThriftClientFactory method buildPooled.

/**
 * build pooled(auto close connections) and thread-safe (unblocking) client.
 * <br/>
 * WARNING: the holder needs to be closed after using.
 */
@SuppressWarnings("unchecked")
public ClientHolder<TI> buildPooled() {
    GenericObjectPoolConfig poolConf = new GenericObjectPoolConfig();
    poolConf.setMinIdle(0);
    poolConf.setMaxTotal(Integer.MAX_VALUE);
    poolConf.setMaxWaitMillis(conf.clientSocketTimeout);
    poolConf.setTimeBetweenEvictionRunsMillis(POOL_IDLE_OBJ_TIMEOUT);
    poolConf.setTestWhileIdle(true);
    GenericObjectPool<ThriftClient> pool = new GenericObjectPool(new PoolObjMaker(), poolConf);
    TI client = (TI) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { conf.iface }, (obj, method, args) -> {
        ThriftClient tc = pool.borrowObject();
        try {
            return tc.invokeThriftClient(method, args);
        } finally {
            pool.returnObject(tc);
        }
    });
    return new ClientHolder<>(client, pool::close);
}
Also used : BasePooledObjectFactory(org.apache.commons.pool2.BasePooledObjectFactory) Logger(org.slf4j.Logger) Proxy(java.lang.reflect.Proxy) PooledObject(org.apache.commons.pool2.PooledObject) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) org.apache.thrift.transport(org.apache.thrift.transport) LoggerFactory(org.slf4j.LoggerFactory) TException(org.apache.thrift.TException) IOException(java.io.IOException) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) SocketException(java.net.SocketException) TProtocol(org.apache.thrift.protocol.TProtocol) Closeable(java.io.Closeable) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Method(java.lang.reflect.Method) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool)

Aggregations

GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)127 Test (org.junit.Test)77 Jedis (redis.clients.jedis.Jedis)41 ShardedJedis (redis.clients.jedis.ShardedJedis)40 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)40 JedisPool (redis.clients.jedis.JedisPool)31 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)19 ArrayList (java.util.ArrayList)15 JedisShardInfo (redis.clients.jedis.JedisShardInfo)15 URI (java.net.URI)11 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)9 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 BaseTest (com.sohu.tv.test.base.BaseTest)6 IOException (java.io.IOException)6 Transaction (redis.clients.jedis.Transaction)6 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)5 PooledObject (org.apache.commons.pool2.PooledObject)5 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)5 Test (org.testng.annotations.Test)5