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());
}
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());
}
}
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();
}
});
}
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 出错啦...");
}
}
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);
}
Aggregations