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

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

Introduction

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

Prototype

byte WHEN_EXHAUSTED_GROW

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

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 simply create a new object anyway.

Usage

From source file:org.apache.wookie.tests.beans.JPAPersistenceTest.java

/**
 * Set up JPA persistence runtime test environment.
 * /*ww w.  jav a 2 s  . c  o m*/
 * @throws Exception
 */
@Before
public void setUpPerTest() throws Exception {
    logger.info("JPA set up test");

    // load database configuration from environment
    String testDatabaseDir = (System.getProperty("user.dir") + "/build/test-database")
            .replace(File.separatorChar, '/');
    dbUser = getSystemProperty(DB_USER_PROPERTY_NAME, "java");
    dbPassword = getSystemProperty(DB_PASSWORD_PROPERTY_NAME, "java");
    dbDriver = getSystemProperty(DB_DRIVER_CLASS_PROPERTY_NAME, "org.apache.derby.jdbc.EmbeddedDriver");
    dbUri = getSystemProperty(DB_URI_PROPERTY_NAME, "jdbc:derby:" + testDatabaseDir + "/widgetdb;create=true");
    dbType = getSystemProperty(DB_TYPE_PROPERTY_NAME, "derby");

    // load driver
    Class.forName(dbDriver);

    // test connection
    Connection conn = DriverManager.getConnection(dbUri, dbUser, dbPassword);
    conn.close();

    // construct pooling datasource
    connectionPool = new GenericObjectPool(null, 0, GenericObjectPool.WHEN_EXHAUSTED_GROW, 0, 5);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbUri, dbUser, dbPassword);
    new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
    DataSource dataSource = new PoolingDataSource(connectionPool);

    // create JNDI context
    rootContext = new InitialContext();
    Context namingContext = lookupOrCreateNamingContext(rootContext, "java:comp");
    namingContext = lookupOrCreateNamingContext(namingContext, "env");
    lookupOrCreateNamingContext(namingContext, "jdbc");

    // bind datasource to JNDI context
    rootContext.rebind(JPAPersistenceManager.WIDGET_DATABASE_JNDI_DATASOURCE_FULL_NAME, dataSource);

    // initialize persistence manager factory and persistence manager;
    // truncate and initialize persistent store
    Configuration configuration = new PropertiesConfiguration();
    configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_CLASS_NAME_PROPERTY_NAME,
            JPAPersistenceManager.class.getName());
    configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_INITIALIZE_STORE_PROPERTY_NAME,
            "true");
    configuration.setProperty(JPAPersistenceManager.PERSISTENCE_MANAGER_CACHE_SIZE_PROPERTY_NAME, "1000");
    configuration.setProperty(JPAPersistenceManager.PERSISTENCE_MANAGER_DB_TYPE_PROPERTY_NAME, dbType);
    PersistenceManagerFactory.initialize(configuration);

    logger.info("JPA test set up");
    configured = true;
}

From source file:org.dataconservancy.dcs.util.PooledKeyDigestPathAlgorithm.java

/**
 * Initializes a pool of 20 MessageDigest objects.  If the pool runs out of objects, the pool will grow.
 *
 * @param algo//from   w w w.  j  a va 2  s . c  o m
 * @param width
 * @param depth
 * @param suffix
 */
public PooledKeyDigestPathAlgorithm(String algo, int width, int depth, String suffix) {
    super(algo, width, depth, suffix);

    this.algorithm = algo;
    this.mdPool = new GenericObjectPool<MessageDigest>(new MessageDigestPoolableObjectFactory(), POOL_MAX_SIZE,
            GenericObjectPool.WHEN_EXHAUSTED_GROW, POOL_TIMEOUT);
}

From source file:org.dspace.storage.rdbms.DataSourceInit.java

public static DataSource getDatasource() throws SQLException {
    if (dataSource != null) {
        return dataSource;
    }/*from ww w  .  ja v a 2  s  .c o  m*/

    try {
        // Register basic JDBC driver
        Class driverClass = Class.forName(ConfigurationManager.getProperty("db.driver"));
        Driver basicDriver = (Driver) driverClass.newInstance();
        DriverManager.registerDriver(basicDriver);

        // Read pool configuration parameter or use defaults
        // Note we check to see if property is null; getIntProperty returns
        // '0' if the property is not set OR if it is actually set to zero.
        // But 0 is a valid option...
        int maxConnections = ConfigurationManager.getIntProperty("db.maxconnections");

        if (ConfigurationManager.getProperty("db.maxconnections") == null) {
            maxConnections = 30;
        }

        int maxWait = ConfigurationManager.getIntProperty("db.maxwait");

        if (ConfigurationManager.getProperty("db.maxwait") == null) {
            maxWait = 5000;
        }

        int maxIdle = ConfigurationManager.getIntProperty("db.maxidle");

        if (ConfigurationManager.getProperty("db.maxidle") == null) {
            maxIdle = -1;
        }

        boolean useStatementPool = ConfigurationManager.getBooleanProperty("db.statementpool", true);

        // Create object pool
        ObjectPool connectionPool = new GenericObjectPool(null, // PoolableObjectFactory
                // - set below
                maxConnections, // max connections
                GenericObjectPool.WHEN_EXHAUSTED_BLOCK, maxWait, // don't
                // block
                // more than 5
                // seconds
                maxIdle, // max idle connections (unlimited)
                true, // validate when we borrow connections from pool
                false // don't bother validation returned connections
        );

        // ConnectionFactory the pool will use to create connections.
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                ConfigurationManager.getProperty("db.url"), ConfigurationManager.getProperty("db.username"),
                ConfigurationManager.getProperty("db.password"));

        //
        // Now we'll create the PoolableConnectionFactory, which wraps
        // the "real" Connections created by the ConnectionFactory with
        // the classes that implement the pooling functionality.
        //
        String validationQuery = "SELECT 1";

        // Oracle has a slightly different validation query
        if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) {
            validationQuery = "SELECT 1 FROM DUAL";
        }

        GenericKeyedObjectPoolFactory statementFactory = null;
        if (useStatementPool) {
            // The statement Pool is used to pool prepared statements.
            GenericKeyedObjectPool.Config statementFactoryConfig = new GenericKeyedObjectPool.Config();
            // Just grow the pool size when needed.
            //
            // This means we will never block when attempting to
            // create a query. The problem is unclosed statements,
            // they can never be reused. So if we place a maximum
            // cap on them, then we might reach a condition where
            // a page can only be viewed X number of times. The
            // downside of GROW_WHEN_EXHAUSTED is that this may
            // allow a memory leak to exist. Both options are bad,
            // but I'd prefer a memory leak over a failure.
            //
            // FIXME: Perhaps this decision should be derived from config parameters?
            statementFactoryConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;

            statementFactory = new GenericKeyedObjectPoolFactory(null, statementFactoryConfig);
        }

        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, statementFactory, validationQuery, // validation query
                false, // read only is not default for now
                false); // Autocommit defaults to none

        //
        // Finally, we create the PoolingDataSource itself...
        //
        PoolingDataSource poolingDataSource = new PoolingDataSource();

        //
        // ...and register our pool with it.
        //
        poolingDataSource.setPool(connectionPool);

        dataSource = poolingDataSource;
        return poolingDataSource;
    } catch (Exception e) {
        // Need to be able to catch other exceptions. Pretend they are
        // SQLExceptions, but do log
        log.warn("Exception initializing DB pool", e);
        throw new SQLException(e.toString(), e);
    }
}

From source file:org.dspace.storage.rdbms.MockDatabaseManager.java

/**
 * Initialize the DatabaseManager./*w w w  . j  a v a 2  s . c o m*/
 */
@Mock
private static synchronized void initialize() throws SQLException {
    if (initialized) {
        return;
    }

    try {
        // Register basic JDBC driver
        Class.forName(ConfigurationManager.getProperty("db.driver"));

        // Register the DBCP driver
        Class.forName("org.apache.commons.dbcp.PoolingDriver");

        // Read pool configuration parameter or use defaults
        // Note we check to see if property is null; getIntProperty returns
        // '0' if the property is not set OR if it is actually set to zero.
        // But 0 is a valid option...
        int maxConnections = ConfigurationManager.getIntProperty("db.maxconnections");

        if (ConfigurationManager.getProperty("db.maxconnections") == null) {
            maxConnections = 30;
        }

        int maxWait = ConfigurationManager.getIntProperty("db.maxwait");

        if (ConfigurationManager.getProperty("db.maxwait") == null) {
            maxWait = 5000;
        }

        int maxIdle = ConfigurationManager.getIntProperty("db.maxidle");

        if (ConfigurationManager.getProperty("db.maxidle") == null) {
            maxIdle = -1;
        }

        boolean useStatementPool = ConfigurationManager.getBooleanProperty("db.statementpool", true);

        // Create object pool
        connectionPool = new GenericObjectPool(null, // PoolableObjectFactory
                // - set below
                maxConnections, // max connections
                GenericObjectPool.WHEN_EXHAUSTED_BLOCK, maxWait, // don't
                // block
                // more than 5
                // seconds
                maxIdle, // max idle connections (unlimited)
                true, // validate when we borrow connections from pool
                false // don't bother validation returned connections
        );

        // ConnectionFactory the pool will use to create connections.
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                ConfigurationManager.getProperty("db.url"), ConfigurationManager.getProperty("db.username"),
                ConfigurationManager.getProperty("db.password"));

        //
        // Now we'll create the PoolableConnectionFactory, which wraps
        // the "real" Connections created by the ConnectionFactory with
        // the classes that implement the pooling functionality.
        //
        String validationQuery = "SELECT 1";

        // Oracle has a slightly different validation query
        if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) {
            validationQuery = "SELECT 1 FROM DUAL";
        }

        GenericKeyedObjectPoolFactory statementFactory = null;
        if (useStatementPool) {
            // The statement Pool is used to pool prepared statements.
            GenericKeyedObjectPool.Config statementFactoryConfig = new GenericKeyedObjectPool.Config();
            // Just grow the pool size when needed.
            //
            // This means we will never block when attempting to
            // create a query. The problem is unclosed statements,
            // they can never be reused. So if we place a maximum
            // cap on them, then we might reach a condition where
            // a page can only be viewed X number of times. The
            // downside of GROW_WHEN_EXHAUSTED is that this may
            // allow a memory leak to exist. Both options are bad,
            // but I'd prefer a memory leak over a failure.
            //
            // Perhaps this decision should be derived from config parameters?
            statementFactoryConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;

            statementFactory = new GenericKeyedObjectPoolFactory(null, statementFactoryConfig);
        }

        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, statementFactory, validationQuery, // validation query
                false, // read only is not default for now
                false); // Autocommit defaults to none

        // Obtain a poolName from the config, default is "dspacepool"
        if (ConfigurationManager.getProperty("db.poolname") != null) {
            poolName = ConfigurationManager.getProperty("db.poolname");
        }

        //
        // Finally, we get the PoolingDriver itself...
        //
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");

        //
        // ...and register our pool with it.
        //
        if (driver != null)
            driver.registerPool(poolName, connectionPool);

        //preload the contents of the database
        String s = new String();
        StringBuilder sb = new StringBuilder();

        String schemaPath = System.getProperty("db.schema.path");
        if (null == schemaPath)
            throw new IllegalArgumentException("System property db.schema.path must be defined");

        FileReader fr = new FileReader(new File(schemaPath));
        BufferedReader br = new BufferedReader(fr);

        while ((s = br.readLine()) != null) {
            //we skip white lines and comments
            if (!"".equals(s.trim()) && !s.trim().startsWith("--")) {
                sb.append(s);
            }
        }
        br.close();

        //we use ";" as a delimiter for each request. This assumes no triggers
        //nor other calls besides CREATE TABLE, CREATE SEQUENCE and INSERT
        //exist in the file
        String[] stmts = sb.toString().split(";");

        //stablish the connection using the pool
        Connection con = DriverManager.getConnection("jdbc:apache:commons:dbcp:" + poolName);
        Statement st = con.createStatement();

        for (int i = 0; i < stmts.length; i++) {
            // we ensure that there is no spaces before or after the request string
            // in order to not execute empty statements
            if (!stmts[i].trim().equals("")) {
                st.executeUpdate(stmts[i]);
                log.debug("Loading into database: " + stmts[i]);
            }
        }

        //commit changes
        con.commit();
        con.close();

        // Old SimplePool init
        //DriverManager.registerDriver(new SimplePool());
        initialized = true;
    } catch (SQLException se) {
        // Simply throw up SQLExceptions
        throw se;
    } catch (Exception e) {
        // Need to be able to catch other exceptions. Pretend they are
        // SQLExceptions, but do log
        log.warn("Exception initializing DB pool", e);
        throw new SQLException(e.toString());
    }
}

From source file:org.jamwiki.Environment.java

/**
 * Initialize the default property values.
 *//*  www.j a  va  2s . co  m*/
private static void initDefaultProperties() {
    defaults = new Properties();
    defaults.setProperty(PROP_BASE_COOKIE_EXPIRE, "31104000");
    defaults.setProperty(PROP_BASE_DEFAULT_TOPIC, "MainPage");
    defaults.setProperty(PROP_BASE_FILE_DIR, "");
    defaults.setProperty(PROP_BASE_INITIALIZED, Boolean.FALSE.toString());
    defaults.setProperty(PROP_BASE_LOGO_IMAGE, "logo_oliver.gif");
    defaults.setProperty(PROP_BASE_META_DESCRIPTION, "");
    // defaults.setProperty(PROP_BASE_PERSISTENCE_TYPE,
    // WikiBase.PERSISTENCE_INTERNAL);
    // defaults.setProperty(PROP_BASE_SEARCH_ENGINE,
    // SearchEngine.SEARCH_ENGINE_LUCENE);
    defaults.setProperty(PROP_BASE_WIKI_VERSION, "0.0.0");
    defaults.setProperty(PROP_CACHE_INDIVIDUAL_SIZE, "500");
    defaults.setProperty(PROP_CACHE_MAX_AGE, "300");
    defaults.setProperty(PROP_CACHE_MAX_IDLE_AGE, "150");
    defaults.setProperty(PROP_CACHE_TOTAL_SIZE, "1000");
    defaults.setProperty(PROP_DB_DRIVER, "");
    defaults.setProperty(PROP_DB_PASSWORD, "");
    defaults.setProperty(PROP_DB_TYPE, "");
    defaults.setProperty(PROP_DB_URL, "");
    defaults.setProperty(PROP_DB_USERNAME, "");
    defaults.setProperty(PROP_DBCP_MAX_ACTIVE, "10");
    defaults.setProperty(PROP_DBCP_MAX_IDLE, "3");
    defaults.setProperty(PROP_DBCP_MIN_EVICTABLE_IDLE_TIME, "600");
    defaults.setProperty(PROP_DBCP_NUM_TESTS_PER_EVICTION_RUN, "5");
    defaults.setProperty(PROP_DBCP_TEST_ON_BORROW, Boolean.TRUE.toString());
    defaults.setProperty(PROP_DBCP_TEST_ON_RETURN, Boolean.TRUE.toString());
    defaults.setProperty(PROP_DBCP_TEST_WHILE_IDLE, Boolean.TRUE.toString());
    defaults.setProperty(PROP_DBCP_TIME_BETWEEN_EVICTION_RUNS, "120");
    defaults.setProperty(PROP_DBCP_WHEN_EXHAUSTED_ACTION,
            String.valueOf(GenericObjectPool.WHEN_EXHAUSTED_GROW));
    defaults.setProperty(PROP_EMAIL_REPLY_ADDRESS, "");
    defaults.setProperty(PROP_EMAIL_SMTP_HOST, "");
    defaults.setProperty(PROP_EMAIL_SMTP_PASSWORD, "");
    defaults.setProperty(PROP_EMAIL_SMTP_USERNAME, "");
    defaults.setProperty(PROP_ENCRYPTION_ALGORITHM, "SHA-512");
    defaults.setProperty(PROP_EXTERNAL_LINK_NEW_WINDOW, Boolean.FALSE.toString());
    defaults.setProperty(PROP_FILE_BLACKLIST, "bat,bin,exe,htm,html,js,jsp,php,sh");
    // defaults.setProperty(PROP_FILE_BLACKLIST_TYPE,
    // String.valueOf(WikiBase.UPLOAD_BLACKLIST));
    defaults.setProperty(PROP_FILE_DIR_FULL_PATH, Environment.retrieveDefaultUploadDirectory());
    defaults.setProperty(PROP_FILE_DIR_RELATIVE_PATH, Environment.retrieveDefaultRelativeUploadDirectory());
    // size is in bytes
    defaults.setProperty(PROP_FILE_MAX_FILE_SIZE, "2000000");
    defaults.setProperty(PROP_FILE_SERVER_URL, "");
    defaults.setProperty(PROP_FILE_WHITELIST, "bmp,gif,jpeg,jpg,pdf,png,properties,svg,txt,zip");
    defaults.setProperty(PROP_IMAGE_RESIZE_INCREMENT, "100");
    defaults.setProperty(PROP_MAX_TOPIC_VERSION_EXPORT, "200");
    defaults.setProperty(PROP_PARSER_ALLOW_HTML, Boolean.TRUE.toString());
    defaults.setProperty(PROP_PARSER_ALLOW_JAVASCRIPT, Boolean.FALSE.toString());
    defaults.setProperty(PROP_PARSER_ALLOW_TEMPLATES, Boolean.TRUE.toString());
    defaults.setProperty(PROP_PARSER_CLASS, "org.jamwiki.parser.bliki.BlikiParser");
    // "org.jamwiki.parser.jflex.JFlexParser");
    defaults.setProperty(PROP_PARSER_SIGNATURE_DATE_PATTERN, "dd-MMM-yyyy HH:mm zzz");
    defaults.setProperty(PROP_PARSER_SIGNATURE_USER_PATTERN, "[[{0}|{4}]]");
    defaults.setProperty(PROP_PARSER_TOC, Boolean.TRUE.toString());
    defaults.setProperty(PROP_PARSER_TOC_DEPTH, "5");
    defaults.setProperty(PROP_PATTERN_INVALID_ROLE_NAME, "([A-Za-z0-9_]+)");
    defaults.setProperty(PROP_PATTERN_INVALID_TOPIC_NAME, "([\\n\\r\\\\<>\\[\\]?#]+)");
    defaults.setProperty(PROP_PATTERN_VALID_USER_LOGIN, "([A-Za-z0-9_]+)");
    defaults.setProperty(PROP_PRINT_NEW_WINDOW, Boolean.FALSE.toString());
    defaults.setProperty(PROP_RECENT_CHANGES_NUM, "100");
    defaults.setProperty(PROP_RSS_ALLOWED, Boolean.TRUE.toString());
    defaults.setProperty(PROP_RSS_TITLE, "Wiki Recent Changes");
    defaults.setProperty(PROP_SERVER_URL, "");
    defaults.setProperty(PROP_SITE_NAME, "JAMWiki");
    // FIXME - hard coding
    defaults.setProperty(PROP_TOPIC_EDITOR, "toolbar");
    defaults.setProperty(PROP_TOPIC_SPAM_FILTER, Boolean.TRUE.toString());
    defaults.setProperty(PROP_TOPIC_USE_PREVIEW, Boolean.TRUE.toString());
    defaults.setProperty(PROP_TOPIC_USE_SHOW_CHANGES, Boolean.TRUE.toString());
}

From source file:org.jamwiki.servlets.AdminServlet.java

/**
  */*  w ww  . j ava 2s  . c  o m*/
  */
private void viewAdmin(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, Properties props)
        throws Exception {
    pageInfo.setContentJsp(JSP_ADMIN);
    pageInfo.setAdmin(true);
    pageInfo.setPageTitle(new WikiMessage("admin.title"));
    Map editors = WikiConfiguration.getInstance().getEditors();
    next.addObject("editors", editors);
    List<WikiConfigurationObject> dataHandlers = WikiConfiguration.getInstance().getDataHandlers();
    next.addObject("dataHandlers", dataHandlers);
    List<WikiConfigurationObject> searchEngines = WikiConfiguration.getInstance().getSearchEngines();
    next.addObject("searchEngines", searchEngines);
    List<WikiConfigurationObject> parsers = WikiConfiguration.getInstance().getParsers();
    next.addObject("parsers", parsers);
    LinkedHashMap<Integer, String> poolExhaustedMap = new LinkedHashMap<Integer, String>();
    poolExhaustedMap.put(Integer.valueOf(GenericObjectPool.WHEN_EXHAUSTED_FAIL),
            "admin.persistence.caption.whenexhaustedaction.fail");
    poolExhaustedMap.put(Integer.valueOf(GenericObjectPool.WHEN_EXHAUSTED_BLOCK),
            "admin.persistence.caption.whenexhaustedaction.block");
    poolExhaustedMap.put(Integer.valueOf(GenericObjectPool.WHEN_EXHAUSTED_GROW),
            "admin.persistence.caption.whenexhaustedaction.grow");
    next.addObject("poolExhaustedMap", poolExhaustedMap);
    LinkedHashMap<Integer, String> blacklistTypesMap = new LinkedHashMap<Integer, String>();
    blacklistTypesMap.put(Integer.valueOf(WikiBase.UPLOAD_ALL), "admin.upload.caption.allowall");
    blacklistTypesMap.put(Integer.valueOf(WikiBase.UPLOAD_NONE), "admin.upload.caption.allownone");
    blacklistTypesMap.put(Integer.valueOf(WikiBase.UPLOAD_BLACKLIST), "admin.upload.caption.useblacklist");
    blacklistTypesMap.put(Integer.valueOf(WikiBase.UPLOAD_WHITELIST), "admin.upload.caption.usewhitelist");
    next.addObject("blacklistTypes", blacklistTypesMap);
    if (props == null) {
        props = Environment.getInstance();
    }
    int maximumFileSize = Integer.valueOf(props.getProperty(Environment.PROP_FILE_MAX_FILE_SIZE)) / 1000;
    next.addObject("maximumFileSize", maximumFileSize);
    next.addObject("props", props);
}

From source file:org.mule.transport.ftp.FtpConnector.java

protected GenericObjectPool createPool(FtpConnectionFactory connectionFactory) {
    GenericObjectPool genericPool = new GenericObjectPool(connectionFactory);
    byte poolExhaustedAction = ThreadingProfile.DEFAULT_POOL_EXHAUST_ACTION;

    ThreadingProfile receiverThreadingProfile = this.getReceiverThreadingProfile();
    if (receiverThreadingProfile != null) {
        int threadingProfilePoolExhaustedAction = receiverThreadingProfile.getPoolExhaustedAction();
        if (threadingProfilePoolExhaustedAction == ThreadingProfile.WHEN_EXHAUSTED_WAIT) {
            poolExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
        } else if (threadingProfilePoolExhaustedAction == ThreadingProfile.WHEN_EXHAUSTED_ABORT) {
            poolExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
        } else if (threadingProfilePoolExhaustedAction == ThreadingProfile.WHEN_EXHAUSTED_RUN) {
            poolExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        }/*w  w w  .  ja  v  a2s .  c  o  m*/
    }

    genericPool.setWhenExhaustedAction(poolExhaustedAction);
    genericPool.setTestOnBorrow(isValidateConnections());
    return genericPool;
}

From source file:org.mule.transport.ftps.FtpsConnector.java

protected GenericObjectPool createPool(FtpsConnectionFactory connectionFactory) {
    GenericObjectPool genericPool = new GenericObjectPool(connectionFactory);
    byte poolExhaustedAction = ThreadingProfile.DEFAULT_POOL_EXHAUST_ACTION;

    ThreadingProfile receiverThreadingProfile = this.getReceiverThreadingProfile();
    if (receiverThreadingProfile != null) {
        int threadingProfilePoolExhaustedAction = receiverThreadingProfile.getPoolExhaustedAction();
        if (threadingProfilePoolExhaustedAction == ThreadingProfile.WHEN_EXHAUSTED_WAIT) {
            poolExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
        } else if (threadingProfilePoolExhaustedAction == ThreadingProfile.WHEN_EXHAUSTED_ABORT) {
            poolExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
        } else if (threadingProfilePoolExhaustedAction == ThreadingProfile.WHEN_EXHAUSTED_RUN) {
            poolExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        }//from   w  w w . ja  va  2  s  . co  m
    }

    genericPool.setWhenExhaustedAction(poolExhaustedAction);
    genericPool.setTestOnBorrow(isValidateConnections());
    return genericPool;
}

From source file:org.onexus.collection.store.h2sql.internal.H2CollectionStore.java

protected DataSource newDataSource() {

    Driver.load();/*from   ww  w  .j  av  a2 s.  co m*/

    // Initialize the DataSource with a connection pool
    ConnectionFactory connectionFactory = new H2ConnectionFactory();
    ObjectPool connectionPool = new GenericObjectPool(null, GenericObjectPool.DEFAULT_MAX_ACTIVE,
            GenericObjectPool.WHEN_EXHAUSTED_GROW, GenericObjectPool.DEFAULT_MAX_WAIT);
    @SuppressWarnings("unused")
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, null, null, false, true);
    return new PoolingDataSource(connectionPool);
}

From source file:org.onexus.collection.store.mysql.internal.MysqlCollectionStore.java

protected DataSource newDataSource() {

    try {/*  ww  w  .  j a  va  2  s.co  m*/
        Class.forName(Driver.class.getName());
    } catch (Exception e) {
        LOGGER.error("Exception: " + e.getMessage());
    }

    // Config parameters
    int maxActive = 8;
    try {
        maxActive = Integer.valueOf(getPoolMaxActive().trim()).intValue();
    } catch (Exception e) {
        LOGGER.error("Malformed config parameter 'poolMaxActive'");
    }

    byte whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    try {
        if (getPoolWhenExhausted().trim().equalsIgnoreCase("FAIL")) {
            whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
        }
        if (getPoolWhenExhausted().trim().equalsIgnoreCase("GROW")) {
            whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_GROW;
        }
    } catch (Exception e) {
        LOGGER.error("Malformed config parameter 'poolWhenExhausted'");
    }

    long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
    try {
        maxWait = Long.valueOf(getPoolMaxWait().trim()).longValue();
    } catch (Exception e) {
        LOGGER.error("Malformed config parameter 'poolMaxWait'");
    }

    // Initialize the DataSource with a connection pool
    ConnectionFactory connectionFactory = new MysqlConnectionFactory();
    GenericObjectPool connectionPool = new GenericObjectPool(null, maxActive, whenExhausted, maxWait);
    connectionPool.setTestWhileIdle(true);
    connectionPool.setTimeBetweenEvictionRunsMillis(3600);
    connectionPool.setMinEvictableIdleTimeMillis(3600);

    @SuppressWarnings("unused")
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, null, null, false, true);
    poolableConnectionFactory.setValidationQuery("SELECT 1");
    return new PoolingDataSource(connectionPool);

}