Example usage for org.apache.commons.pool2.impl GenericKeyedObjectPoolConfig GenericKeyedObjectPoolConfig

List of usage examples for org.apache.commons.pool2.impl GenericKeyedObjectPoolConfig GenericKeyedObjectPoolConfig

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl GenericKeyedObjectPoolConfig GenericKeyedObjectPoolConfig.

Prototype

public GenericKeyedObjectPoolConfig() 

Source Link

Document

Create a new configuration with default settings.

Usage

From source file:org.jmxtrans.embedded.util.pool.ManagedGenericKeyedObjectPoolTest.java

@Test
public void testMbeanAttributeAccess() throws Exception {
    BaseKeyedPooledObjectFactory<String, String> factory = new BaseKeyedPooledObjectFactory<String, String>() {
        @Override/*  ww w .  j a v a2s .  c o  m*/
        public String create(String key) throws Exception {
            return key;
        }

        @Override
        public PooledObject<String> wrap(String value) {
            return new DefaultPooledObject<String>(value);
        }
    };
    GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
    config.setJmxNameBase("org.jmxtrans.embedded:type=GenericKeyedObjectPool,writer=MyWriter,name=");
    config.setJmxNamePrefix("my-host_1234");
    GenericKeyedObjectPool<String, String> objectPool = new GenericKeyedObjectPool<String, String>(factory,
            config);

    ObjectName objectName = new ObjectName(
            "org.jmxtrans.embedded:type=GenericKeyedObjectPool,writer=MyWriter,name=my-host_1234");
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        Object numIdle = mbeanServer.getAttribute(objectName, "NumIdle");
        assertThat(numIdle, instanceOf(Number.class));

    } finally {
        mbeanServer.unregisterMBean(objectName);
    }
}

From source file:org.springframework.ldap.pool2.factory.PooledContextSource.java

private GenericKeyedObjectPoolConfig getConfig(PoolConfig poolConfig) {
    GenericKeyedObjectPoolConfig objectPoolConfig = new GenericKeyedObjectPoolConfig();

    objectPoolConfig.setMaxTotalPerKey(poolConfig.getMaxTotalPerKey());
    objectPoolConfig.setMaxTotal(poolConfig.getMaxTotal());

    objectPoolConfig.setMaxIdlePerKey(poolConfig.getMaxIdlePerKey());
    objectPoolConfig.setMinIdlePerKey(poolConfig.getMinIdlePerKey());

    objectPoolConfig.setTestWhileIdle(poolConfig.isTestWhileIdle());
    objectPoolConfig.setTestOnReturn(poolConfig.isTestOnReturn());
    objectPoolConfig.setTestOnCreate(poolConfig.isTestOnCreate());
    objectPoolConfig.setTestOnBorrow(poolConfig.isTestOnBorrow());

    objectPoolConfig.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
    objectPoolConfig.setEvictionPolicyClassName(poolConfig.getEvictionPolicyClassName());
    objectPoolConfig.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
    objectPoolConfig.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
    objectPoolConfig.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());

    objectPoolConfig.setJmxEnabled(poolConfig.isJmxEnabled());
    objectPoolConfig.setJmxNameBase(poolConfig.getJmxNameBase());
    objectPoolConfig.setJmxNamePrefix(poolConfig.getJmxNamePrefix());

    objectPoolConfig.setMaxWaitMillis(poolConfig.getMaxWaitMillis());

    objectPoolConfig.setFairness(poolConfig.isFairness());
    objectPoolConfig.setBlockWhenExhausted(poolConfig.isBlockWhenExhausted());
    objectPoolConfig.setLifo(poolConfig.isLifo());

    return objectPoolConfig;
}