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

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

Introduction

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

Prototype

public GenericObjectPool(PoolableObjectFactory factory) 

Source Link

Document

Create a new GenericObjectPool using the specified factory.

Usage

From source file:org.deegree.tile.persistence.geotiff.GeoTIFFTileDataLevel.java

public GeoTIFFTileDataLevel(TileMatrix metadata, File file, int imageIndex, int xoff, int yoff, int numx,
        int numy) {
    this.metadata = metadata;
    this.imageIndex = imageIndex;
    ImageReaderFactory fac = new ImageReaderFactory(file);
    this.readerPool = new GenericObjectPool(fac);
    this.xoff = xoff;
    this.yoff = yoff;
    this.numx = numx;
    this.numy = numy;
}

From source file:org.eclipse.scada.utils.osgi.jdbc.pool.PoolConnectionAccessor.java

public PoolConnectionAccessor(final DataSourceFactory dataSourceFactory, final Properties paramProperties)
        throws SQLException {
    logger.debug("Creating pool connection accessor : {}", paramProperties);

    // first remove all our properties

    this.connectionPool = new GenericObjectPool<Object>(null);
    this.connectionPool.setMaxActive(getInteger(paramProperties, PREFIX + "maxActive", 8));
    this.connectionPool.setMaxIdle(getInteger(paramProperties, PREFIX + "maxIdle", 8));
    this.connectionPool.setMinIdle(getInteger(paramProperties, PREFIX + "minIdle", 1));
    this.connectionPool.setTestOnBorrow(getBoolean(paramProperties, PREFIX + "testOnBorrow", true));
    this.connectionPool.setTestOnReturn(getBoolean(paramProperties, PREFIX + "testOnReturn", true));

    this.connectionPool.setTimeBetweenEvictionRunsMillis(
            getLong(paramProperties, PREFIX + "timeBetweenEvictionRunsMillis", -1));
    this.connectionPool.setMinEvictableIdleTimeMillis(
            getLong(paramProperties, PREFIX + "minEvictableIdleTimeMillis", 30 * 60 * 1000));
    this.connectionPool.setTestWhileIdle(getBoolean(paramProperties, PREFIX + "testWhileIdle", false));
    this.connectionPool.setSoftMinEvictableIdleTimeMillis(
            getLong(paramProperties, PREFIX + "softMinEvictableIdleTimeMillis", -1));
    this.connectionPool
            .setNumTestsPerEvictionRun(getInteger(paramProperties, PREFIX + "numTestsPerEvictionRun", 3));

    final String connectionInitSql = getString(paramProperties, PREFIX + "connectionInitSql", null);
    final String validationQuery = getString(paramProperties, PREFIX + "validationQuery", null);
    final Integer validationQueryTimeout = getInteger(paramProperties, PREFIX + "validationQueryTimeout", -1);

    this.driverDataSource = dataSourceFactory.createDataSource(paramProperties);

    final ConnectionFactory connectionFactory = new DataSourceConnectionFactory(this.driverDataSource);
    this.poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, this.connectionPool, null,
            null, false, true);/*from  w  w w . ja va 2  s  .c  om*/

    if (connectionInitSql != null) {
        this.poolableConnectionFactory.setConnectionInitSql(Arrays.asList(connectionInitSql));
    }
    if (validationQuery != null) {
        this.poolableConnectionFactory.setValidationQuery(validationQuery);
    }
    if (validationQueryTimeout != null) {
        this.poolableConnectionFactory.setValidationQueryTimeout(validationQueryTimeout);
    }

    this.dataSource = new PoolingDataSource(this.connectionPool);
}

From source file:org.graylog2.syslog4j.impl.pool.generic.GenericSyslogPoolFactory.java

public ObjectPool createPool() throws SyslogRuntimeException {
    GenericObjectPool genericPool = new GenericObjectPool(this);

    configureGenericObjectPool(genericPool);

    return genericPool;
}

From source file:org.helios.collector.jmx.connection.MBeanServerConnectionPool.java

/**
 * Creates a new MBeanServerConnectionPool for the passed connection factory
 * @param connectionFactory the MBeanServerConnection provider to populate the pool
 *///www. j a v  a 2  s  .  co m
public MBeanServerConnectionPool(IMBeanServerConnectionFactory connectionFactory) {
    this.connectionFactory = connectionFactory;
    objectPool = new GenericObjectPool(this.connectionFactory);
}

From source file:org.imirsel.plugins.JndiInitializeServlet.java

private DataSource setupDataSource(String jdbc_url, String user, String password) {
    System.out.println("Setting up jdbc datasource: " + jdbc_url + " user: " + user);
    GenericObjectPool connectionPool = new GenericObjectPool(null);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(jdbc_url, user, password);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, null, null, false, false);
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
    if (dataSource == null) {
        logger.info("DataSource is null");
    }//from  ww  w .j  av a  2 s.  c  o  m
    return dataSource;
}

From source file:org.integratedmodelling.sql.SQLServer.java

private DataSource setupDataSource(String connectURI) throws ThinklabStorageException {

    PoolingDataSource dataSource = null;
    ClassLoader clsl = null;/*  www  .j  a  v  a  2  s.  co  m*/

    try {
        clsl = SQLPlugin.get().swapClassloader();

        ObjectPool connectionPool = new GenericObjectPool(null);
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, getUser(),
                getPassword());
        @SuppressWarnings("unused")
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                connectionPool, null, null, readOnly, autoCommit);
        dataSource = new PoolingDataSource(connectionPool);
    } finally {
        SQLPlugin.get().resetClassLoader(clsl);
    }

    return dataSource;
}

From source file:org.jaffa.persistence.engines.jdbcengine.datasource.DbcpDataSourceConnectionFactory.java

private void createDbcpDataSource() throws SQLException {
    try {/* w w w  . j a  v  a  2s  . c  o  m*/
        synchronized (dataSourceLock) {
            if (c_dataSource == null) {
                // First we load the underlying JDBC driver.
                Class.forName(getDriverClass());

                // Next, we'll need a ObjectPool that serves as the actual pool of connections.
                // We'll use a GenericObjectPool instance
                GenericObjectPool connectionPool = new GenericObjectPool(null);
                if (getMaximumConnections() != null)
                    connectionPool.setMaxActive(getMaximumConnections());
                if (getMinimumConnections() != null)
                    connectionPool.setMaxIdle(getMinimumConnections());
                if (getMaxWait() != null)
                    connectionPool.setMaxWait(getMaxWait());
                if (getTestOnBorrow() != null)
                    connectionPool.setTestOnBorrow(getTestOnBorrow());
                if (getTestOnReturn() != null)
                    connectionPool.setTestOnReturn(getTestOnReturn());

                // Next, we'll create a ConnectionFactory that the pool will use to create Connections.
                // We'll use the DriverManagerConnectionFactory
                ConnectionFactory connectionFactory = null;
                if (m_driverProperties == null || m_driverProperties.isEmpty())
                    connectionFactory = new DriverManagerConnectionFactory(getUrl(), getUser(), getPassword());
                else
                    connectionFactory = new DriverManagerConnectionFactory(getUrl(), getDriverProperties());
                // Now we'll create the PoolableConnectionFactory, which wraps the "real" Connections created by the ConnectionFactory with the classes that implement the pooling functionality.
                KeyedObjectPoolFactory stmtPoolFactory = new StackKeyedObjectPoolFactory();
                String validationQuery = getValidationQuery();
                boolean defaultReadOnly = false;
                boolean defaultAutoCommit = false;
                PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
                        connectionFactory, connectionPool, stmtPoolFactory, validationQuery, defaultReadOnly,
                        defaultAutoCommit);

                // Finally, we create the PoolingDriver itself, passing in the object pool we created.
                c_dataSource = new PoolingDataSource(connectionPool);

                // This will allow us to access the underlying Connection objects, required by the JdbcSecurityPlugin
                ((PoolingDataSource) c_dataSource).setAccessToUnderlyingConnectionAllowed(true);

                if (log.isDebugEnabled())
                    log.debug("Created the Dbcp DataSource");
            }
        }
    } catch (Exception e) {
        String str = "Error in creating the Dbcp DataSource";
        log.error(str, e);
        throw new SQLException(str);
    }
}

From source file:org.jboss.processFlow.knowledgeService.AsyncBAMProducerPool.java

@PostConstruct
public void start() {
    // 1)  grab JMS objects
    try {//from w  w w .  ja  va2s .  co  m
        cFactory = MessagingUtil.grabConnectionFactory();
        connectObj = cFactory.createConnection();
        dQueue = (Destination) MessagingUtil.grabDestination(IBAMService.BAM_QUEUE);
    } catch (Exception x) {
        throw new RuntimeException(x);
    }

    // 2)  create a FIFO pool to manage 'PoolWrapper' objects
    producerPool = new GenericObjectPool(this);

    // 3)  set settings on pool
    int poolMaxIdle = 10;
    if (System.getProperty("org.jboss.processFlow.bam.AsyncBAMProducerPool.poolMaxIdle") != null)
        poolMaxIdle = Integer
                .parseInt(System.getProperty("org.jboss.processFlow.bam.AsyncBAMProducerPool.poolMaxIdle"));
    producerPool.setMaxIdle(poolMaxIdle);
    producerPool.setMaxActive(-1);
    producerPool.setLifo(false);
    log.info("start() just created AsyncBAMProducerPool with poolMaxIdle = " + poolMaxIdle);
}

From source file:org.jivesoftware.database.DbConnectionManager.java

public void setupDataSource(String dbString, String username, String password) {
    try {//from   w  w w  .  j  ava2  s .com
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    StringBuilder connectURI = new StringBuilder();
    connectURI.append(dbString);
    if (dbString.contains("?")) {
        connectURI.append("&");
    } else {
        connectURI.append("?");
    }
    connectURI.append("user=");
    connectURI.append(username);
    connectURI.append("&password=");
    connectURI.append(password);

    connectionPool = new GenericObjectPool(null);

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI.toString(), null);

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

    dataSource = new PoolingDataSource(connectionPool);
}

From source file:org.jvoicexml.implementation.pool.KeyedResourcePool.java

/**
 * Adds the given resource factory.//from   www  .  j a va  2  s  .  c o  m
 * @param resourceFactory The {@link ResourceFactory} to add.
 * @exception Exception error populating the pool
 */
public void addResourceFactory(final ResourceFactory<T> resourceFactory) throws Exception {
    final PoolableObjectFactory factory = new PoolableResourceFactory<T>(resourceFactory);
    final GenericObjectPool pool = new GenericObjectPool(factory);
    final int instances = resourceFactory.getInstances();
    pool.setMinIdle(instances);
    pool.setMaxActive(instances);
    pool.setMaxIdle(instances);
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);
    final String type = resourceFactory.getType();
    pools.put(type, pool);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("loading resources of type '" + type + "'...");
    }
    for (int i = 0; i < instances; i++) {
        pool.addObject();
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("...resources loaded.");
    }
}