Search in sources :

Example 1 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project cas by apereo.

the class MemcachedMonitorConfiguration method memcachedHealthIndicator.

@Bean
public HealthIndicator memcachedHealthIndicator() {
    final MonitorProperties.Memcached memcached = casProperties.getMonitor().getMemcached();
    final MemcachedPooledClientConnectionFactory factory = new MemcachedPooledClientConnectionFactory(memcached, memcachedMonitorTranscoder());
    final ObjectPool<MemcachedClientIF> pool = new GenericObjectPool<>(factory);
    return new MemcachedHealthIndicator(pool, casProperties);
}
Also used : MemcachedPooledClientConnectionFactory(org.apereo.cas.memcached.MemcachedPooledClientConnectionFactory) MemcachedClientIF(net.spy.memcached.MemcachedClientIF) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) MemcachedHealthIndicator(org.apereo.cas.monitor.MemcachedHealthIndicator) MonitorProperties(org.apereo.cas.configuration.model.core.monitor.MonitorProperties) Bean(org.springframework.context.annotation.Bean)

Example 2 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project fess-crawler by codelibs.

the class WebDriverClientTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    CrawlerPooledObjectFactory<CrawlerWebDriver> pooledObjectFactory = new CrawlerPooledObjectFactory<>();
    pooledObjectFactory.setComponentName("webDriver");
    pooledObjectFactory.setOnDestroyListener(p -> {
        final CrawlerWebDriver driver = p.getObject();
        driver.quit();
    });
    final StandardCrawlerContainer container = new StandardCrawlerContainer();
    container.prototype("webDriver", CrawlerWebDriver.class).singleton("mimeTypeHelper", MimeTypeHelperImpl.class).singleton("pooledObjectFactory", pooledObjectFactory).singleton("webDriverPool", new GenericObjectPool<>(pooledObjectFactory), null, pool -> {
        pool.close();
    }).<AOnClickAction>singleton("aOnClickAction", AOnClickAction.class).<FormAction>singleton("formAction", FormAction.class).<WebDriverClient>singleton("webDriverClient", WebDriverClient.class, client -> {
        AOnClickAction aOnClick = container.getComponent("aOnClickAction");
        aOnClick.setName("aOnClick");
        aOnClick.setCssQuery("a");
        client.addUrlAction(aOnClick);
        FormAction formAction = container.getComponent("formAction");
        formAction.setName("form");
        formAction.setCssQuery("form");
        client.addUrlAction(formAction);
    });
    webDriverClient = container.getComponent("webDriverClient");
}
Also used : StandardCrawlerContainer(org.codelibs.fess.crawler.container.StandardCrawlerContainer) MimeTypeHelperImpl(org.codelibs.fess.crawler.helper.impl.MimeTypeHelperImpl) Iterator(java.util.Iterator) CrawlerPooledObjectFactory(org.codelibs.fess.crawler.pool.CrawlerPooledObjectFactory) ResourceUtil(org.codelibs.core.io.ResourceUtil) PlainTestCase(org.dbflute.utflute.core.PlainTestCase) CrawlerWebDriver(org.codelibs.fess.crawler.client.http.webdriver.CrawlerWebDriver) Resource(javax.annotation.Resource) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Set(java.util.Set) File(java.io.File) AOnClickAction(org.codelibs.fess.crawler.client.http.action.AOnClickAction) SystemUtil(org.codelibs.core.lang.SystemUtil) Constants(org.codelibs.fess.crawler.Constants) RequestData(org.codelibs.fess.crawler.entity.RequestData) FormAction(org.codelibs.fess.crawler.client.http.action.FormAction) WebDriverClient(org.codelibs.fess.crawler.client.http.WebDriverClient) CrawlerWebServer(org.codelibs.fess.crawler.util.CrawlerWebServer) RequestDataBuilder(org.codelibs.fess.crawler.builder.RequestDataBuilder) InputStreamUtil(org.codelibs.core.io.InputStreamUtil) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) AOnClickAction(org.codelibs.fess.crawler.client.http.action.AOnClickAction) WebDriverClient(org.codelibs.fess.crawler.client.http.WebDriverClient) FormAction(org.codelibs.fess.crawler.client.http.action.FormAction) CrawlerWebDriver(org.codelibs.fess.crawler.client.http.webdriver.CrawlerWebDriver) StandardCrawlerContainer(org.codelibs.fess.crawler.container.StandardCrawlerContainer) CrawlerPooledObjectFactory(org.codelibs.fess.crawler.pool.CrawlerPooledObjectFactory) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) MimeTypeHelperImpl(org.codelibs.fess.crawler.helper.impl.MimeTypeHelperImpl)

Example 3 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project atmosphere by Atmosphere.

the class PoolableBroadcasterFactoryTest method testImplementation.

@Test
public void testImplementation() {
    assertNotNull(factory.poolableProvider());
    assertNotNull(factory.poolableProvider().implementation());
    assertEquals(factory.poolableProvider().implementation().getClass(), GenericObjectPool.class);
    GenericObjectPool nativePool = (GenericObjectPool) factory.poolableProvider().implementation();
    assertTrue(nativePool.getLifo());
    GenericObjectPoolConfig c = new GenericObjectPoolConfig();
    c.setMaxTotal(1);
    nativePool.setConfig(c);
    assertEquals(1, nativePool.getMaxTotal());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Test(org.testng.annotations.Test)

Example 4 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project cloudstack by apache.

the class TransactionLegacy method createDataSource.

/**
 * Creates a data source
 */
private static DataSource createDataSource(String uri, String username, String password, Integer maxActive, Integer maxIdle, Long maxWait, Long timeBtwnEvictionRuns, Long minEvictableIdleTime, Boolean testWhileIdle, Boolean testOnBorrow, String validationQuery, Integer isolationLevel) {
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(uri, username, password);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    GenericObjectPoolConfig config = createPoolConfig(maxActive, maxIdle, maxWait, timeBtwnEvictionRuns, minEvictableIdleTime, testWhileIdle, testOnBorrow);
    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, config);
    poolableConnectionFactory.setPool(connectionPool);
    if (validationQuery != null) {
        poolableConnectionFactory.setValidationQuery(validationQuery);
    }
    if (isolationLevel != null) {
        poolableConnectionFactory.setDefaultTransactionIsolation(isolationLevel);
    }
    return new PoolingDataSource<>(connectionPool);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) PoolingDataSource(org.apache.commons.dbcp2.PoolingDataSource) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 5 with GenericObjectPool

use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project cas by apereo.

the class MemcachedMonitorConfiguration method memcachedHealthClientPool.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "memcachedHealthClientPool")
public ObjectPool<MemcachedClientIF> memcachedHealthClientPool(@Qualifier("memcachedMonitorTranscoder") final Transcoder memcachedMonitorTranscoder, final CasConfigurationProperties casProperties) {
    val memcached = casProperties.getMonitor().getMemcached();
    val factory = new MemcachedPooledClientConnectionFactory(memcached, memcachedMonitorTranscoder);
    return new GenericObjectPool<>(factory);
}
Also used : lombok.val(lombok.val) MemcachedPooledClientConnectionFactory(org.apereo.cas.memcached.MemcachedPooledClientConnectionFactory) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

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