当前位置: 首页>>代码示例>>Java>>正文


Java GenericObjectPool.Config方法代码示例

本文整理汇总了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);
	}

}
 
开发者ID:crosg,项目名称:Albianj2,代码行数:21,代码来源:AlbianRemoteUNIDService.java

示例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;
}
 
开发者ID:neoremind,项目名称:navi-pbrpc,代码行数:28,代码来源:PooledConfiguration.java

示例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;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:23,代码来源:PoolConfiguration.java

示例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);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:13,代码来源:ChannelManager.java

示例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;
}
 
开发者ID:yswang0927,项目名称:ralasafe,代码行数:31,代码来源:DataSourceProviderDbcpImpl.java

示例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;
}
 
开发者ID:somewhereMrli,项目名称:albedo-thrift,代码行数:13,代码来源:ThriftServiceClientProxyFactory.java

示例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;
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:15,代码来源:ConnectionManager.java

示例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);

}
 
开发者ID:wso2,项目名称:carbon-deployment,代码行数:13,代码来源:JMSConnectionFactory.java

示例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);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:12,代码来源:ConnectionFactoryPooledImpl.java

示例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\""));


}
 
开发者ID:kzwang,项目名称:elasticsearch-transport-redis,代码行数:29,代码来源:RedisTransportTests.java

示例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();
}
 
开发者ID:srikalyc,项目名称:Sql4D,代码行数:11,代码来源:MysqlAccessor.java

示例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);
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:12,代码来源:APNSClient.java

示例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);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:73,代码来源:RedisRegistry.java

示例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);
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:82,代码来源:RedisRegistry.java

示例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);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:53,代码来源:NettyProducer.java


注:本文中的org.apache.commons.pool.impl.GenericObjectPool.Config方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。