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

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

Introduction

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

Prototype

byte WHEN_EXHAUSTED_BLOCK

To view the source code for org.apache.commons.pool.impl GenericObjectPool WHEN_EXHAUSTED_BLOCK.

Click Source Link

Document

A "when exhausted action" type indicating that when the pool is exhausted (i.e., the maximum number of active objects has been reached), the #borrowObject method should block until a new object is available, or the #getMaxWait maximum wait time has been reached.

Usage

From source file:org.alinous.plugin.mysql.MySQLDataSource.java

public void init(AlinousCore core) throws DataSourceException {
    this.logger = core.getLogger();

    try {/*www  .j  a  v a 2 s  . co m*/
        this.driver = MySQLDriverSingleton.getDriver(core);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        throw new DataSourceException(e);
    } catch (InstantiationException e) {
        throw new DataSourceException(e);
    } catch (IllegalAccessException e) {
        throw new DataSourceException(e);
    } catch (Throwable e) {
        throw new DataSourceException(e);
    }

    this.factory = new MySQLConnectionFactory(this.driver, this.user, this.pass, this.uri);
    this.connectionPool = new GenericObjectPool(this.factory);
    this.connectionPool.setMaxActive(32);
    this.connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    this.connectionPool.setTestOnBorrow(true);
    this.connectionPool.setMinEvictableIdleTimeMillis(1000 * 60 * 5);

    this.typeHelper = new TypeHelper(this);

    this.core = core;
}

From source file:org.apache.airavata.api.server.handler.AiravataServerHandler.java

public AiravataServerHandler() {
    try {/*from  w ww  . j a  v a2s.  c o  m*/
        statusPublisher = MessagingFactory.getPublisher(Type.STATUS);
        experimentPublisher = MessagingFactory.getPublisher(Type.EXPERIMENT_LAUNCH);

        GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
        poolConfig.maxActive = 100;
        poolConfig.minIdle = 5;
        poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
        poolConfig.testOnBorrow = true;
        poolConfig.testWhileIdle = true;
        poolConfig.numTestsPerEvictionRun = 10;
        poolConfig.maxWait = 3000;

        sharingClientPool = new ThriftClientPool<>(tProtocol -> new SharingRegistryService.Client(tProtocol),
                poolConfig, ServerSettings.getSharingRegistryHost(),
                Integer.parseInt(ServerSettings.getSharingRegistryPort()));
        registryClientPool = new ThriftClientPool<>(tProtocol -> new RegistryService.Client(tProtocol),
                poolConfig, ServerSettings.getRegistryServerHost(),
                Integer.parseInt(ServerSettings.getRegistryServerPort()));
        csClientPool = new ThriftClientPool<>(tProtocol -> new CredentialStoreService.Client(tProtocol),
                poolConfig, ServerSettings.getCredentialStoreServerHost(),
                Integer.parseInt(ServerSettings.getCredentialStoreServerPort()));

        initSharingRegistry();
    } catch (ApplicationSettingsException e) {
        logger.error("Error occured while reading airavata-server properties..", e);
    } catch (AiravataException e) {
        logger.error("Error occured while reading airavata-server properties..", e);
    } catch (TException e) {
        logger.error("Error occured while reading airavata-server properties..", e);
    }
}

From source file:org.apache.aries.transaction.jms.internal.ConnectionPool.java

/**
 * Configure whether the createSession method should block when there are no more idle sessions and the
 * pool already contains the maximum number of active sessions.  If false the create method will fail
 * and throw an exception./*from w  ww  .  java2 s  .c o m*/
 *
 * @param block
 *       Indicates whether blocking should be used to wait for more space to create a session.
 */
public void setBlockIfSessionPoolIsFull(boolean block) {
    this.sessionPool.setWhenExhaustedAction(
            (block ? GenericObjectPool.WHEN_EXHAUSTED_BLOCK : GenericObjectPool.WHEN_EXHAUSTED_FAIL));
}

From source file:org.apache.aries.transaction.jms.internal.ConnectionPool.java

public boolean isBlockIfSessionPoolIsFull() {
    return this.sessionPool.getWhenExhaustedAction() == GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
}

From source file:org.apache.camel.component.rabbitmq.RabbitMQProducer.java

/**
 * Open connection and initialize channel pool
 *///w  ww .  j a  va 2  s  .  c  om
private void openConnectionAndChannelPool() throws Exception {
    log.trace("Creating connection...");
    this.conn = getEndpoint().connect(executorService);
    log.debug("Created connection: {}", conn);

    log.trace("Creating channel pool...");
    channelPool = new GenericObjectPool<Channel>(new PoolableChannelFactory(this.conn),
            getEndpoint().getChannelPoolMaxSize(), GenericObjectPool.WHEN_EXHAUSTED_BLOCK,
            getEndpoint().getChannelPoolMaxWait());
    if (getEndpoint().isDeclare()) {
        execute(new ChannelCallback<Void>() {
            @Override
            public Void doWithChannel(Channel channel) throws Exception {
                getEndpoint().declareExchangeAndQueue(channel);
                return null;
            }
        });
    }
}

From source file:org.apache.hadoop.hive.metastore.MyXid.java

public synchronized static void checkGlobalPoolingDataSource(String url, String user, String pass) {
    if (globalDbConPool != null) {
        return;/*from w ww.  j  a va2  s . com*/
    } else {
        LOG.error(
                "#################################################################### init master connetion pool");
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, pass);
        GenericObjectPool connectionPool = new GenericObjectPool();
        connectionPool.setMaxActive(poolActiveSize);
        connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
        connectionPool.setMaxWait(10000);
        connectionPool.setTestOnBorrow(true);
        connectionPool.setTestWhileIdle(true);
        connectionPool.setTimeBetweenEvictionRunsMillis(30000);
        connectionPool.setMinEvictableIdleTimeMillis(300000);
        connectionPool.setLifo(true);

        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, null, null, false, true);

        globalDbConPool = new PoolingDataSource(connectionPool);
        LOG.error(
                "#################################################################### init global connetion pool over");
    }
}

From source file:org.apache.hadoop.hive.metastore.MyXid.java

public synchronized static PoolingDataSource getSegPoolingDataSource(String url, String user, String pass) {
    url = url.toLowerCase();/*from  www.  j a  va2s . co  m*/
    PoolingDataSource pool = SegmentDbConPool.get(url);
    if (pool != null) {
        return pool;
    } else {
        LOG.debug(
                "#################################################################### init global connetion pool:"
                        + url);
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, pass);
        GenericObjectPool connectionPool = new GenericObjectPool();
        connectionPool.setMaxActive(poolActiveSize);
        connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
        connectionPool.setMaxWait(10000);
        connectionPool.setTestOnBorrow(true);
        connectionPool.setTestWhileIdle(true);
        connectionPool.setTimeBetweenEvictionRunsMillis(30000);
        connectionPool.setMinEvictableIdleTimeMillis(300000);
        connectionPool.setLifo(true);

        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, null, null, false, true);

        pool = new PoolingDataSource(connectionPool);
        SegmentDbConPool.put(url, pool);

        LOG.debug(
                "#################################################################### init global connetion pool:"
                        + url + " over");
        return pool;
    }
}

From source file:org.apache.jackrabbit.oak.security.authentication.ldap.impl.LdapIdentityProvider.java

/**
 * Initializes the ldap identity provider.
 */// w w w  .ja  v  a2s  .c om
private void init() {
    if (adminConnectionFactory != null) {
        throw new IllegalStateException("Provider already initialized.");
    }

    // make sure the JVM supports the TLSv1.1
    try {
        enabledSSLProtocols = null;
        SSLContext.getInstance("TLSv1.1");
    } catch (NoSuchAlgorithmException e) {
        log.warn("JDK does not support TLSv1.1. Disabling it.");
        enabledSSLProtocols = new String[] { "TLSv1" };
    }

    // setup admin connection pool
    LdapConnectionConfig cc = createConnectionConfig();
    String bindDN = config.getBindDN();
    if (bindDN != null && !bindDN.isEmpty()) {
        cc.setName(bindDN);
        cc.setCredentials(config.getBindPassword());
    }
    adminConnectionFactory = new ValidatingPoolableLdapConnectionFactory(cc);
    if (config.getAdminPoolConfig().lookupOnValidate()) {
        adminConnectionFactory.setValidator(new LookupLdapConnectionValidator());
    } else {
        adminConnectionFactory.setValidator(new DefaultLdapConnectionValidator());
    }
    if (config.getAdminPoolConfig().getMaxActive() != 0) {
        adminPool = new LdapConnectionPool(adminConnectionFactory);
        adminPool.setTestOnBorrow(true);
        adminPool.setMaxActive(config.getAdminPoolConfig().getMaxActive());
        adminPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    }

    // setup unbound connection pool. let's create a new version of the config
    cc = createConnectionConfig();

    userConnectionFactory = new PoolableUnboundConnectionFactory(cc);
    if (config.getUserPoolConfig().lookupOnValidate()) {
        userConnectionFactory.setValidator(new UnboundLookupConnectionValidator());
    } else {
        userConnectionFactory.setValidator(new UnboundConnectionValidator());
    }
    if (config.getUserPoolConfig().getMaxActive() != 0) {
        userPool = new UnboundLdapConnectionPool(userConnectionFactory);
        userPool.setTestOnBorrow(true);
        userPool.setMaxActive(config.getUserPoolConfig().getMaxActive());
        userPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    }

    log.info("LdapIdentityProvider initialized: {}", config);
}

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;//ww w.  ja v a2  s . c o  m
    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.datacleaner.util.ws.PooledServiceSession.java

/**
 * Creates a connection pool that can be used for one or more
 * {@link PooledServiceSession} objects.
 * //  w w  w  .  j  av a 2s. c om
 * @param maxConnections
 * @return
 */
public static GenericObjectPool<Integer> createConnectionPool(int maxConnections) {
    GenericObjectPool<Integer> connectionPool = new GenericObjectPool<Integer>(
            new ConnectionPoolObjectFactory());
    connectionPool.setMaxActive(maxConnections);
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    return connectionPool;
}