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.apache.camel.component.sjms.SjmsProducer.java

@Override
protected void doStart() throws Exception {
    super.doStart();
    this.executor = getEndpoint().getCamelContext().getExecutorServiceManager().newDefaultThreadPool(this,
            "SjmsProducer");
    if (getProducers() == null) {
        setProducers(new GenericObjectPool<MessageProducerResources>(new MessageProducerResourcesFactory()));
        getProducers().setMaxActive(getProducerCount());
        getProducers().setMaxIdle(getProducerCount());
        getProducers().setLifo(false);/*from   ww  w  .  java2 s  .  c  om*/
        if (getEndpoint().isPrefillPool()) {
            if (getEndpoint().isAsyncStartListener()) {
                asyncStart = getEndpoint().getComponent().getAsyncStartStopExecutorService()
                        .submit(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    fillProducersPool();
                                } catch (Throwable e) {
                                    log.warn("Error filling producer pool for destination: "
                                            + getDestinationName() + ". This exception will be ignored.", e);
                                }
                            }

                            @Override
                            public String toString() {
                                return "AsyncStartListenerTask[" + getDestinationName() + "]";
                            }
                        });
            } else {
                fillProducersPool();
            }
        }
    }
}

From source file:org.apache.oodt.cas.workflow.instrepo.DataSourceWorkflowInstanceRepositoryFactory.java

/**
 * <p>/*  w w w  . ja  v a 2s .c  o  m*/
 * Default constructor
 * </p>
 */
public DataSourceWorkflowInstanceRepositoryFactory() throws WorkflowException {
    String jdbcUrl, user, pass, driver;

    jdbcUrl = PathUtils.replaceEnvVariables(
            System.getProperty("org.apache.oodt.cas.workflow.instanceRep.datasource.jdbc.url"));
    user = PathUtils.replaceEnvVariables(
            System.getProperty("org.apache.oodt.cas.workflow.instanceRep.datasource.jdbc.user"));
    pass = PathUtils.replaceEnvVariables(
            System.getProperty("org.apache.oodt.cas.workflow.instanceRep.datasource.jdbc.pass"));
    driver = PathUtils.replaceEnvVariables(
            System.getProperty("org.apache.oodt.cas.workflow.instanceRep.datasource.jdbc.driver"));

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

    GenericObjectPool connectionPool = new GenericObjectPool(null);

    dataSource = new PoolingDataSource(connectionPool);
    quoteFields = Boolean.getBoolean("org.apache.oodt.cas.workflow.instanceRep.datasource.quoteFields");
    pageSize = Integer.getInteger("org.apache.oodt.cas.workflow.instanceRep.pageSize", VAL);

}

From source file:org.apache.oodt.cas.workflow.repository.DataSourceWorkflowRepositoryFactory.java

/**
 * <p>/*from   w w w. ja v a 2  s . c  o m*/
 * Default Constructor
 * </p>.
 */
public DataSourceWorkflowRepositoryFactory() throws WorkflowException {
    String jdbcUrl, user, pass, driver;

    jdbcUrl = System.getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.url");
    user = System.getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.user");
    pass = System.getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.pass");
    driver = System.getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.driver");

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        throw new WorkflowException("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);

    dataSource = new PoolingDataSource(connectionPool);
}

From source file:org.apache.oodt.commons.database.DatabaseConnectionBuilder.java

public static DataSource buildDataSource(String user, String pass, String driver, String url) {

    DataSource ds;/*from w  ww.j  a  va2s .com*/

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException ignore) {
    }

    GenericObjectPool connectionPool = new GenericObjectPool(null);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, pass);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, null, null, false, true);

    return new PoolingDataSource(connectionPool);
}

From source file:org.apache.slide.store.impl.rdbms.JDBCStore.java

/**
 * Initializes driver.//from  www  .ja  va2  s . c o  m
 * <p/>
 * Occurs in four steps :
 * <li>Driver class is loaded</li>
 * <li>Driver is instantiated</li>
 * <li>Driver registration in the driver manager</li>
 * <li>Creation of the basic tables, if they didn't exist before</li>
 * 
 * @exception ServiceInitializationFailedException Throws an exception 
 * if the data source has already been initialized before
 */
public synchronized void initialize(NamespaceAccessToken token) throws ServiceInitializationFailedException {

    // XXX might be done already in setParameter
    if (!alreadyInitialized) {
        try {
            // Loading and registering driver
            getLogger().log("Loading and registering driver '" + driver + "'", LOG_CHANNEL, Logger.INFO);
            Class driverClass = Class.forName(driver);
            Driver driverInstance = (Driver) driverClass.newInstance();

            String levelString = isolationLevelToString(isolationLevel);

            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);
                new PoolableConnectionFactory(connectionFactory, connectionPool,
                        // TODO switching on pooling of prepared statements causes problems with closing of connections
                        // switched off for now
                        //                  new StackKeyedObjectPoolFactory(),
                        null, null, false, false, isolationLevel);
                PoolingDriver driver = new PoolingDriver();
                driver.registerPool(dbcpPoolName, connectionPool);
                // already done when loding PoolingDriver class 
                //                DriverManager.registerDriver(driver);
            } else {
                DriverManager.registerDriver(driverInstance);
                getLogger().log("Not using DBCP pooling", LOG_CHANNEL, Logger.WARNING);
            }
        } catch (Exception e) {
            getLogger().log("Loading and registering driver '" + driver + "' failed (" + e.getMessage() + ")",
                    LOG_CHANNEL, Logger.ERROR);
            throw new ServiceInitializationFailedException(this, e);
        } finally {
            alreadyInitialized = true;
        }
    }

}

From source file:org.broadleafcommerce.openadmin.server.service.persistence.datasource.SandBoxDataSource.java

public SandBoxDataSource() {
    synchronized (this) {
        if (server == null) {
            try {
                Class.forName(DRIVERNAME);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }/*from  w  ww  . j  a  v a2s .  c om*/
            try {
                HsqlProperties p = new HsqlProperties();
                p.setProperty("server.remote_open", true);
                server = new Server();
                server.setAddress(address);
                server.setPort(port);
                server.setProperties(p);
                server.setLogWriter(logWriter == null ? new PrintWriter(System.out) : logWriter);
                server.setErrWriter(logWriter == null ? new PrintWriter(System.out) : logWriter);
                server.start();
            } catch (IOException e) {
                throw new RuntimeException(e);
            } catch (AclFormatException e) {
                throw new RuntimeException(e);
            }
        }
    }
    uuid = UUID.randomUUID().toString();
    sandboxDataBasePool = new GenericObjectPool(new PoolableSandBoxDataBaseFactory());
}

From source file:org.broadleafcommerce.openadmin.server.service.persistence.entitymanager.pool.DefaultEntityManagerPool.java

public DefaultEntityManagerPool() {
    sandboxPool = new GenericObjectPool(new PoolableSandBoxFactory());
}

From source file:org.codehaus.griffon.runtime.datasource.DefaultDataSourceFactory.java

@Nonnull
@SuppressWarnings("ConstantConditions")
private DataSource createDataSource(@Nonnull Map<String, Object> config, @Nonnull String name) {
    String driverClassName = getConfigValueAsString(config, "driverClassName", "");
    requireNonBlank(driverClassName, "Configuration for " + name + ".driverClassName must not be blank");
    String url = getConfigValueAsString(config, "url", "");
    requireNonBlank(url, "Configuration for " + name + ".url must not be blank");

    try {/*from   ww w . ja v  a  2 s. c o m*/
        getApplication().getApplicationClassLoader().get().loadClass(driverClassName);
    } catch (ClassNotFoundException e) {
        throw new GriffonException(e);
    }

    GenericObjectPool<DataSource> connectionPool = new GenericObjectPool<>(null);
    Map<String, Object> pool = getConfigValue(config, "pool", Collections.<String, Object>emptyMap());
    GriffonClassUtils.setPropertiesNoException(connectionPool, pool);

    String username = getConfigValueAsString(config, "username", "");
    String password = getConfigValueAsString(config, "password", "");
    ConnectionFactory connectionFactory = null;
    if (isBlank(username)) {
        connectionFactory = new DriverManagerConnectionFactory(url, null);
    } else {
        connectionFactory = new DriverManagerConnectionFactory(url, username, password);
    }

    new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
    return new PoolingDataSource(connectionPool);
}

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  .  ja  va  2  s . co m*/
 * @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;
}

From source file:org.deegree.commons.jdbc.ConnectionPool.java

/**
 * Creates a new {@link ConnectionPool} instance.
 * //from w ww  . j av  a2  s .  co m
 * @param id
 * @param connectURI
 * @param user
 * @param password
 * @param readOnly
 * @param minIdle
 * @param maxActive
 */
public ConnectionPool(String id, String connectURI, String user, String password, boolean readOnly, int minIdle,
        int maxActive) {

    this.id = id;
    pool = new GenericObjectPool<Connection>(null);
    pool.setMinIdle(minIdle);
    pool.setMaxActive(maxActive);

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, user, password);
    // TODO make this configurable
    new PoolableConnectionFactory(connectionFactory, pool, null, null, readOnly, true);
    ds = new PoolingDataSource(pool);
    // needed, so users can retrieve the underlying connection from pooled
    // connections, e.g. to access the
    // LargeObjectManager from a PGConnection
    ds.setAccessToUnderlyingConnectionAllowed(true);
}