Support integer property placeholders for pool and pool2
See gh-387
This commit is contained in:
@@ -45,6 +45,7 @@ import static org.springframework.ldap.config.ParserUtils.getString;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Eddu Melendez
|
||||
*/
|
||||
public class ContextSourceParser implements BeanDefinitionParser {
|
||||
private static final String ATT_ANONYMOUS_READ_ONLY = "anonymous-read-only";
|
||||
@@ -212,15 +213,16 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
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);
|
||||
@@ -302,26 +304,26 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -114,7 +114,7 @@
|
||||
</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
|
||||
@@ -122,7 +122,7 @@
|
||||
</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,
|
||||
@@ -130,7 +130,7 @@
|
||||
</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
|
||||
@@ -138,7 +138,7 @@
|
||||
</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)
|
||||
@@ -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).
|
||||
@@ -263,7 +263,7 @@
|
||||
</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
|
||||
@@ -271,7 +271,7 @@
|
||||
</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),
|
||||
@@ -280,7 +280,7 @@
|
||||
</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,
|
||||
@@ -288,7 +288,7 @@
|
||||
</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
|
||||
@@ -296,7 +296,7 @@
|
||||
</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)
|
||||
@@ -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).
|
||||
@@ -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
|
||||
|
||||
@@ -507,6 +507,12 @@ public class LdapTemplateNamespaceHandlerTest {
|
||||
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
|
||||
@@ -522,5 +528,11 @@ public class LdapTemplateNamespaceHandlerTest {
|
||||
(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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 />
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user