Java Code Examples for org.apache.commons.pool2.impl.AbandonedConfig

The following are top voted examples for showing how to use org.apache.commons.pool2.impl.AbandonedConfig. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: cyberduck   File: DefaultSessionPool.java   Source Code and License 6 votes vote down vote up
public DefaultSessionPool(final ConnectionService connect, final X509TrustManager trust, final X509KeyManager key,
                          final VaultRegistry registry, final Cache<Path> cache, final TranscriptListener transcript,
                          final Host bookmark) {
    this.connect = connect;
    this.registry = registry;
    this.cache = cache;
    this.bookmark = bookmark;
    this.transcript = transcript;
    final GenericObjectPoolConfig configuration = new GenericObjectPoolConfig();
    configuration.setJmxEnabled(false);
    configuration.setEvictionPolicyClassName(CustomPoolEvictionPolicy.class.getName());
    configuration.setBlockWhenExhausted(true);
    configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL);
    this.pool = new GenericObjectPool<Session>(new PooledSessionFactory(connect, trust, key, cache, bookmark, registry), configuration);
    final AbandonedConfig abandon = new AbandonedConfig();
    abandon.setUseUsageTracking(true);
    this.pool.setAbandonedConfig(abandon);
}
 
Example 2
Project: commons-pool   File: BaseTestProxiedObjectPool.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() {
    log = new StringWriter();

    final PrintWriter pw = new PrintWriter(log);
    final AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setLogAbandoned(true);
    abandonedConfig.setRemoveAbandonedOnBorrow(true);
    abandonedConfig.setUseUsageTracking(true);
    abandonedConfig.setRemoveAbandonedTimeout(ABANDONED_TIMEOUT_SECS);
    abandonedConfig.setLogWriter(pw);

    final GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(3);

    final PooledObjectFactory<TestObject> factory = new TestObjectFactory();

    final ObjectPool<TestObject> innerPool =
            new GenericObjectPool<>(factory, config, abandonedConfig);

    pool = new ProxiedObjectPool<>(innerPool, getproxySource());
}
 
Example 3
Project: FKC   File: KryoPoolConfig.java   Source Code and License 5 votes vote down vote up
public AbandonedConfig getAbandonedConfig() {
    AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setRemoveAbandonedOnBorrow(this.removeAbandonedOnBorrow);
    abandonedConfig.setRemoveAbandonedTimeout(this.removeAbandonedTimeout);
    abandonedConfig.setRemoveAbandonedOnMaintenance(this.removeAbandonedOnMaintenance);
    return abandonedConfig;
}
 
Example 4
Project: leopard   File: JedisPool.java   Source Code and License 5 votes vote down vote up
public JedisPool(final JedisPoolConfig poolConfig, final String host, final int port, final int timeout, String password) {
	super(poolConfig, host, port, timeout, formatPassword(password));
	this.initRedisConnectionListener(poolConfig, host, port, timeout);

	AbandonedConfig abandonedConfig = new AbandonedConfig();
	abandonedConfig.setRemoveAbandonedTimeout(10);
	abandonedConfig.setRemoveAbandonedOnBorrow(true);
	abandonedConfig.setRemoveAbandonedOnMaintenance(true);
	internalPool.setAbandonedConfig(abandonedConfig);
}
 
Example 5
Project: leopard-data   File: JedisPool.java   Source Code and License 5 votes vote down vote up
public JedisPool(final JedisPoolConfig poolConfig, final String host, final int port, final int timeout, String password) {
	super(poolConfig, host, port, timeout, formatPassword(password));
	this.initRedisConnectionListener(poolConfig, host, port, timeout);

	AbandonedConfig abandonedConfig = new AbandonedConfig();
	abandonedConfig.setRemoveAbandonedTimeout(10);
	abandonedConfig.setRemoveAbandonedOnBorrow(true);
	abandonedConfig.setRemoveAbandonedOnMaintenance(true);
	internalPool.setAbandonedConfig(abandonedConfig);
}
 
Example 6
Project: AutoLoadCache   File: DataLoaderFactory.java   Source Code and License 5 votes vote down vote up
private DataLoaderFactory() {
    GenericObjectPoolConfig config=new GenericObjectPoolConfig();
    config.setMaxTotal(1024);
    config.setMaxIdle(50);
    config.setMinIdle(8);
    config.setBlockWhenExhausted(false);// 当Pool中没有对象时不等待,而是直接new个新的

    AbandonedConfig abandonConfig=new AbandonedConfig();
    abandonConfig.setRemoveAbandonedTimeout(300);
    abandonConfig.setRemoveAbandonedOnBorrow(true);
    abandonConfig.setRemoveAbandonedOnMaintenance(true);
    factory=new GenericObjectPool<DataLoader>(this, config, abandonConfig);
}
 
Example 7
Project: cattle   File: LDAPIdentityProvider.java   Source Code and License 5 votes vote down vote up
public void init() {
    if (getContextPool() == null) {
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        PoolConfig.setConfig(config, "ldap.context.pool", "ldap.context.pool.", "global.pool.");
        config.setTestOnBorrow(true);
        LdapServiceContextPoolFactory serviceContextPoolFactory = new LdapServiceContextPoolFactory(getConstantsConfig());
        setContextPool(new GenericObjectPool<>(serviceContextPoolFactory, config));
        AbandonedConfig abandonedConfig = new AbandonedConfig();
        abandonedConfig.setUseUsageTracking(true);
        abandonedConfig.setRemoveAbandonedOnMaintenance(true);
        abandonedConfig.setRemoveAbandonedOnBorrow(true);
        abandonedConfig.setRemoveAbandonedTimeout(60);
        getContextPool().setAbandonedConfig(abandonedConfig);
    }
}
 
Example 8
Project: proctor   File: SvnObjectPools.java   Source Code and License 5 votes vote down vote up
private static <T> ObjectPool<T> createObjectPool(final PooledObjectFactory<T> factory) {
    final GenericObjectPoolConfig objectPoolConfig = new GenericObjectPoolConfig();
    objectPoolConfig.setMinEvictableIdleTimeMillis(TimeUnit.HOURS.toMillis(1)); // arbitrary, but positive so objects do get evicted
    objectPoolConfig.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES.toMillis(10)); // arbitrary, but positive so objects do get evicted
    objectPoolConfig.setJmxEnabled(false);
    objectPoolConfig.setBlockWhenExhausted(false);
    objectPoolConfig.setMaxTotal(-1); // uncapped number of objects in the pool
    final AbandonedConfig abandonedConfig = new AbandonedConfig();
    abandonedConfig.setRemoveAbandonedOnBorrow(true);
    abandonedConfig.setRemoveAbandonedTimeout((int) TimeUnit.MINUTES.toSeconds(30));
    return new GenericObjectPool<T>(factory, objectPoolConfig, abandonedConfig);
}
 
Example 9
Project: commons-dbcp   File: BasicDataSource.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an object pool used to provide pooling support for {@link Connection JDBC connections}.
 *
 * @param factory         the object factory
 * @param poolConfig      the object pool configuration
 * @param abandonedConfig the abandoned objects configuration
 * @return a non-null instance
 */
protected  GenericObjectPool<PoolableConnection> createObjectPool(
        final PoolableConnectionFactory factory, final GenericObjectPoolConfig poolConfig,
        final AbandonedConfig abandonedConfig) {
    GenericObjectPool<PoolableConnection> gop;
    if (abandonedConfig != null &&
            (abandonedConfig.getRemoveAbandonedOnBorrow() ||
                    abandonedConfig.getRemoveAbandonedOnMaintenance())) {
        gop = new GenericObjectPool<>(factory, poolConfig, abandonedConfig);
    }
    else {
        gop = new GenericObjectPool<>(factory, poolConfig);
    }
    return gop;
}
 
Example 10
Project: FKC   File: KryoPoolCommonsImpl.java   Source Code and License 4 votes vote down vote up
public KryoPoolCommonsImpl(GenericObjectPoolConfig genericObjectPoolConfig, PooledObjectFactory<Kryo> pooledObjectFactory, AbandonedConfig abandonedConfig, FKCExceptionHandler fkcExceptionHandler) {
    this.kryoPool = new GenericObjectPool<Kryo>(pooledObjectFactory, genericObjectPoolConfig, abandonedConfig);
    this.fkcExceptionHandler = fkcExceptionHandler;
}
 
Example 11
Project: FKC   File: KryoPool.java   Source Code and License 4 votes vote down vote up
public CommonsBuilder abandonedStrategy(AbandonedConfig abandonedConfig) {
    this.abandonedConfig = abandonedConfig;
    return this;
}
 
Example 12
Project: shachi   File: HBaseResourcePoolDefault.java   Source Code and License 4 votes vote down vote up
public HBaseResourcePoolDefault(final PooledObjectFactory<R> factory, final GenericObjectPoolConfig config, final AbandonedConfig abandonedConfig) {
    super(factory, config, abandonedConfig);
}
 
Example 13
Project: smtp-connection-pool   File: SmtpConnectionPool.java   Source Code and License 4 votes vote down vote up
public SmtpConnectionPool(SmtpConnectionFactory factory, GenericObjectPoolConfig config, AbandonedConfig abandonedConfig) {
  super(factory, config, abandonedConfig);
}
 
Example 14
Project: ezbake-common-java   File: ThriftClientPool.java   Source Code and License 4 votes vote down vote up
/**
 * Initializes a new ThriftClientPool.
 *
 * @param configuration The properties for this instance of the pool
 */
public ThriftClientPool(Properties configuration) {
    this.configuration = new EzProperties(configuration, true);
    /* We only need to use this to get the application name, so we want this to fall out of scope and get garbage
     collected */
    EzBakeApplicationConfigurationHelper appConfig = new EzBakeApplicationConfigurationHelper(configuration);
    this.applicationName = appConfig.getApplicationName();
    this.applicationSecurityId = appConfig.getSecurityID();
    if (Strings.isNullOrEmpty(applicationName)) {
        logger.warn("No application name was found.  Only common services will be discoverable");
    }

    this.thriftConfiguration = new ThriftConfigurationHelper(configuration);

    poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxIdle(thriftConfiguration.getMaxIdleClients());
    poolConfig.setMaxTotal(thriftConfiguration.getMaxPoolClients());
    poolConfig.setMinEvictableIdleTimeMillis(thriftConfiguration.getMillisIdleBeforeEviction());
    poolConfig.setTimeBetweenEvictionRunsMillis(thriftConfiguration.getMillisIdleBeforeEviction());
    poolConfig.setTestOnBorrow(thriftConfiguration.getTestOnBorrow());
    poolConfig.setTestWhileIdle(thriftConfiguration.getTestWhileIdle());
    poolConfig.setBlockWhenExhausted(thriftConfiguration.getBlockWhenExhausted());

    abandonedConfig = new AbandonedConfig();
    abandonedConfig.setLogAbandoned(thriftConfiguration.getLogAbandoned());
    abandonedConfig.setRemoveAbandonedOnBorrow(thriftConfiguration.getRemoveAbandonedOnBorrow());
    abandonedConfig.setRemoveAbandonedOnMaintenance(thriftConfiguration.getRemoveAbandonedOnMaintenance());
    abandonedConfig.setRemoveAbandonedTimeout(thriftConfiguration.getRemoveAbandonedTimeout());

    if(!thriftConfiguration.actuallyPoolClients()) {
        logger.info("Thrift client pool is NOT actually pooling clients!");
    }

    ServiceDiscovery serviceDiscoveryClient = getServiceDiscoveryClient();
    try {
        this.commonServices.addAll(serviceDiscoveryClient.getServices());
    } catch(Exception e) {
        logger.warn("Could not obtain common services!");
        throw new RuntimeException(e);
    }

    RefreshEndpoints(serviceDiscoveryClient);
    RefreshCommonEndpoints(serviceDiscoveryClient);
    closeClient(serviceDiscoveryClient);
}
 
Example 15
Project: seldon-server   File: DbcpFactory.java   Source Code and License 4 votes vote down vote up
private void createDbcp(DbcpConfig conf)
{
	if (!dataSources.containsKey(conf.name))
	{
		try
	    {
			
			Class.forName(conf.driverClassName);
		    
		    DriverManagerConnectionFactory cf =  new DriverManagerConnectionFactory(conf.jdbc,conf.user,conf.password);
		    
		    PoolableConnectionFactory pcf  =  new PoolableConnectionFactory(cf,null);
		    pcf.setValidationQuery(conf.validationQuery);
		    //, pool, null, conf.validationQuery, false, true,abandondedConfig);
			
		    logger.info("Creating pool "+conf.toString());
		    // create a generic pool
		    GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(pcf);
		    pool.setMaxTotal(conf.maxTotal);
		    pool.setMaxIdle(conf.maxIdle);
		    pool.setMinIdle(conf.minIdle);
		    pool.setMaxWaitMillis(conf.maxWait);
		    pool.setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
		    pool.setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
		    pool.setTestWhileIdle(conf.testWhileIdle);
		    pool.setTestOnBorrow(conf.testOnBorrow);
	    
		    AbandonedConfig abandonedConfig = new AbandonedConfig();
		    abandonedConfig.setRemoveAbandonedOnMaintenance(conf.removeAbanadoned);
		    abandonedConfig.setRemoveAbandonedTimeout(conf.removeAbandonedTimeout);
		    abandonedConfig.setLogAbandoned(conf.logAbandonded);
	    
		    pool.setAbandonedConfig(abandonedConfig);
	    
		    pcf.setPool(pool);
		    DataSource ds = new PoolingDataSource(pool);
		    dataSources.put(conf.name, ds);

	    } catch (ClassNotFoundException e) {
			logger.error("Failed to create datasource for "+conf.name+ " with class "+conf.driverClassName);
		}
	   
	}
	else
	{
		logger.error("Pool "+conf.name+" already exists. Can't change existing datasource at present.");
	}
}
 
Example 16
Project: incubator-sentry   File: PoolClientInvocationHandler.java   Source Code and License 4 votes vote down vote up
public PoolClientInvocationHandler(Configuration conf) throws Exception {
  this.conf = conf;
  readConfiguration();
  poolFactory = new SentryServiceClientPoolFactory(conf);
  pool = new GenericObjectPool<SentryPolicyServiceClient>(poolFactory, poolConfig, new AbandonedConfig());
}
 
Example 17
Project: ezbake-common-java   File: ThriftConnectionPool.java   Source Code and License 2 votes vote down vote up
/**
 * Create a new connection pool based on the supplied client and protocol factories as well as the supplied pool
 * configuration.
 *
 * @param clientFactory Factory used to create TServiceClient
 * @param protocolFactory Factory used to generate the protocol used when creating a new TServiceClient for the pool
 * @param poolConfig Configuration object used to determine things like pool evicition, max idle connections,
 *                   max active connections, etc
 */
public ThriftConnectionPool(ClientFactory<T> clientFactory, ProtocolFactory protocolFactory,
                            GenericObjectPoolConfig poolConfig, AbandonedConfig abandonedConfig) {
    this.internalPool = new GenericObjectPool<T>(new ThriftClientFactory(
            clientFactory, protocolFactory), poolConfig, abandonedConfig);
}