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

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

Introduction

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

Prototype

boolean DEFAULT_LIFO

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

Click Source Link

Document

The default LIFO status.

Usage

From source file:com.fjn.helper.frameworkex.apache.commons.pool.connectionPool.ConnectionManager.java

/**
 *
 * @param maxNum/*from  ww  w. ja  v  a  2s  .c o  m*/
 * @param maxIdleCount
 * @param minIdleCount
 * @param maxWaitTime
 *
 */
public void initConnectionPool(int maxNum, int maxIdleCount, int minIdleCount, long maxWaitTime) {
    int maxActive = maxNum;
    byte whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
    long maxWait = maxWaitTime;
    int maxIdle = maxIdleCount;
    int minIdle = minIdleCount;
    boolean testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW;
    boolean testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN;
    long timeBetweenEvictionRunsMillis = GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
    int numTestsPerEvictionRun = GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
    long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    boolean testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE;
    long softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    boolean lifo = GenericObjectPool.DEFAULT_LIFO;
    connPoolFactory = new ConnectionPoolFactory(connFactory, maxActive, whenExhaustedAction, maxWait, maxIdle,
            minIdle, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle, softMinEvictableIdleTimeMillis, lifo);

}

From source file:com.att.cspd.SimpleSipServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    logger.info("the simple sip servlet has been started");
    super.init(servletConfig);

    RABBITMQ_CONN_URL = servletConfig.getInitParameter("rabbitmq_conn_url");
    EXCHANGE_NAME = servletConfig.getInitParameter("exchange_name");
    String pool_max_active = servletConfig.getInitParameter("rabbitmq_pool_max_active");
    String pool_max_idle = servletConfig.getInitParameter("rabbitmq_pool_max_idle");
    String pool_min_idle = servletConfig.getInitParameter("rabbitmq_pool_min_idle");
    String time_between_evication = servletConfig.getInitParameter("rabbitmq_pool_time_between_eviction");
    String idle_time_before_eviction = servletConfig
            .getInitParameter("rabbitmq_pool_idle_time_before_eviction");

    logger.info("INIT PARAM:  rabbitmq_conn_url = " + RABBITMQ_CONN_URL);
    logger.info("INIT PARAM : exchange name  = " + EXCHANGE_NAME);
    logger.info("INIT PARAM : pool max active = " + pool_max_active);
    logger.info("INIT PARAM : pool max idle  = " + pool_max_idle);
    logger.info("INIT PARAM : pool min idle = " + pool_min_idle);
    logger.info("INIT PARAM : time_between_evication  = " + time_between_evication);
    logger.info("INIT PARAM : idle_time_before_eviction  = " + idle_time_before_eviction);

    try {//from  www .  j a v  a 2s . com
        POOL_MAX_ACTIVE = Integer.parseInt(pool_max_active);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the pool max active : " + pool_max_active, e);
    }

    try {
        POOL_MAX_IDLE = Integer.parseInt(pool_max_idle);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the pool max idle : " + pool_max_idle, e);
    }

    try {
        POOL_MIN_IDLE = Integer.parseInt(pool_min_idle);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the pool min idle  : " + pool_min_idle, e);
    }

    try {
        TIME_BETWEEN_EVICTION = Integer.parseInt(time_between_evication);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the time between eviction : " + time_between_evication, e);
    }
    try {
        IDL_TIME_BEFORE_EVICTION = Integer.parseInt(idle_time_before_eviction);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse idle time before eviction : " + idle_time_before_eviction, e);
    }

    /**
     * create static instance of rabbitmq connection pool
     */
    try {

        GenericObjectPool.Config config = new GenericObjectPool.Config();
        config.maxActive = POOL_MAX_ACTIVE;
        config.maxIdle = POOL_MAX_IDLE;
        config.minIdle = POOL_MIN_IDLE;
        config.timeBetweenEvictionRunsMillis = TIME_BETWEEN_EVICTION;
        config.minEvictableIdleTimeMillis = IDL_TIME_BEFORE_EVICTION;
        config.testOnBorrow = true;
        config.testOnReturn = true;
        config.lifo = GenericObjectPool.DEFAULT_LIFO;
        config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;

        pool = new GenericObjectPool<Channel>(new ConnectionPoolableObjectFactory(RABBITMQ_CONN_URL), config);

        //create an initial pool instances.
        /*
        int initSize = 25;
        for (int i =0; i < initSize; i++) {
           try {
              pool.addObject();
           } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
           }
        }
        */

        /*
        pool.setMaxActive(POOL_MAX_ACTIVE);   //maximum connection allowed in the pool (100). If reached, worker thread needs to be blocked to wait.
        pool.setMinIdle(POOL_MIN_IDLE);       //keep minimum idle connection (set to 3) in pool in all time.
        pool.setMaxIdle(POOL_MAX_IDLE);      //No minimum to create new connection when needed (set to -1).
        pool.setTimeBetweenEvictionRunsMillis(TIME_BETWEEN_EVICTION);   //wait up eviction thread in 10 second
        pool.setMinEvictableIdleTimeMillis(IDL_TIME_BEFORE_EVICTION);  //kill the idle connection that is 5 second old
        pool.setTestOnBorrow(true);   //sanity checking when getting connection from pool.
        pool.setTestOnReturn(true);   //sanity check when returning connection to pool.
        */

    } catch (IOException ex) {

        logger.error("RabbitMQ Pool failed to create. Error = " + ex.getMessage());
        throw new ServletException(ex);
    }

    //logger.info("HELLO... FINISHED LOADING THE RABBITMQ CONNECTION/CHANNEL POOL");

}

From source file:org.apache.hadoop.hive.metastore.datasource.DbCPDataSourceProvider.java

@Override
public DataSource create(Configuration hdpConfig) throws SQLException {

    LOG.debug("Creating dbcp connection pool for the MetaStore");

    String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig);
    String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig);
    String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig);
    int maxPoolSize = hdpConfig.getInt(MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS.getVarname(),
            ((Long) MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS.getDefaultVal()).intValue());
    long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L);
    int connectionMaxIlde = hdpConfig.getInt(CONNECTION_MAX_IDLE_PROPERTY, GenericObjectPool.DEFAULT_MAX_IDLE);
    int connectionMinIlde = hdpConfig.getInt(CONNECTION_MIN_IDLE_PROPERTY, GenericObjectPool.DEFAULT_MIN_IDLE);
    boolean testOnBorrow = hdpConfig.getBoolean(CONNECTION_TEST_BORROW_PROPERTY,
            GenericObjectPool.DEFAULT_TEST_ON_BORROW);
    long evictionTimeMillis = hdpConfig.getLong(CONNECTION_MIN_EVICT_MILLIS_PROPERTY,
            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    boolean testWhileIdle = hdpConfig.getBoolean(CONNECTION_TEST_IDLEPROPERTY,
            GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
    long timeBetweenEvictionRuns = hdpConfig.getLong(CONNECTION_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    int numTestsPerEvictionRun = hdpConfig.getInt(CONNECTION_NUM_TESTS_PER_EVICTION_RUN,
            GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
    boolean testOnReturn = hdpConfig.getBoolean(CONNECTION_TEST_ON_RETURN,
            GenericObjectPool.DEFAULT_TEST_ON_RETURN);
    long softMinEvictableIdleTimeMillis = hdpConfig.getLong(CONNECTION_SOFT_MIN_EVICTABLE_IDLE_TIME,
            GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    boolean lifo = hdpConfig.getBoolean(CONNECTION_LIFO, GenericObjectPool.DEFAULT_LIFO);

    GenericObjectPool objectPool = new GenericObjectPool();
    objectPool.setMaxActive(maxPoolSize);
    objectPool.setMaxWait(connectionTimeout);
    objectPool.setMaxIdle(connectionMaxIlde);
    objectPool.setMinIdle(connectionMinIlde);
    objectPool.setTestOnBorrow(testOnBorrow);
    objectPool.setTestWhileIdle(testWhileIdle);
    objectPool.setMinEvictableIdleTimeMillis(evictionTimeMillis);
    objectPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
    objectPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    objectPool.setTestOnReturn(testOnReturn);
    objectPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
    objectPool.setLifo(lifo);//from   w w w. j av a 2  s .c om

    ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, user, passwd);
    // This doesn't get used, but it's still necessary, see
    // https://git1-us-west.apache.org/repos/asf?p=commons-dbcp.git;a=blob;f=doc/ManualPoolingDataSourceExample.java;
    // h=f45af2b8481f030b27364e505984c0eef4f35cdb;hb=refs/heads/DBCP_1_5_x_BRANCH
    new PoolableConnectionFactory(connFactory, objectPool, null, null, false, true);

    return new PoolingDataSource(objectPool);
}

From source file:org.mobicents.servlet.sip.example.SimpleSipServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    logger.info("the simple sip servlet has been started");
    super.init(servletConfig);

    RABBITMQ_CONN_URL = servletConfig.getInitParameter("rabbitmq_conn_url");
    EXCHANGE_NAME = servletConfig.getInitParameter("exchange_name");
    String pool_max_active = servletConfig.getInitParameter("rabbitmq_pool_max_active");
    String pool_max_idle = servletConfig.getInitParameter("rabbitmq_pool_max_idle");
    String pool_min_idle = servletConfig.getInitParameter("rabbitmq_pool_min_idle");
    String time_between_evication = servletConfig.getInitParameter("rabbitmq_pool_time_between_eviction");
    String idle_time_before_eviction = servletConfig
            .getInitParameter("rabbitmq_pool_idle_time_before_eviction");

    logger.info("INIT PARAM:  rabbitmq_conn_url = " + RABBITMQ_CONN_URL);
    logger.info("INIT PARAM : exchange name  = " + EXCHANGE_NAME);
    logger.info("INIT PARAM : pool max active = " + pool_max_active);
    logger.info("INIT PARAM : pool max idle  = " + pool_max_idle);
    logger.info("INIT PARAM : pool min idle = " + pool_min_idle);
    logger.info("INIT PARAM : time_between_evication  = " + time_between_evication);
    logger.info("INIT PARAM : idle_time_before_eviction  = " + idle_time_before_eviction);

    try {/*  ww w  . j ava2 s.co  m*/
        POOL_MAX_ACTIVE = Integer.parseInt(pool_max_active);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the pool max active : " + pool_max_active, e);
    }

    try {
        POOL_MAX_IDLE = Integer.parseInt(pool_max_idle);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the pool max idle : " + pool_max_idle, e);
    }

    try {
        POOL_MIN_IDLE = Integer.parseInt(pool_min_idle);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the pool min idle  : " + pool_min_idle, e);
    }

    try {
        TIME_BETWEEN_EVICTION = Integer.parseInt(time_between_evication);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse the time between eviction : " + time_between_evication, e);
    }
    try {
        IDL_TIME_BEFORE_EVICTION = Integer.parseInt(idle_time_before_eviction);
    } catch (NumberFormatException e) {
        logger.error("Impossible to parse idle time before eviction : " + idle_time_before_eviction, e);
    }

    /**
     * create static instance of rabbitmq connection pool
     */
    try {

        GenericObjectPool.Config config = new GenericObjectPool.Config();
        config.maxActive = POOL_MAX_ACTIVE;
        config.maxIdle = POOL_MAX_IDLE;
        config.minIdle = POOL_MIN_IDLE;
        config.timeBetweenEvictionRunsMillis = TIME_BETWEEN_EVICTION;
        config.minEvictableIdleTimeMillis = IDL_TIME_BEFORE_EVICTION;
        config.testOnBorrow = false;
        config.testOnReturn = false;
        config.lifo = GenericObjectPool.DEFAULT_LIFO;
        config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;

        pool = new GenericObjectPool<Channel>(new ConnectionPoolableObjectFactory(RABBITMQ_CONN_URL), config);

        //create an initial pool instances.
        /*
        int initSize = 25;
        for (int i =0; i < initSize; i++) {
           try {
              pool.addObject();
           } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
           }
        }
        */

        /*
        pool.setMaxActive(POOL_MAX_ACTIVE);   //maximum connection allowed in the pool (100). If reached, worker thread needs to be blocked to wait.
        pool.setMinIdle(POOL_MIN_IDLE);       //keep minimum idle connection (set to 3) in pool in all time.
        pool.setMaxIdle(POOL_MAX_IDLE);      //No minimum to create new connection when needed (set to -1).
        pool.setTimeBetweenEvictionRunsMillis(TIME_BETWEEN_EVICTION);   //wait up eviction thread in 10 second
        pool.setMinEvictableIdleTimeMillis(IDL_TIME_BEFORE_EVICTION);  //kill the idle connection that is 5 second old
        pool.setTestOnBorrow(true);   //sanity checking when getting connection from pool.
        pool.setTestOnReturn(true);   //sanity check when returning connection to pool.
        */

    } catch (IOException ex) {

        logger.error("RabbitMQ Pool failed to create. Error = " + ex.getMessage());
        throw new ServletException(ex);
    }

    //logger.info("HELLO... FINISHED LOADING THE RABBITMQ CONNECTION/CHANNEL POOL");

}