org.apache.commons.pool.impl.GenericKeyedObjectPool Java Examples

The following examples show how to use org.apache.commons.pool.impl.GenericKeyedObjectPool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyParsePool2WithPlaceholders() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-config-with-placeholders.xml");
    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
            (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10);
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20);
    assertThat(objectPool.getMaxWaitMillis()).isEqualTo(10);
    assertThat(objectPool.getMaxTotal()).isEqualTo(11);
    assertThat(objectPool.getMinIdlePerKey()).isEqualTo(12);
    assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(13);
    assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(14);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18);
}
 
Example #2
Source File: DataEndpointConfiguration.java    From product-microgateway with Apache License 2.0 6 votes vote down vote up
public DataEndpointConfiguration(String receiverURL, String authURL, String username, String password,
                                 GenericKeyedObjectPool transportPool,
                                 GenericKeyedObjectPool securedTransportPool,
                                 int batchSize, int corePoolSize, int maxPoolSize, int keepAliveTimeInPool) {
    this.receiverURL = receiverURL;
    this.authURL = authURL;
    this.username = username;
    this.password = password.toCharArray();
    this.transportPool = transportPool;
    this.securedTransportPool = securedTransportPool;
    this.publisherKey = this.receiverURL + DataEndpointConstants.SEPARATOR + username;
    this.authKey = this.authURL + DataEndpointConstants.SEPARATOR + username;
    this.batchSize = batchSize;
    this.corePoolSize = corePoolSize;
    this.maxPoolSize = maxPoolSize;
    this.keepAliveTimeInPool = keepAliveTimeInPool;
}
 
Example #3
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyParsePoolWithPlaceholders() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-config-with-placeholders.xml");
    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10);
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20);
    assertThat(objectPool.getMaxWait()).isEqualTo(10);
    assertThat(objectPool.getMaxTotal()).isEqualTo(11);
    assertThat(objectPool.getMaxActive()).isEqualTo(15);
    assertThat(objectPool.getMinIdle()).isEqualTo(16);
    assertThat(objectPool.getMaxIdle()).isEqualTo(17);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18);
}
 
Example #4
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyParsePoolingSizeSet() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-configured-poolsize.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMaxActive()).isEqualTo(10);
    assertThat(objectPool.getMaxTotal()).isEqualTo(12);
    assertThat(objectPool.getMaxIdle()).isEqualTo(11);
    assertThat(objectPool.getMaxWait()).isEqualTo(13);
    assertThat(objectPool.getMinIdle()).isEqualTo(14);
    assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)0);
}
 
Example #5
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyParsePool2ValidationSet() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-test-specified.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
            (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123);
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22);
    assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(12);

    assertThat(objectPool.getTestOnBorrow()).isEqualTo(true);
    assertThat(objectPool.getTestOnReturn()).isEqualTo(true);
    assertThat(objectPool.getTestOnCreate()).isEqualTo(true);
    assertThat(objectPool.getTestWhileIdle()).isEqualTo(true);

    Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
    org.springframework.ldap.pool2.validation.DefaultDirContextValidator validator =
            (org.springframework.ldap.pool2.validation.DefaultDirContextValidator) getInternalState(objectFactory, "dirContextValidator");
    assertThat(validator.getBase()).isEqualTo("ou=test");
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");

    SearchControls searchControls = ctx.getBean(SearchControls.class);
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");
    assertThat(validator.getSearchControls()).isSameAs(searchControls);

    Set<Class<? extends Throwable>> nonTransientExceptions =
            (Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
    assertThat(nonTransientExceptions).hasSize(2);
    assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
    assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
}
 
Example #6
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyParsePool2SizeSet() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-configured-poolsize.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
            (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMaxTotal()).isEqualTo(12);
    assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(20);
    assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(10);
    assertThat(objectPool.getMaxWaitMillis()).isEqualTo(13);
    assertThat(objectPool.getMinIdlePerKey()).isEqualTo(14);
    assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true);
    assertThat(objectPool.getEvictionPolicyClassName()).isEqualTo("org.springframework.ldap.pool2.DummyEvictionPolicy");
    assertThat(objectPool.getFairness()).isEqualTo(true);
    assertThat(objectPool.getLifo()).isEqualTo(false);

    // ensures the pool is registered
    ObjectName oname = objectPool.getJmxName();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> result = mbs.queryNames(oname, null);
    assertThat(result).hasSize(1);
    assertThat(oname.toString()).isEqualTo("org.springframework.ldap.pool2:type=ldap-pool,name=test-pool");
}
 
Example #7
Source File: RiceXADataSource.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected KeyedObjectPoolFactory createStatementPoolFactory() {
	return new GenericKeyedObjectPoolFactory(null, 
               -1, // unlimited maxActive (per key)
               GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 
               0, // maxWait
               1, // maxIdle (per key) 
               getPreparedStatementCacheSize()); 
}
 
Example #8
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void verifyParsePoolingValidationSet() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-test-specified.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123);
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22);

    Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory");
    DefaultDirContextValidator validator = (DefaultDirContextValidator) getInternalState(objectFactory, "dirContextValidator");
    assertThat(validator.getBase()).isEqualTo("ou=test");
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");

    SearchControls searchControls = ctx.getBean(SearchControls.class);
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");
    assertThat(validator.getSearchControls()).isSameAs(searchControls);

    Set<Class<? extends Throwable>> nonTransientExceptions =
            (Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
    assertThat(nonTransientExceptions).hasSize(2);
    assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
    assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
}
 
Example #9
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void verifyParsePoolingDefaults() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-defaults.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();
    assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();
    assertThat(pooledContextSource instanceof PoolingContextSource).isTrue();

    Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory");
    assertThat(getInternalState(objectFactory, "contextSource")).isNotNull();
    assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull();
    Set<Class<? extends Throwable>> nonTransientExceptions =
            (Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
    assertThat(nonTransientExceptions).hasSize(1);
    assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();

    GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMaxActive()).isEqualTo(8);
    assertThat(objectPool.getMaxTotal()).isEqualTo(-1);
    assertThat(objectPool.getMaxIdle()).isEqualTo(8);
    assertThat(objectPool.getMaxWait()).isEqualTo(-1);
    assertThat(objectPool.getMinIdle()).isEqualTo(0);
    assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)1);
}
 
Example #10
Source File: PoolingContextSource.java    From spring-ldap with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new pooling context source, setting up the DirContext object
 * factory and generic keyed object pool.
 */
public PoolingContextSource() {
	this.dirContextPoolableObjectFactory = new DirContextPoolableObjectFactory();
	this.keyedObjectPool = new GenericKeyedObjectPool();
	this.keyedObjectPool.setFactory(this.dirContextPoolableObjectFactory);
}
 
Example #11
Source File: LdapTemplateNamespaceHandlerTest.java    From spring-ldap with Apache License 2.0 4 votes vote down vote up
@Test
public void verifyParsePooling2Defaults() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-defaults.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();
    assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();
    assertThat(pooledContextSource instanceof PooledContextSource).isTrue();
    assertThat(getInternalState(pooledContextSource, "poolConfig")).isNotNull();

    Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
    assertThat(getInternalState(objectFactory, "contextSource")).isNotNull();
    assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull();
    Set<Class<? extends Throwable>> nonTransientExceptions =
            (Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
    assertThat(nonTransientExceptions).hasSize(1);
    assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();

    org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
            (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(8);
    assertThat(objectPool.getMaxTotal()).isEqualTo(-1);
    assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(8);
    assertThat(objectPool.getMinIdlePerKey()).isEqualTo(0);
    assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true);
    assertThat(objectPool.getEvictionPolicyClassName()).isEqualTo(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME);
    assertThat(objectPool.getFairness()).isEqualTo(false);

    // ensures the pool is registered
    ObjectName oname = objectPool.getJmxName();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> result = mbs.queryNames(oname, null);
    assertThat(result).hasSize(1);

    assertThat(objectPool.getLifo()).isEqualTo(true);
    assertThat(objectPool.getMaxWaitMillis()).isEqualTo(-1L);
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(1000L*60L*30L);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(3);
    assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(-1L);
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(-1L);
    assertThat(objectPool.getTestOnBorrow()).isEqualTo(false);
    assertThat(objectPool.getTestOnCreate()).isEqualTo(false);
    assertThat(objectPool.getTestOnReturn()).isEqualTo(false);
    assertThat(objectPool.getTestWhileIdle()).isEqualTo(false);
}
 
Example #12
Source File: DataEndpointAgent.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
public GenericKeyedObjectPool getTransportPool() {
    return transportPool;
}
 
Example #13
Source File: ProtoRpcRaftClientProvider.java    From barge with Apache License 2.0 4 votes vote down vote up
@Inject
public ProtoRpcRaftClientProvider(@Nonnull RpcClient client) {
  RpcChannelFactory channelFactory = new RpcChannelFactory(client);
  this.connectionPools = new GenericKeyedObjectPool<>(channelFactory, config);
}
 
Example #14
Source File: RpcClientProvider.java    From TakinRPC with Apache License 2.0 4 votes vote down vote up
@Inject
public RpcClientProvider(@Nonnull RpcClient client) {
    RpcChannelFactory channelFactory = new RpcChannelFactory(client);
    this.connectionPools = new GenericKeyedObjectPool(channelFactory, config);
}
 
Example #15
Source File: DataEndpointConfiguration.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
public GenericKeyedObjectPool getSecuredTransportPool() {
    return securedTransportPool;
}
 
Example #16
Source File: DataEndpointConfiguration.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
public GenericKeyedObjectPool getTransportPool() {
    return transportPool;
}
 
Example #17
Source File: DataEndpointAgent.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
public GenericKeyedObjectPool getSecuredTransportPool() {
    return securedTransportPool;
}
 
Example #18
Source File: AlfrescoJavaMailSender.java    From alfresco-repository with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Default constructor.
 * 
 * @param transportPool Pool to borrow/return transports to/from.
 * @param session {@link Session} used to create new transports.
 * @param protocol Mail protocol for transport.
 */
private PooledTransportWrapper(GenericKeyedObjectPool transportPool, Session session, String protocol)
{
    super(session, new URLName(protocol, null, 0, null, null, null));
    this.pool = transportPool;
    this.protocol = protocol;
}