本文整理匯總了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();
}