本文整理汇总了Java中org.apache.commons.pool2.impl.GenericObjectPoolConfig类的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPoolConfig类的具体用法?Java GenericObjectPoolConfig怎么用?Java GenericObjectPoolConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericObjectPoolConfig类属于org.apache.commons.pool2.impl包,在下文中一共展示了GenericObjectPoolConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJedisCluster
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
/**
* 注意:
* 这里返回的JedisCluster是单例的,并且可以直接注入到其他类中去使用
* @return
*/
@Bean
public JedisCluster getJedisCluster() {
//获取服务器数组(这里要相信自己的输入,所以没有考虑空指针问题)
String[] serverArray = redisProperties.getClusterNodes().split(",");
Set<HostAndPort> nodes = new HashSet<>();
for (String ipPort : serverArray) {
String[] ipPortPair = ipPort.split(":");
nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
}
return new JedisCluster(nodes,10000,
1000,1,redisProperties.getPassword() ,
new GenericObjectPoolConfig());
}
示例2: JaRedisPool
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
public JaRedisPool(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);
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(h, port,
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(host,
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
}
}
示例3: JedisPool
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
public JedisPool(final String host, final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
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 JedisFactory(h, port, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database,
null, ssl, sslSocketFactory, sslParameters, hostnameVerifier),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<Jedis>(
new JedisFactory(host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT,
null, Protocol.DEFAULT_DATABASE, null, false, null, null, null),
new GenericObjectPoolConfig());
}
}
示例4: initializeSlotsCache
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
private void initializeSlotsCache(Set<HostAndPort> startNodes, GenericObjectPoolConfig poolConfig, String password,
String clientName) {
for (HostAndPort hostAndPort : startNodes) {
Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort());
try {
if (password != null) {
jedis.auth(password);
}
if (clientName != null) {
jedis.clientSetname(clientName);
}
cache.discoverClusterNodesAndSlots(jedis);
break;
} catch (JedisConnectionException e) {
// try next nodes
} finally {
if (jedis != null) {
jedis.close();
}
}
}
}
示例5: checkResourceIsCloseable
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
@Test
public void checkResourceIsCloseable() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
"foobared", 2);
Jedis jedis = pool.getResource();
try {
jedis.set("hello", "jedis");
} finally {
jedis.close();
}
Jedis jedis2 = pool.getResource();
try {
assertEquals(jedis, jedis2);
} finally {
jedis2.close();
}
}
示例6: customClientName
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
@Test
public void customClientName() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
"foobared", 0, "my_shiny_client_name");
Jedis jedis = pool.getResource();
try {
assertEquals("my_shiny_client_name", jedis.clientGetname());
} finally {
jedis.close();
pool.destroy();
}
assertTrue(pool.isClosed());
}
示例7: testSimplePool
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
@Test
public void testSimplePool() throws Exception {
GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
pc.setMinIdle(2);
pc.setMaxIdle(10);
pc.setMaxTotal(10);
JedisPool pool = new JedisPool(pc, "localhost", 6379);
testWithPool(pool);
}
示例8: start
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
public static void start(){
// int size = 1024;
int size = 1024;
int max = 32;
GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
genericObjectPoolConfig.setMaxTotal(size * max);
genericObjectPoolConfig.setMaxIdle(size * max);
genericObjectPoolConfig.setMinIdle(size);
long time = 1000 * 30;
genericObjectPoolConfig.setMaxWaitMillis(time);
genericObjectPoolConfig.setSoftMinEvictableIdleTimeMillis(time);
updateEventCacheFactory = new UpdateEventCacheFactory(new UpdateEventPoolFactory(), genericObjectPoolConfig);
}
示例9: JaRedisSentinelPool
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
public JaRedisSentinelPool(String masterName, Set<String> sentinels,
final GenericObjectPoolConfig poolConfig, final int connectionTimeout, final int soTimeout,
final String password, final int database, final String clientName) {
this.poolConfig = poolConfig;
this.connectionTimeout = connectionTimeout;
this.soTimeout = soTimeout;
this.password = password;
this.database = database;
this.clientName = clientName;
HostAndPort master = initSentinels(sentinels, masterName);
initPool(master);
}
示例10: createRabbitMqChannelPool
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
static RabbitMqChannelPool createRabbitMqChannelPool(RabbitMqChannelFactory channelFactory) {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setJmxNameBase("storm-rabbitmq:name=");
config.setJmxNamePrefix("ChannelPool");
RabbitMqChannelPool channelPool = new RabbitMqChannelPool(channelFactory, config);
channelPool.setMaxTotal(-1);
channelPool.setMaxIdle(-1);
return channelPool;
}
示例11: TracingJedisCluster
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
public TracingJedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
int soTimeout,
int maxAttempts, GenericObjectPoolConfig poolConfig, Tracer tracer,
boolean traceWithActiveSpanOnly) {
super(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, poolConfig);
this.helper = new TracingHelper(tracer, traceWithActiveSpanOnly);
}
示例12: checkPoolOverflow
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
@Test(expected = JedisException.class)
public void checkPoolOverflow() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
ShardedJedis jedis = pool.getResource();
jedis.set("foo", "0");
ShardedJedis newJedis = pool.getResource();
newJedis.incr("foo");
}
示例13: checkConnectionWithDefaultPort
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
@Test
public void checkConnectionWithDefaultPort() {
ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
ShardedJedis jedis = pool.getResource();
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
pool.returnResource(jedis);
pool.destroy();
}
示例14: checkCloseableConnections
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
@Test
public void checkCloseableConnections() throws Exception {
ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
ShardedJedis jedis = pool.getResource();
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
pool.returnResource(jedis);
pool.close();
assertTrue(pool.isClosed());
}
示例15: checkFailedJedisServer
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入依赖的package包/类
@Test
public void checkFailedJedisServer() {
ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
ShardedJedis jedis = pool.getResource();
jedis.incr("foo");
pool.returnResource(jedis);
pool.destroy();
}