Search in sources :

Example 41 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project terra-workspace-manager by DataBiosphere.

the class BaseDatabaseConfiguration method configureDataSource.

private void configureDataSource() {
    Properties props = new Properties();
    props.setProperty("user", getUsername());
    props.setProperty("password", getPassword());
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(getUri(), props);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
    poolableConnectionFactory.setPool(connectionPool);
    dataSource = new PoolingDataSource<>(connectionPool);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) Properties(java.util.Properties) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 42 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project micrometer by micrometer-metrics.

the class CommonsObjectPool2MetricsTest method createGenericObjectPool.

private GenericObjectPool<Object> createGenericObjectPool() {
    genericObjectPoolCount++;
    GenericObjectPoolConfig<Object> config = new GenericObjectPoolConfig<>();
    config.setMaxTotal(10);
    return new GenericObjectPool<>(new BasePooledObjectFactory<Object>() {

        @Override
        public Object create() {
            return new Object();
        }

        @Override
        public PooledObject<Object> wrap(Object testObject) {
            return new DefaultPooledObject<>(testObject);
        }
    }, config);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) PooledObject(org.apache.commons.pool2.PooledObject) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) PooledObject(org.apache.commons.pool2.PooledObject) DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool)

Example 43 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project businessautomation-cop by redhat-cop.

the class JPAAdditionalPersistence method auditDatasource.

@Bean
public DataSource auditDatasource() {
    DataSourceXAConnectionFactory dataSourceXAConnectionFactory = new DataSourceXAConnectionFactory(tm, h2DataSource());
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(dataSourceXAConnectionFactory, null);
    GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
    poolableConnectionFactory.setPool(connectionPool);
    return new ManagedDataSource<>(connectionPool, dataSourceXAConnectionFactory.getTransactionRegistry());
}
Also used : PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) DataSourceXAConnectionFactory(org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) ManagedDataSource(org.apache.commons.dbcp2.managed.ManagedDataSource) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 44 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project jans by JanssenProject.

the class SqlConnectionProvider method open.

private void open() {
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectionUri, connectionProperties);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    ObjectPool<PoolableConnection> objectPool = new GenericObjectPool<>(poolableConnectionFactory, objectPoolConfig);
    this.poolingDataSource = new PoolingDataSource<>(objectPool);
    poolableConnectionFactory.setPool(objectPool);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 45 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project spring-amqp by spring-projects.

the class PooledChannelConnectionFactoryTests method evictShouldCloseAllUnneededChannelsWithoutErrors.

@Test
public void evictShouldCloseAllUnneededChannelsWithoutErrors() throws Exception {
    PooledChannelConnectionFactory pcf = new PooledChannelConnectionFactory(new ConnectionFactory());
    AtomicReference<GenericObjectPool<Channel>> channelsReference = new AtomicReference<>();
    AtomicReference<GenericObjectPool<Channel>> txChannelsReference = new AtomicReference<>();
    AtomicInteger swallowedExceptionsCount = new AtomicInteger();
    pcf.setPoolConfigurer((pool, tx) -> {
        if (tx) {
            channelsReference.set(pool);
        } else {
            txChannelsReference.set(pool);
        }
        pool.setEvictionPolicy((ec, u, idleCount) -> idleCount > ec.getMinIdle());
        pool.setSwallowedExceptionListener(ex -> swallowedExceptionsCount.incrementAndGet());
        pool.setNumTestsPerEvictionRun(5);
        pool.setMinIdle(1);
        pool.setMaxIdle(5);
    });
    createAndCloseFiveChannelTxAndChannelNonTx(pcf);
    final GenericObjectPool<Channel> channels = channelsReference.get();
    channels.evict();
    assertThat(channels.getNumIdle()).isEqualTo(1);
    assertThat(channels.getDestroyedByEvictorCount()).isEqualTo(4);
    final GenericObjectPool<Channel> txChannels = txChannelsReference.get();
    txChannels.evict();
    assertThat(txChannels.getNumIdle()).isEqualTo(1);
    assertThat(txChannels.getDestroyedByEvictorCount()).isEqualTo(4);
    assertThat(swallowedExceptionsCount.get()).isZero();
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Channel(com.rabbitmq.client.Channel) AtomicReference(java.util.concurrent.atomic.AtomicReference) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Test(org.junit.jupiter.api.Test)

Aggregations

GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)79 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)32 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)27 PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)23 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)19 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)16 Test (org.junit.jupiter.api.Test)13 Properties (java.util.Properties)11 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)9 SQLException (java.sql.SQLException)8 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)8 Connection (java.sql.Connection)7 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)5 Bean (org.springframework.context.annotation.Bean)5 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)4 IOException (java.io.IOException)3 PooledObject (org.apache.commons.pool2.PooledObject)3 Test (org.junit.Test)3 TimeInterval (com.adaptris.util.TimeInterval)2 ThresholdedRandomCutForestMapper (com.amazon.randomcutforest.parkservices.state.ThresholdedRandomCutForestMapper)2