Examples of GenericObjectPool


Examples of org.apache.commons.pool.impl.GenericObjectPool

            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            throw new Exception("Cannot load driver: " + driver);
        }

        GenericObjectPool connectionPool = new GenericObjectPool(null);
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                jdbcUrl, user, pass);
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
                connectionFactory, connectionPool, null, null, false, true);
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

     *
     * @throws SQLException if an error occurs closing idle connections
     */
    public synchronized void close() throws SQLException {
        closed = true;
        GenericObjectPool oldpool = connectionPool;
        connectionPool = null;
        dataSource = null;
        try {
            if (oldpool != null) {
                oldpool.close();
            }
        } catch(SQLException e) {
            throw e;
        } catch(RuntimeException e) {
            throw e;
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

     * Creates a connection pool for this datasource.  This method only exists
     * so subclasses can replace the implementation class.
     */
    protected void createConnectionPool() {
        // Create an object pool to contain our active connections
        GenericObjectPool gop;
        if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) {
            gop = new AbandonedObjectPool(null,abandonedConfig);
        }
        else {
            gop = new GenericObjectPool();
        }
        gop.setMaxActive(maxActive);
        gop.setMaxIdle(maxIdle);
        gop.setMinIdle(minIdle);
        gop.setMaxWait(maxWait);
        gop.setTestOnBorrow(testOnBorrow);
        gop.setTestOnReturn(testOnReturn);
        gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
        gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
        gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
        gop.setTestWhileIdle(testWhileIdle);
        connectionPool = gop;
    }
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

                getLogger().log("Setting isolation level '" + levelString + "'", LOG_CHANNEL, Logger.INFO);

                // use DBCP pooling if enabled
                if (useDbcpPooling) {
                    getLogger().log("Using DBCP pooling", LOG_CHANNEL, Logger.INFO);
                    GenericObjectPool connectionPool = new GenericObjectPool(null);
                    if (maxPooledConnections != -1) {
                        connectionPool.setMaxActive(maxPooledConnections);
                    }
                    getLogger().log(
                        "Number of connections set to " + connectionPool.getMaxActive(),
                        LOG_CHANNEL,
                        Logger.INFO);

                    DriverManagerConnectionFactory connectionFactory =
                        new DriverManagerConnectionFactory(url, user, password);
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

      Class.forName(driver);

      //create a new data source based on the database connection info provided.
      ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
          url, username, password)
      GenericObjectPool connectionPool = new GenericObjectPool();
      KeyedObjectPoolFactory stmtPool = new GenericKeyedObjectPoolFactory(null);
      new PoolableConnectionFactory(
          connectionFactory, connectionPool, stmtPool, null, false, true);
      DataSource dataSource = new PoolingDataSource(connectionPool);
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

                }
            } catch (PrivilegedActionException pae) {
                throw (UnknownHostException) pae.getException();
            }
            // -1 max wait == as long as it takes
            _socketPool = new GenericObjectPool
                (new SocketPoolableObjectFactory(), _maxActive,
                    GenericObjectPool.WHEN_EXHAUSTED_BLOCK, -1);
            _isAvailable = true;
        }
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

            // wrap it with a LocalXAConnectionFactory
            XAConnectionFactory xacf = new LocalXAConnectionFactory(txMgr, cf);

            // configure the pool settings
            GenericObjectPool pool = new GenericObjectPool();
            pool.setTimeBetweenEvictionRunsMillis(600000);
            pool.setMaxActive(maxSize);
            pool.setMaxIdle(maxIdle);
            pool.setMinIdle(minSize);
            pool.setMaxWait(120000);


            // create the pool object factory
            PoolableConnectionFactory factory = new PoolableConnectionFactory(xacf, pool, null, null, true, true);
            factory.setValidationQuery("select example_type_id from example_type limit 1");
            factory.setDefaultReadOnly(false);

            String transIso = jotmJdbcElement.getAttribute("isolation-level");
            if (transIso != null && transIso.length() > 0) {
                if ("Serializable".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
                } else if ("RepeatableRead".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
                } else if ("ReadUncommitted".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
                } else if ("ReadCommitted".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                } else if ("None".equals(transIso)) {
                    factory.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
                }
            }
            pool.setFactory(factory);

            mds = new ManagedDataSource(pool, xacf.getTransactionRegistry());
            mds.setAccessToUnderlyingConnectionAllowed(true);

            // cache the pool
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

    private InetAddress localAddress;
    private int localPort;

    public void afterPropertiesSet() throws Exception {
        if (pool == null) {
            pool = new GenericObjectPool();
        }
        pool.setFactory(this);
    }
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

            if(regionId == null){
              s_region_id = 1;
            } else {
              s_region_id = Integer.parseInt(regionId);
            }
            final GenericObjectPool cloudConnectionPool = new GenericObjectPool(null, cloudMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                    cloudMaxWait, cloudMaxIdle, cloudTestOnBorrow, false, cloudTimeBtwEvictionRunsMillis, 1, cloudMinEvcitableIdleTimeMillis, cloudTestWhileIdle);

            final ConnectionFactory cloudConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + cloudHost + ":" + cloudPort + "/" + cloudDbName +
                    "?autoReconnect=" + cloudAutoReconnect + (url != null ? "&" + url : "") + (useSSL ? "&useSSL=true" : ""), cloudUsername, cloudPassword);

            final KeyedObjectPoolFactory poolableObjFactory = (cloudPoolPreparedStatements ? new StackKeyedObjectPoolFactory() : null);

            final PoolableConnectionFactory cloudPoolableConnectionFactory = new PoolableConnectionFactory(cloudConnectionFactory, cloudConnectionPool, poolableObjFactory,
                    cloudValidationQuery, false, false, isolationLevel);

            // Default Data Source for CloudStack
            s_ds = new PoolingDataSource(cloudPoolableConnectionFactory.getPool());

            // Configure the usage db
            final int usageMaxActive = Integer.parseInt(dbProps.getProperty("db.usage.maxActive"));
            final int usageMaxIdle = Integer.parseInt(dbProps.getProperty("db.usage.maxIdle"));
            final long usageMaxWait = Long.parseLong(dbProps.getProperty("db.usage.maxWait"));
            final String usageUsername = dbProps.getProperty("db.usage.username");
            final String usagePassword = dbProps.getProperty("db.usage.password");
            final String usageHost = dbProps.getProperty("db.usage.host");
            final int usagePort = Integer.parseInt(dbProps.getProperty("db.usage.port"));
            final String usageDbName = dbProps.getProperty("db.usage.name");
            final boolean usageAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.usage.autoReconnect"));
            final String usageUrl = dbProps.getProperty("db.usage.url.params");

            final GenericObjectPool usageConnectionPool = new GenericObjectPool(null, usageMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                    usageMaxWait, usageMaxIdle);

            final ConnectionFactory usageConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + usageHost + ":" + usagePort + "/" + usageDbName +
                    "?autoReconnect=" + usageAutoReconnect + (usageUrl != null ? "&" + usageUrl : ""), usageUsername, usagePassword);

            final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory(usageConnectionFactory, usageConnectionPool,
                    new StackKeyedObjectPoolFactory(), null, false, false);

            // Data Source for usage server
            s_usageDS = new PoolingDataSource(usagePoolableConnectionFactory.getPool());

            // Configure awsapi db
            final String awsapiDbName = dbProps.getProperty("db.awsapi.name");
            final GenericObjectPool awsapiConnectionPool = new GenericObjectPool(null, usageMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                    usageMaxWait, usageMaxIdle);
            final ConnectionFactory awsapiConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + cloudHost + ":" + cloudPort + "/" + awsapiDbName +
                    "?autoReconnect=" + usageAutoReconnect, cloudUsername, cloudPassword);
            final PoolableConnectionFactory awsapiPoolableConnectionFactory = new PoolableConnectionFactory(awsapiConnectionFactory, awsapiConnectionPool,
                    new StackKeyedObjectPoolFactory(), null, false, false);

            // Data Source for awsapi
            s_awsapiDS = new PoolingDataSource(awsapiPoolableConnectionFactory.getPool());

            try {
                // Configure the simulator db
                final int simulatorMaxActive = Integer.parseInt(dbProps.getProperty("db.simulator.maxActive"));
                final int simulatorMaxIdle = Integer.parseInt(dbProps.getProperty("db.simulator.maxIdle"));
                final long simulatorMaxWait = Long.parseLong(dbProps.getProperty("db.simulator.maxWait"));
                final String simulatorUsername = dbProps.getProperty("db.simulator.username");
                final String simulatorPassword = dbProps.getProperty("db.simulator.password");
                final String simulatorHost = dbProps.getProperty("db.simulator.host");
                final int simulatorPort = Integer.parseInt(dbProps.getProperty("db.simulator.port"));
                final String simulatorDbName = dbProps.getProperty("db.simulator.name");
                final boolean simulatorAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.simulator.autoReconnect"));

                final GenericObjectPool simulatorConnectionPool = new GenericObjectPool(null, simulatorMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                        simulatorMaxWait, simulatorMaxIdle);

                final ConnectionFactory simulatorConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://" + simulatorHost + ":" + simulatorPort + "/" + simulatorDbName +
                        "?autoReconnect=" + simulatorAutoReconnect, simulatorUsername, simulatorPassword);
View Full Code Here

Examples of org.apache.commons.pool.impl.GenericObjectPool

            s_logger.warn("Unable to load db configuration, using defaults with 5 connections. Falling back on assumed datasource on localhost:3306 using username:password=cloud:cloud. Please check your configuration", e);
        }
    }

    private static DataSource getDefaultDataSource(final String database) {
        final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
        final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
           "jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
        final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
           connectionFactory, connectionPool, null, null, false, true);
        return new PoolingDataSource(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.