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

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

Introduction

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

Prototype

public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive) 

Source Link

Document

Create a new GenericObjectPoolFactory.

Usage

From source file:com.yahoo.sql4d.sql4ddriver.sql.MysqlAccessor.java

private void init() {
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.maxActive = 2;//TODO: Make this configurable.
    config.testOnBorrow = true;//w  ww .  j a va  2  s.c o m
    config.testWhileIdle = true;
    config.timeBetweenEvictionRunsMillis = 10000;
    config.minEvictableIdleTimeMillis = 60000;
    GenericObjectPoolFactory genericObjectPoolFactory = new GenericObjectPoolFactory(this, config);
    pool = genericObjectPoolFactory.createPool();
}

From source file:com.yahoo.sql4d.indexeragent.sql.DBAccessor.java

private void initPool() {
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.maxActive = 2;//TODO: Make this configurable.
    config.testOnBorrow = true;/*  ww w . j  a  v a  2 s  . com*/
    config.testWhileIdle = true;
    config.timeBetweenEvictionRunsMillis = 10000;
    config.minEvictableIdleTimeMillis = 60000;
    GenericObjectPoolFactory genericObjectPoolFactory = new GenericObjectPoolFactory(this, config);
    pool = genericObjectPoolFactory.createPool();
}

From source file:com.ccc.ccm.client.activemq.StoreablePooledConnectionFactory.java

protected ObjectPoolFactory createPoolFactory() {
    return new GenericObjectPoolFactory(null, maximumActive);
}

From source file:org.axonframework.commandhandling.distributed.websockets.WebsocketCommandBusConnectorClient.java

public WebsocketCommandBusConnectorClient(ClientSessionFactory clientSessionFactory, int sessionCount) {
    //Create the pool. Server side connections are bound to the commands in process. Therefore scaling down the
    //amount of connections results in losing callbacks of pending commands. We will therefore never scale down or
    //invalidate connections.
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.maxActive = sessionCount;//from  www . ja  v  a  2 s .  c  om
    config.maxIdle = sessionCount;
    config.maxWait = -1;
    config.minEvictableIdleTimeMillis = -1;
    config.minIdle = 0;
    config.numTestsPerEvictionRun = 0;
    config.softMinEvictableIdleTimeMillis = -1;
    config.testOnBorrow = true;
    config.testOnReturn = false;
    config.testWhileIdle = false;
    config.timeBetweenEvictionRunsMillis = -1;
    config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;

    sessions = new GenericObjectPoolFactory<>(new PoolableObjectFactory<Session>() {
        @Override
        public Session makeObject() throws Exception {
            return clientSessionFactory.createSession(WebsocketCommandBusConnectorClient.this);
        }

        @Override
        public void destroyObject(Session obj) throws Exception {
            if (obj.isOpen())
                obj.close();
        }

        @Override
        public boolean validateObject(Session obj) {
            return obj.isOpen();
        }

        @Override
        public void activateObject(Session obj) throws Exception {
            //
        }

        @Override
        public void passivateObject(Session obj) throws Exception {
            //
        }
    }, config).createPool();
}

From source file:org.fusesource.jms.pool.PooledConnectionFactory.java

/**
 * Creates an ObjectPoolFactory. Its behavior is controlled by the two
 * properties @see #maximumActive and @see #blockIfSessionPoolIsFull.
 *
 * @return the newly created but empty ObjectPoolFactory
 *//*w w  w. j  ava2 s.  c  o m*/
protected ObjectPoolFactory createPoolFactory() {
    if (blockIfSessionPoolIsFull) {
        return new GenericObjectPoolFactory(null, maximumActive);
    } else {
        return new GenericObjectPoolFactory(null, maximumActive, GenericObjectPool.WHEN_EXHAUSTED_FAIL,
                GenericObjectPool.DEFAULT_MAX_WAIT);
    }
}

From source file:org.geotools.referencing.factory.AbstractAuthorityMediator.java

ObjectPool getPool() {
    if (workers == null) {
        // create pool
        PoolableObjectFactory objectFactory = new AuthorityPoolableObjectFactory();
        ObjectPoolFactory poolFactory = new GenericObjectPoolFactory(objectFactory, poolConfig);
        this.setPool(poolFactory.createPool());
    }//from  w  w w . j  a  v  a 2  s .  c  om
    return workers;
}

From source file:org.mobicents.slee.container.profile.ProfileObjectPoolManagement.java

/**
 * /*from  ww w.  j  a va  2  s. com*/
 * @param profileTable
 */
private void createObjectPool(final ProfileTableImpl profileTable) {
    // create the pool
    GenericObjectPoolFactory poolFactory = new GenericObjectPoolFactory(
            new ProfileObjectPoolFactory(profileTable), config);
    final ObjectPool objectPool = poolFactory.createPool();
    final ProfileObjectPool oldObjectPool = pools.put(profileTable.getProfileTableName(),
            new ProfileObjectPool(objectPool));
    if (oldObjectPool != null) {
        // there was an old pool, close it
        try {
            oldObjectPool.close();
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to close old pool for " + profileTable);
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Created Pool for " + profileTable);
    }
}

From source file:org.mobicents.slee.runtime.sbb.SbbObjectPoolManagementImpl.java

/**
 * /*from w  w  w. j a v  a2  s. co  m*/
 * @param serviceID
 * @param sbbID
 */
private void createObjectPool(final ServiceID serviceID, final SbbComponent sbbComponent) {
    // create the pool for the given SbbID
    GenericObjectPoolFactory poolFactory = new GenericObjectPoolFactory(
            new SbbObjectPoolFactory(serviceID, sbbComponent), config);
    final ObjectPool objectPool = poolFactory.createPool();
    final SbbObjectPoolImpl oldObjectPool = pools.put(new ObjectPoolMapKey(serviceID, sbbComponent.getSbbID()),
            new SbbObjectPoolImpl(sbbComponent, serviceID, objectPool));
    if (oldObjectPool != null) {
        // there was an old pool, close it
        try {
            oldObjectPool.close();
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to close old pool for " + serviceID + "and " + sbbComponent);
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Created Pool for " + serviceID + "and " + sbbComponent);
    }
}