本文整理汇总了Java中org.apache.commons.pool.impl.GenericObjectPool.Config方法的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool.Config方法的具体用法?Java GenericObjectPool.Config怎么用?Java GenericObjectPool.Config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool.impl.GenericObjectPool
的用法示例。
在下文中一共展示了GenericObjectPool.Config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parserServers
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
protected void parserServers(@SuppressWarnings("rawtypes") List nodes)
throws AlbianRemoteUNIDAttributeException {
for (Object node : nodes) {
IAlbianRemoteUNIDAttribute attr = parserServer((Element) node);
if (null == attr)
continue;
_list.add(attr);
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.maxActive = attr.getPoolSize();
config.maxWait = 300;
GenericObjectPool<Socket> pool = new GenericObjectPool<Socket>(
new AlbianUNIDSocketConnectPoolFactory(attr),
config) {
};
AlbianUNIDConnectPoolMap.insert(
String.format("%s:%d", attr.getHost(), attr.getPort()),
pool);
}
}
示例2: getPoolConfig
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* 获取对象池配置
*
* @return
*/
public GenericObjectPool.Config getPoolConfig() {
GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
// maxIdle为负数时,不对pool size大小做限制,此处做限制,防止保持过多空闲redis连接
if (this.maxIdle >= 0) {
poolConfig.maxIdle = this.maxIdle;
}
poolConfig.maxWait = this.maxWait;
if (this.whenExhaustedAction >= 0 && this.whenExhaustedAction < 3) {
poolConfig.whenExhaustedAction = this.whenExhaustedAction;
}
poolConfig.testOnBorrow = this.testOnBorrow;
poolConfig.minIdle = this.minIdle;
poolConfig.maxActive = this.maxActive;
poolConfig.testOnReturn = this.testOnReturn;
poolConfig.testWhileIdle = this.testWhileIdle;
poolConfig.timeBetweenEvictionRunsMillis = this.timeBetweenEvictionRunsMillis;
poolConfig.numTestsPerEvictionRun = this.numTestsPerEvictionRun;
poolConfig.minEvictableIdleTimeMillis = this.minEvictableIdleTimeMillis;
poolConfig.softMinEvictableIdleTimeMillis = this.softMinEvictableIdleTimeMillis;
poolConfig.lifo = this.lifo;
return poolConfig;
}
示例3: getObjectPoolConfig
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* Returns an {@link org.apache.commons.pool.impl.GenericObjectPool.Config} object
* configurated with the properties extracted from the this instance.
* Use this to configurate a pool implementation using
* {@link org.apache.commons.pool.impl.GenericObjectPool}.
*/
public GenericObjectPool.Config getObjectPoolConfig()
{
GenericObjectPool.Config conf = new GenericObjectPool.Config();
conf.maxActive = getMaxActive();
conf.maxIdle = getMaxIdle();
conf.minIdle = getMinIdle();
conf.maxWait = getMaxWait();
conf.minEvictableIdleTimeMillis = getMinEvictableIdleTimeMillis();
conf.numTestsPerEvictionRun = getNumTestsPerEvictionRun();
conf.testOnBorrow = isTestOnBorrow();
conf.testOnReturn = isTestOnReturn();
conf.testWhileIdle = isTestWhileIdle();
conf.timeBetweenEvictionRunsMillis = getTimeBetweenEvictionRunsMillis();
conf.whenExhaustedAction = getWhenExhaustedAction();
return conf;
}
示例4: createPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
private GenericObjectPool<Channel> createPool(Location loc, int active) {
GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
poolConfig.maxActive = active * 5;
poolConfig.maxWait = 30000;
poolConfig.maxIdle = active * 5;
poolConfig.minIdle = active;
poolConfig.testOnBorrow = false;
poolConfig.testOnReturn = false;
poolConfig.minEvictableIdleTimeMillis = Integer.MAX_VALUE;
poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
return new GenericObjectPool<Channel>(new ChannelObjectFactory(loc, bootstrap), poolConfig);
}
示例5: setup
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public void setup( Properties prop ) {
this.prop=prop;
GenericObjectPool.Config conPoolCfg = new GenericObjectPool.Config();
conPoolCfg.maxActive = Integer.parseInt( prop.getProperty( "connectionPoolMaxSize", "15" ) );
conPoolCfg.maxIdle = Integer.parseInt( prop.getProperty( "connectionPoolMaxIdle", "8" ) );
conPoolCfg.maxWait = Integer.parseInt( prop.getProperty( "connectionPoolMaxWait", "60000" ) );
conPoolCfg.minIdle = Integer.parseInt( prop.getProperty( "connectionPoolMinSize", "2" ) );
ObjectPool connectionPool = new GenericObjectPool( null, conPoolCfg );
try {
Class.forName( prop.getProperty( "jdbcDriver" ) );
} catch( ClassNotFoundException e ) {
e.printStackTrace();
throw new RuntimeException();
}
ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory( prop.getProperty( "jdbcUrl" ),
prop.getProperty( "jdbcUser" ),
prop.getProperty( "jdbcPassword" ) );
new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
ds = dataSource;
}
示例6: makePoolConfig
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
private GenericObjectPool.Config makePoolConfig() {
GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
poolConfig.maxActive = maxActive;
poolConfig.maxIdle = 1;
poolConfig.minIdle = 0;
poolConfig.minEvictableIdleTimeMillis = idleTime;
poolConfig.timeBetweenEvictionRunsMillis = idleTime * 2L;
poolConfig.testOnBorrow=true;
poolConfig.testOnReturn=false;
poolConfig.testWhileIdle=false;
return poolConfig;
}
示例7: instantiateAndConfigureConfig
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
private GenericObjectPool.Config instantiateAndConfigureConfig() {
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.maxActive = poolConfiguration.getMaxActivePerPool();
config.maxIdle = poolConfiguration.getMaxIdlePerPool();
config.minIdle = poolConfiguration.getMinIdlePerPool();
config.testOnBorrow = poolConfiguration.isTestOnBorrow();
config.testWhileIdle = poolConfiguration.isTestWhileIdle();
config.timeBetweenEvictionRunsMillis = poolConfiguration.getTimeBetweenEvictionRuns();
config.minEvictableIdleTimeMillis = poolConfiguration.getMinEvictableIdleTime();
config.whenExhaustedAction = poolConfiguration.getExhaustedAction();
config.maxWait = poolConfiguration.getMaxWait();
return config;
}
示例8: createConnectionPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
private void createConnectionPool() {
GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
poolConfig.minEvictableIdleTimeMillis = 3000;
poolConfig.maxWait = 3000;
poolConfig.maxActive = maxConnections;
poolConfig.maxIdle = maxConnections;
poolConfig.minIdle = 0;
poolConfig.numTestsPerEvictionRun = Math.max(1, maxConnections / 10);
poolConfig.timeBetweenEvictionRunsMillis = 5000;
this.connectionPool = new GenericObjectPool(new PoolableJMSConnectionFactory(), poolConfig);
}
示例9: createConnectionPool
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
* Create the pool for pooling the connections of the given connection descriptor.
* Override this method to implement your on {@link org.apache.commons.pool.ObjectPool}.
*/
public ObjectPool createConnectionPool(JdbcConnectionDescriptor jcd)
{
if (log.isDebugEnabled()) log.debug("createPool was called");
PoolableObjectFactory pof = new ConPoolFactory(this, jcd);
GenericObjectPool.Config conf = jcd.getConnectionPoolDescriptor().getObjectPoolConfig();
return (ObjectPool)new GenericObjectPool(pof, conf);
}
示例10: test_json
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void test_json() throws IOException {
Settings.Builder builder = ImmutableSettings.builder().put("redis.response.set", "json")
.put("redis.response.del", "json");
client().admin().cluster().prepareUpdateSettings().setTransientSettings(builder).get();
JedisPool pool = new JedisPool(new GenericObjectPool.Config(), "localhost", 6379, 1000000);
Jedis jedis = pool.getResource();
// test set
String setResult = jedis.set("/test/person/1", jsonBuilder().startObject().field("test", "value").endObject().string());
assertThat(setResult, containsString("\"created\":true"));
assertThat(setResult, containsString("\"_index\":\"test\""));
assertThat(setResult, containsString("\"_type\":\"person\""));
assertThat(setResult, containsString("\"_id\":\"1\""));
Client jedisClient = jedis.getClient();
// test delete
jedisClient.del("/test/person/1");
String deleteResult = jedisClient.getBulkReply();
assertThat(deleteResult, containsString("\"found\":true"));
assertThat(deleteResult, containsString("\"_index\":\"test\""));
assertThat(deleteResult, containsString("\"_type\":\"person\""));
assertThat(deleteResult, containsString("\"_id\":\"1\""));
}
示例11: init
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
private void init() {
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.maxActive = 2;//TODO: Make this configurable.
config.testOnBorrow = true;
config.testWhileIdle = true;
config.timeBetweenEvictionRunsMillis = 10000;
config.minEvictableIdleTimeMillis = 60000;
GenericObjectPoolFactory genericObjectPoolFactory = new GenericObjectPoolFactory(this, config);
pool = genericObjectPoolFactory.createPool();
}
示例12: APNSClient
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public APNSClient(AppleNotificationServer appleNotificationServer) {
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.testOnBorrow = true;
config.testOnReturn = true;
config.testWhileIdle = true;
config.minIdle = 1;
config.maxIdle = Runtime.getRuntime().availableProcessors();
config.maxActive = Runtime.getRuntime().availableProcessors() * 4;
this.pool = new PushNotificationManagerPool(config, appleNotificationServer);
}
示例13: RedisRegistry
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public RedisRegistry(URL url) {
super(url);
if (url.isAnyHost()) {
throw new IllegalStateException("registry address == null");
}
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.testOnBorrow = url.getParameter("test.on.borrow", true);
config.testOnReturn = url.getParameter("test.on.return", false);
config.testWhileIdle = url.getParameter("test.while.idle", false);
if (url.getParameter("max.idle", 0) > 0)
config.maxIdle = url.getParameter("max.idle", 0);
if (url.getParameter("min.idle", 0) > 0)
config.minIdle = url.getParameter("min.idle", 0);
if (url.getParameter("max.active", 0) > 0)
config.maxActive = url.getParameter("max.active", 0);
if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0)
config.maxWait = url.getParameter("max.wait", url.getParameter("timeout", 0));
if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
config.numTestsPerEvictionRun = url.getParameter("num.tests.per.eviction.run", 0);
if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
config.timeBetweenEvictionRunsMillis = url.getParameter("time.between.eviction.runs.millis", 0);
if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
config.minEvictableIdleTimeMillis = url.getParameter("min.evictable.idle.time.millis", 0);
String cluster = url.getParameter("cluster", "failover");
if (! "failover".equals(cluster) && ! "replicate".equals(cluster)) {
throw new IllegalArgumentException("Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate.");
}
replicate = "replicate".equals(cluster);
List<String> addresses = new ArrayList<String>();
addresses.add(url.getAddress());
String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]);
if (backups != null && backups.length > 0) {
addresses.addAll(Arrays.asList(backups));
}
for (String address : addresses) {
int i = address.indexOf(':');
String host;
int port;
if (i > 0) {
host = address.substring(0, i);
port = Integer.parseInt(address.substring(i + 1));
} else {
host = address;
port = DEFAULT_REDIS_PORT;
}
this.jedisPools.put(address, new JedisPool(config, host, port,
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
}
this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
if (! group.startsWith(Constants.PATH_SEPARATOR)) {
group = Constants.PATH_SEPARATOR + group;
}
if (! group.endsWith(Constants.PATH_SEPARATOR)) {
group = group + Constants.PATH_SEPARATOR;
}
this.root = group;
this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT);
this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() {
public void run() {
try {
deferExpired(); // 延长过期时间
} catch (Throwable t) { // 防御性容错
logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t);
}
}
}, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS);
}
示例14: RedisRegistry
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
public RedisRegistry(URL url) {
super(url);
if (url.isAnyHost()) {
throw new IllegalStateException("registry address == null");
}
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.testOnBorrow = url.getParameter("test.on.borrow", true);
config.testOnReturn = url.getParameter("test.on.return", false);
config.testWhileIdle = url.getParameter("test.while.idle", false);
if (url.getParameter("max.idle", 0) > 0)
config.maxIdle = url.getParameter("max.idle", 0);
if (url.getParameter("min.idle", 0) > 0)
config.minIdle = url.getParameter("min.idle", 0);
if (url.getParameter("max.active", 0) > 0)
config.maxActive = url.getParameter("max.active", 0);
if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0)
config.maxWait = url.getParameter("max.wait", url.getParameter("timeout", 0));
if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
config.numTestsPerEvictionRun = url.getParameter("num.tests.per.eviction.run", 0);
if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
config.timeBetweenEvictionRunsMillis = url.getParameter("time.between.eviction.runs.millis", 0);
if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
config.minEvictableIdleTimeMillis = url.getParameter("min.evictable.idle.time.millis", 0);
String cluster = url.getParameter("cluster", "failover");
if (! "failover".equals(cluster) && ! "replicate".equals(cluster)) {
throw new IllegalArgumentException("Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate.");
}
replicate = "replicate".equals(cluster);
List<String> addresses = new ArrayList<String>();
addresses.add(url.getAddress());
String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]);
if (backups != null && backups.length > 0) {
addresses.addAll(Arrays.asList(backups));
}
// 增加Redis密码支持
String password = url.getPassword();
for (String address : addresses) {
int i = address.indexOf(':');
String host;
int port;
if (i > 0) {
host = address.substring(0, i);
port = Integer.parseInt(address.substring(i + 1));
} else {
host = address;
port = DEFAULT_REDIS_PORT;
}
if (StringUtils.isEmpty(password)) {
this.jedisPools.put(address, new JedisPool(config, host, port,
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
} else {
// 使用密码连接。 此处要求备用redis与主要redis使用相同的密码
this.jedisPools.put(address, new JedisPool(config, host, port,
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), password));
}
}
this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
if (! group.startsWith(Constants.PATH_SEPARATOR)) {
group = Constants.PATH_SEPARATOR + group;
}
if (! group.endsWith(Constants.PATH_SEPARATOR)) {
group = group + Constants.PATH_SEPARATOR;
}
this.root = group;
this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT);
this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() {
public void run() {
try {
deferExpired(); // 延长过期时间
} catch (Throwable t) { // 防御性容错
logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t);
}
}
}, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS);
}
示例15: doStart
import org.apache.commons.pool.impl.GenericObjectPool; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
super.doStart();
if (configuration.getWorkerGroup() == null) {
// create new pool which we should shutdown when stopping as its not shared
workerGroup = new NettyWorkerPoolBuilder()
.withNativeTransport(configuration.isNativeTransport())
.withWorkerCount(configuration.getWorkerCount())
.withName("NettyClientTCPWorker").build();
}
if (configuration.isProducerPoolEnabled()) {
// setup pool where we want an unbounded pool, which allows the pool to shrink on no demand
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.maxActive = configuration.getProducerPoolMaxActive();
config.minIdle = configuration.getProducerPoolMinIdle();
config.maxIdle = configuration.getProducerPoolMaxIdle();
// we should test on borrow to ensure the channel is still valid
config.testOnBorrow = true;
// only evict channels which are no longer valid
config.testWhileIdle = true;
// run eviction every 30th second
config.timeBetweenEvictionRunsMillis = 30 * 1000L;
config.minEvictableIdleTimeMillis = configuration.getProducerPoolMinEvictableIdle();
config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
pool = new GenericObjectPool<Channel>(new NettyProducerPoolableObjectFactory(), config);
if (LOG.isDebugEnabled()) {
LOG.debug("Created NettyProducer pool[maxActive={}, minIdle={}, maxIdle={}, minEvictableIdleTimeMillis={}] -> {}",
new Object[]{config.maxActive, config.minIdle, config.maxIdle, config.minEvictableIdleTimeMillis, pool});
}
} else {
pool = new SharedSingletonObjectPool<Channel>(new NettyProducerPoolableObjectFactory());
if (LOG.isDebugEnabled()) {
LOG.info("Created NettyProducer shared singleton pool -> {}", pool);
}
}
// setup pipeline factory
ClientInitializerFactory factory = configuration.getClientInitializerFactory();
if (factory != null) {
pipelineFactory = factory.createPipelineFactory(this);
} else {
pipelineFactory = new DefaultClientInitializerFactory(this);
}
if (!configuration.isLazyChannelCreation()) {
// ensure the connection can be established when we start up
Channel channel = pool.borrowObject();
pool.returnObject(channel);
}
}