Example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

List of usage examples for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool.

Prototype

public GenericObjectPool(PoolableObjectFactory factory, int maxActive) 

Source Link

Document

Create a new GenericObjectPool using the specified values.

Usage

From source file:com.jaspersoft.bigquery.connection.BigQueryConnectionManager.java

private GenericObjectPool<BigQueryConnection> startConnectionsPool() {
    if (connectionsPool == null) {
        connectionsPool = new GenericObjectPool<BigQueryConnection>(connectionFactory, poolConfiguration);
    }/*from  w w  w.  jav a 2 s  .c o  m*/
    return connectionsPool;
}

From source file:com.khubla.cbean.riakkv.RiakKVService.java

/**
 * ctor//from  w  w  w.jav  a  2s. c  o  m
 */
public RiakKVService(CBeanUrl cBeanUrl) {
    this.cBeanUrl = cBeanUrl;
    riakClientPool = new GenericObjectPool<RiakClient>(
            new RiakPoolableObjectFactoryImpl(cBeanUrl.getHostName()), MAX_STORAGESERVICE_CONNECTIONS);
}

From source file:com.khubla.cbean.kvservice.fskv.FSKVService.java

/**
 * ctor//from ww w  . j a  v a2s.  c  o m
 */
public FSKVService(CBeanUrl cBeanUrl) {
    final String rootFS = cBeanUrl.getHostName() + File.separator + cBeanUrl.getClusterName() + File.separator;
    File dir = new File(rootFS);
    dir.mkdirs();
    logger.info("FSKV data is at '" + dir.getAbsolutePath() + "'");
    fileClientPool = new GenericObjectPool<File>(new FSPoolableObjectFactoryImpl(rootFS),
            MAX_STORAGESERVICE_CONNECTIONS);
}

From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.ProcessorChainThreadPool.java

/**
 * Singleton.//from w  w w .ja v a 2s. c  o  m
 */
private ProcessorChainThreadPool(ServletConfig config) {
    theQueue = new LinkedBlockingQueue<ProcessorChainThread>();
    //theQueue = new PriorityBlockingQueue(1000, new ThreadComparator());
    maxActiveProcesses = Integer.parseInt(Util.getInitParameter(config, Constants.MAX_ACTIVE_PROCESSING));
    log.info("Creating thread pool with max active processes = " + maxActiveProcesses);
    thePool = new GenericObjectPool(new BasePoolableObjectFactory() {
        @Override
        public Object makeObject() throws Exception {
            return new Object();
        }
    }, maxActiveProcesses);
}

From source file:net.sf.hajdbc.pool.generic.GenericObjectPoolFactory.java

@Override
public <T, E extends Exception> Pool<T, E> createPool(final PoolProvider<T, E> provider) {
    PoolableObjectFactory<T> factory = new PoolableObjectFactory<T>() {
        @Override/* w ww. jav  a  2 s. c  o  m*/
        public void destroyObject(T object) {
            provider.close(object);
        }

        @Override
        public T makeObject() throws Exception {
            return provider.create();
        }

        @Override
        public boolean validateObject(T object) {
            return provider.isValid(object);
        }

        @Override
        public void activateObject(T object) {
        }

        @Override
        public void passivateObject(T object) {
        }
    };

    final ObjectPool<T> pool = new GenericObjectPool<T>(factory, this.config);

    return new Pool<T, E>() {
        @Override
        public void close() {
            try {
                pool.close();
            } catch (Exception e) {
                logger.log(Level.WARN, e, e.getMessage());
            }
        }

        @Override
        public void release(T item) {
            try {
                pool.returnObject(item);
            } catch (Exception e) {
                logger.log(Level.WARN, e, e.getMessage());
            }
        }

        @Override
        public T take() throws E {
            try {
                return pool.borrowObject();
            } catch (NoSuchElementException e) {
                return provider.create();
            } catch (IllegalStateException e) {
                throw e;
            } catch (Exception e) {
                throw provider.getExceptionClass().cast(e);
            }
        }
    };
}

From source file:com.weibo.api.motan.transport.AbstractPoolClient.java

protected void initPool() {
    poolConfig = new GenericObjectPool.Config();
    poolConfig.minIdle = url.getIntParameter(URLParamType.minClientConnection.getName(),
            URLParamType.minClientConnection.getIntValue());
    poolConfig.maxIdle = url.getIntParameter(URLParamType.maxClientConnection.getName(),
            URLParamType.maxClientConnection.getIntValue());
    poolConfig.maxActive = poolConfig.maxIdle;
    poolConfig.maxWait = url.getIntParameter(URLParamType.requestTimeout.getName(),
            URLParamType.requestTimeout.getIntValue());
    poolConfig.lifo = url.getBooleanParameter(URLParamType.poolLifo.getName(),
            URLParamType.poolLifo.getBooleanValue());
    poolConfig.minEvictableIdleTimeMillis = defaultMinEvictableIdleTimeMillis;
    poolConfig.softMinEvictableIdleTimeMillis = defaultSoftMinEvictableIdleTimeMillis;
    poolConfig.timeBetweenEvictionRunsMillis = defaultTimeBetweenEvictionRunsMillis;
    factory = createChannelFactory();// w w  w . ja v a2s . co  m

    pool = new GenericObjectPool(factory, poolConfig);

    boolean lazyInit = url.getBooleanParameter(URLParamType.lazyInit.getName(),
            URLParamType.lazyInit.getBooleanValue());

    if (!lazyInit) {
        for (int i = 0; i < poolConfig.minIdle; i++) {
            try {
                pool.addObject();
            } catch (Exception e) {
                LoggerUtil.error("NettyClient init pool create connect Error: url=" + url.getUri(), e);
            }
        }
    }
}

From source file:com.gramercysoftware.persistence.dao.GSPDataSourceFactory.java

private ObjectPool createConnectionPool(Properties properties) {
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.maxActive = Integer.parseInt(properties.getProperty("pool.maxActive"));
    config.maxIdle = Integer.parseInt(properties.getProperty("pool.maxIdle"));
    config.minIdle = Integer.parseInt(properties.getProperty("pool.minIdle"));
    config.maxWait = Integer.parseInt(properties.getProperty("pool.maxWait"));

    ObjectPool connectionPool = new GenericObjectPool(null, config);
    return connectionPool;
}

From source file:edu.amc.sakai.user.PoolingLdapConnectionManager.java

/**
 * {@inheritDoc}//  w  w  w.j a  va  2  s.co  m
 */
public void init() {
    super.init();

    if (pool != null) {
        return;
    }

    if (factory == null) {
        factory = new PooledLDAPConnectionFactory();
    }
    factory.setConnectionManager(this);

    Config poolConfig = new Config();
    poolConfig.maxActive = getConfig().getPoolMaxConns();
    poolConfig.maxIdle = getConfig().getPoolMaxConns();
    poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    poolConfig.maxWait = POOL_MAX_WAIT;
    poolConfig.testOnBorrow = true;
    poolConfig.testOnReturn = false;

    pool = new GenericObjectPool(factory, poolConfig);
}

From source file:de.unidue.inf.is.ezdl.dlbackend.database.ApacheDBCPConnectionProvider.java

private PoolingDataSource setupDataSource(String connectURI, String user, String password, boolean autoCommit) {
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.maxActive = 15;//  w  w  w  .j  ava2  s.  com
    config.maxIdle = 10;
    config.minIdle = 3;
    config.maxWait = 1000;

    ObjectPool connectionPool = new GenericObjectPool(null, config);

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, user, password);

    poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null,
            false, true);
    poolableConnectionFactory.setDefaultAutoCommit(autoCommit);
    PoolingDataSource poolingDataSource = new PoolingDataSource(connectionPool);

    return poolingDataSource;
}

From source file:com.baifendian.swordfish.common.hive.metastore.HiveMetaPoolClient.java

protected GenericObjectPool bulidClientPool(String metastoreUris) {
    //  poolConfig
    GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();

    poolConfig.maxActive = maxActive;/*from   w w w.  j a  va 2  s. com*/
    poolConfig.maxIdle = maxIdle;
    poolConfig.minIdle = minIdle;
    poolConfig.maxWait = maxWait;
    poolConfig.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    poolConfig.testWhileIdle = testWhileIdle;
    poolConfig.testOnBorrow = true;
    poolConfig.testOnReturn = true;

    HiveMetaStorePoolFactory clientFactory = new HiveMetaStorePoolFactory(metastoreUris);
    return new GenericObjectPool(clientFactory, poolConfig);
}