Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

/**
* @author Mattias Hellborg Arthursson
* @author Eddu Melendez
*/
public class ContextSourceParser implements BeanDefinitionParser {
private static final String ATT_ANONYMOUS_READ_ONLY = "anonymous-read-only";
Expand Down Expand Up @@ -212,15 +213,16 @@ private BeanDefinition applyPoolingIfApplicable(
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(PoolingContextSource.class);
builder.addPropertyValue("contextSource", targetContextSourceDefinition);

builder.addPropertyValue("maxActive", getInt(poolingElement, ATT_MAX_ACTIVE, DEFAULT_MAX_ACTIVE));
builder.addPropertyValue("maxTotal", getInt(poolingElement, ATT_MAX_TOTAL, DEFAULT_MAX_TOTAL));
builder.addPropertyValue("maxIdle", getInt(poolingElement, ATT_MAX_IDLE, DEFAULT_MAX_IDLE));
builder.addPropertyValue("minIdle", getInt(poolingElement, ATT_MIN_IDLE, DEFAULT_MIN_IDLE));
builder.addPropertyValue("maxWait", getInt(poolingElement, ATT_MAX_WAIT, DEFAULT_MAX_WAIT));
builder.addPropertyValue("maxActive", getString(poolingElement, ATT_MAX_ACTIVE, String.valueOf(DEFAULT_MAX_ACTIVE)));
builder.addPropertyValue("maxTotal", getString(poolingElement, ATT_MAX_TOTAL, String.valueOf(DEFAULT_MAX_TOTAL)));
builder.addPropertyValue("maxIdle", getString(poolingElement, ATT_MAX_IDLE, String.valueOf(DEFAULT_MAX_IDLE)));
builder.addPropertyValue("minIdle", getString(poolingElement, ATT_MIN_IDLE, String.valueOf(DEFAULT_MIN_IDLE)));
builder.addPropertyValue("maxWait", getString(poolingElement, ATT_MAX_WAIT, String.valueOf(DEFAULT_MAX_WAIT)));
String whenExhausted = getString(poolingElement, ATT_WHEN_EXHAUSTED, PoolExhaustedAction.BLOCK.name());
builder.addPropertyValue("whenExhaustedAction", PoolExhaustedAction.valueOf(whenExhausted).getValue());
builder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(poolingElement, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
builder.addPropertyValue("minEvictableIdleTimeMillis", getString(poolingElement, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
builder.addPropertyValue("numTestsPerEvictionRun", getString(poolingElement, ATT_TESTS_PER_EVICTION_RUN, String.valueOf(DEFAULT_TESTS_PER_EVICTION_RUN)));

boolean testOnBorrow = getBoolean(poolingElement, ATT_TEST_ON_BORROW, false);
boolean testOnReturn = getBoolean(poolingElement, ATT_TEST_ON_RETURN, false);
Expand Down Expand Up @@ -302,26 +304,26 @@ private void populatePoolConfigProperties(BeanDefinitionBuilder builder, Element
BeanDefinitionBuilder configBuilder = BeanDefinitionBuilder
.rootBeanDefinition(PoolConfig.class);

configBuilder.addPropertyValue("maxTotal", getInt(element, ATT_MAX_TOTAL, DEFAULT_MAX_TOTAL));
configBuilder.addPropertyValue("maxTotalPerKey", getInt(element, ATT_MAX_TOTAL_PER_KEY, DEFAULT_MAX_TOTAL_PER_KEY));
configBuilder.addPropertyValue("maxIdlePerKey", getInt(element, ATT_MAX_IDLE_PER_KEY, DEFAULT_MAX_IDLE_PER_KEY));
configBuilder.addPropertyValue("minIdlePerKey", getInt(element, ATT_MIN_IDLE_PER_KEY, DEFAULT_MIN_IDLE_PER_KEY));
configBuilder.addPropertyValue("maxTotal", getString(element, ATT_MAX_TOTAL, String.valueOf(DEFAULT_MAX_TOTAL)));
configBuilder.addPropertyValue("maxTotalPerKey", getString(element, ATT_MAX_TOTAL_PER_KEY, String.valueOf(DEFAULT_MAX_TOTAL_PER_KEY)));
configBuilder.addPropertyValue("maxIdlePerKey", getString(element, ATT_MAX_IDLE_PER_KEY, String.valueOf(DEFAULT_MAX_IDLE_PER_KEY)));
configBuilder.addPropertyValue("minIdlePerKey", getString(element, ATT_MIN_IDLE_PER_KEY, String.valueOf(DEFAULT_MIN_IDLE_PER_KEY)));
configBuilder.addPropertyValue("evictionPolicyClassName", getString(element, ATT_EVICTION_POLICY_CLASS, DEFAULT_EVICTION_POLICY_CLASS_NAME));
configBuilder.addPropertyValue("fairness", getBoolean(element, ATT_FAIRNESS, DEFAULT_FAIRNESS));
configBuilder.addPropertyValue("jmxEnabled", getBoolean(element, ATT_JMX_ENABLE, DEFAULT_JMX_ENABLE));
configBuilder.addPropertyValue("jmxNameBase", getString(element, ATT_JMX_NAME_BASE, DEFAULT_JMX_NAME_BASE));
configBuilder.addPropertyValue("jmxNamePrefix", getString(element, ATT_JMX_NAME_PREFIX, DEFAULT_JMX_NAME_PREFIX));
configBuilder.addPropertyValue("lifo", getBoolean(element, ATT_LIFO, DEFAULT_LIFO));
configBuilder.addPropertyValue("maxWaitMillis", getInt(element, ATT_MAX_WAIT, DEFAULT_MAX_WAIT_MILLIS));
configBuilder.addPropertyValue("blockWhenExhausted", getBoolean(element, ATT_BLOCK_WHEN_EXHAUSTED, DEFAULT_BLOCK_WHEN_EXHAUSTED));
configBuilder.addPropertyValue("maxWaitMillis", getString(element, ATT_MAX_WAIT, String.valueOf(DEFAULT_MAX_WAIT_MILLIS)));
configBuilder.addPropertyValue("blockWhenExhausted", Boolean.valueOf(getString(element, ATT_BLOCK_WHEN_EXHAUSTED, String.valueOf(DEFAULT_BLOCK_WHEN_EXHAUSTED))));
configBuilder.addPropertyValue("testOnBorrow", getBoolean(element, ATT_TEST_ON_BORROW, false));
configBuilder.addPropertyValue("testOnCreate", getBoolean(element, ATT_TEST_ON_CREATE, false));
configBuilder.addPropertyValue("testOnReturn", getBoolean(element, ATT_TEST_ON_RETURN, false));
configBuilder.addPropertyValue("testWhileIdle", getBoolean(element, ATT_TEST_WHILE_IDLE, false));
configBuilder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
configBuilder.addPropertyValue("numTestsPerEvictionRun", getInt(element, ATT_TESTS_PER_EVICTION_RUN, DEFAULT_TESTS_PER_EVICTION_RUN));
configBuilder.addPropertyValue("numTestsPerEvictionRun", getString(element, ATT_TESTS_PER_EVICTION_RUN, String.valueOf(DEFAULT_TESTS_PER_EVICTION_RUN)));
configBuilder.addPropertyValue("minEvictableIdleTimeMillis", getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
configBuilder.addPropertyValue("softMinEvictableIdleTimeMillis", getInt(element, ATT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
configBuilder.addPropertyValue("softMinEvictableIdleTimeMillis", getString(element, ATT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, String.valueOf(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS)));

builder.addConstructorArgValue(configBuilder.getBeanDefinition());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</xs:attributeGroup>

<xs:attributeGroup name="pooling.attlist">
<xs:attribute name="max-active" type="xs:integer">
<xs:attribute name="max-active" type="xs:string">
<xs:annotation>
<xs:documentation>
The maximum number of active connections of each type (read-only|read-write)
Expand All @@ -114,31 +114,31 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="max-total" type="xs:integer">
<xs:attribute name="max-total" type="xs:string">
<xs:annotation>
<xs:documentation>
The overall maximum number of active connections (for all types) that can be allocated from
this pool at the same time, or non-positive for no limit. Default is -1 (no limit).
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="max-idle" type="xs:integer">
<xs:attribute name="max-idle" type="xs:string">
<xs:annotation>
<xs:documentation>
The maximum number of active connections of each type (read-only|read-write) that can remain idle in the pool,
without extra ones being released, or non-positive for no limit. Default is 8.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="min-idle" type="xs:integer">
<xs:attribute name="min-idle" type="xs:string">
<xs:annotation>
<xs:documentation>
The minimum number of active connections of each type (read-only|read-write) that can remain
idle in the pool, without extra ones being created, or zero to create none. Default is 0.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="max-wait" type="xs:integer">
<xs:attribute name="max-wait" type="xs:string">
<xs:annotation>
<xs:documentation>
The maximum number of milliseconds that the pool will wait (when there are no available connections)
Expand Down Expand Up @@ -214,7 +214,7 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="tests-per-eviction-run" type="xs:int">
<xs:attribute name="tests-per-eviction-run" type="xs:string">
<xs:annotation>
<xs:documentation>
The number of objects to examine during each run of the idle object evictor thread (if any).
Expand Down Expand Up @@ -263,15 +263,15 @@
</xs:attributeGroup>

<xs:attributeGroup name="pooling2.attlist">
<xs:attribute name="max-total" type="xs:integer">
<xs:attribute name="max-total" type="xs:string">
<xs:annotation>
<xs:documentation>
The overall maximum number of active connections (for all types) that can be allocated from
this pool at the same time, or non-positive for no limit. Default is -1 (no limit).
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="max-total-per-key" type="xs:integer">
<xs:attribute name="max-total-per-key" type="xs:string">
<xs:annotation>
<xs:documentation>
The limit on the number of object instances allocated by the pool (checked out or idle),
Expand All @@ -280,23 +280,23 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="max-idle-per-key" type="xs:integer">
<xs:attribute name="max-idle-per-key" type="xs:string">
<xs:annotation>
<xs:documentation>
The maximum number of active connections per type (read-only|read-write) that can remain idle in the pool,
without extra ones being released, or non-positive for no limit. Default is 8.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="min-idle-per-key" type="xs:integer">
<xs:attribute name="min-idle-per-key" type="xs:string">
<xs:annotation>
<xs:documentation>
The minimum number of active connections per type (read-only|read-write) that can remain
idle in the pool, without extra ones being created, or zero to create none. Default is 0.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="max-wait" type="xs:integer">
<xs:attribute name="max-wait" type="xs:string">
<xs:annotation>
<xs:documentation>
The maximum number of milliseconds that the pool will wait (when there are no available connections)
Expand Down Expand Up @@ -355,7 +355,7 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="tests-per-eviction-run" type="xs:int">
<xs:attribute name="tests-per-eviction-run" type="xs:string">
<xs:annotation>
<xs:documentation>
The number of objects to examine during each run of the idle object evictor thread (if any).
Expand All @@ -371,7 +371,7 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="soft-min-evictable-idle-time-millis" type="xs:int">
<xs:attribute name="soft-min-evictable-idle-time-millis" type="xs:string">
<xs:annotation>
<xs:documentation>
The minimum amount of time an object may sit idle in the pool before it is eligible for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ public void verifyParsePoolWithPlaceholders() {
GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(20, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(10, objectPool.getMaxWait());
assertEquals(11, objectPool.getMaxTotal());
assertEquals(15, objectPool.getMaxActive());
assertEquals(16, objectPool.getMinIdle());
assertEquals(17, objectPool.getMaxIdle());
assertEquals(18, objectPool.getNumTestsPerEvictionRun());
}

@Test
Expand All @@ -522,5 +528,11 @@ public void verifyParsePool2WithPlaceholders() {
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(20, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(10, objectPool.getMaxWaitMillis());
assertEquals(11, objectPool.getMaxTotal());
assertEquals(12, objectPool.getMinIdlePerKey());
assertEquals(13, objectPool.getMaxIdlePerKey());
assertEquals(14, objectPool.getMaxTotalPerKey());
assertEquals(18, objectPool.getNumTestsPerEvictionRun());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<context:property-placeholder location="classpath*:ldap.properties" />

<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling eviction-run-interval-millis="${ldap.eviction.run.internal.milis}" min-evictable-time-millis="${ldap.min.evictable.time.milis}"/>
<ldap:pooling eviction-run-interval-millis="${ldap.eviction.run.internal.milis}" min-evictable-time-millis="${ldap.min.evictable.time.milis}"
max-wait="${ldap.maxWait}" max-total="${ldap.maxTotal}" max-active="${ldap.maxActive}" min-idle="${ldap.minIdle}" max-idle="${ldap.maxIdle}"
tests-per-eviction-run="${ldap.testsPerEvictionRun}" />
</ldap:context-source>

<ldap:ldap-template />
</beans>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<context:property-placeholder location="classpath*:ldap.properties" />

<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling2 eviction-run-interval-millis="${ldap.eviction.run.internal.milis}" min-evictable-time-millis="${ldap.min.evictable.time.milis}"/>
<ldap:pooling2 eviction-run-interval-millis="${ldap.eviction.run.internal.milis}" min-evictable-time-millis="${ldap.min.evictable.time.milis}"
max-wait="${ldap.maxWait}" max-total="${ldap.maxTotal}" min-idle-per-key="${ldap.minIdlePerKey}" max-idle-per-key="${ldap.maxIdlePerKey}" max-total-per-key="${ldap.maxTotalPerKey}"
tests-per-eviction-run="${ldap.testsPerEvictionRun}" />
</ldap:context-source>

<ldap:ldap-template />
Expand Down
14 changes: 13 additions & 1 deletion core/src/test/resources/ldap.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
ldap.eviction.run.internal.milis=10
ldap.min.evictable.time.milis=20
ldap.min.evictable.time.milis=20
ldap.maxWait=10
ldap.maxTotal=11
ldap.minIdlePerKey=12
ldap.maxIdlePerKey=13
ldap.maxTotalPerKey=14
ldap.maxActive=15
ldap.minIdle=16
ldap.maxIdle=17
ldap.testsPerEvictionRun=18
ldap.testOnBorrow=true
ldap.testOnReturn=true
ldap.testWhileIdle=true