public class PooledContextSource extends DelegatingBaseLdapPathContextSourceSupport implements ContextSource, DisposableBean
ContextSource implementation that wraps an object pool and another
ContextSource. DirContexts are retrieved from the pool which
maintains them.
NOTE: This implementation is based on apache commons-pool2.
| Property | Description | Required | Default |
|---|---|---|---|
| contextSource |
The ContextSource to get DirContexts from for adding to the
pool. |
Yes | null |
| dirContextValidator |
The DirContextValidator to use for validating DirContexts.
Required if any of the test/validate options are enabled. |
No | null |
| poolConfig | The PoolConfig to configure the pool. |
No | null |
| Modifier and Type | Field and Description |
|---|---|
protected GenericKeyedObjectPool<Object,Object> |
keyedObjectPool |
protected org.slf4j.Logger |
logger
The logger for this class and sub-classes
|
| Constructor and Description |
|---|
PooledContextSource(PoolConfig poolConfig)
Creates a new pooling context source, setting up the DirContext object
factory and generic keyed object pool.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
protected DirContext |
getContext(DirContextType dirContextType)
Gets a DirContext of the specified type from the keyed object pool.
|
DirContext |
getContext(String principal,
String credentials)
Gets a
DirContext instance authenticated using the supplied
principal and credentials. |
ContextSource |
getContextSource() |
DirContextValidator |
getDirContextValidator() |
int |
getNumActive() |
int |
getNumActiveRead() |
int |
getNumActiveWrite() |
int |
getNumIdle() |
int |
getNumIdleRead() |
int |
getNumIdleWrite() |
int |
getNumWaiters() |
PoolConfig |
getPoolConfig() |
DirContext |
getReadOnlyContext()
Gets a read-only
DirContext. |
DirContext |
getReadWriteContext()
Gets a read-write
DirContext instance. |
protected ContextSource |
getTarget()
Get the target ContextSource.
|
void |
setContextSource(ContextSource contextSource) |
void |
setDirContextValidator(DirContextValidator dirContextValidator) |
void |
setNonTransientExceptions(Collection<Class<? extends Throwable>> nonTransientExceptions)
Configure the exception classes that are to be interpreted as no-transient with regards to eager
context invalidation.
|
getBaseLdapName, getBaseLdapPath, getBaseLdapPathAsStringprotected final org.slf4j.Logger logger
protected final GenericKeyedObjectPool<Object,Object> keyedObjectPool
public PooledContextSource(PoolConfig poolConfig)
public PoolConfig getPoolConfig()
public int getNumIdle()
GenericKeyedObjectPool.getNumIdle()public int getNumIdleRead()
public int getNumIdleWrite()
public int getNumActive()
GenericKeyedObjectPool.getNumActive()public int getNumActiveRead()
public int getNumActiveWrite()
public int getNumWaiters()
GenericKeyedObjectPool.getNumWaiters()public ContextSource getContextSource()
public DirContextValidator getDirContextValidator()
public void setContextSource(ContextSource contextSource)
contextSource - the contextSource to set
Requiredpublic void setDirContextValidator(DirContextValidator dirContextValidator)
dirContextValidator - the dirContextValidator to set
Requiredpublic void setNonTransientExceptions(Collection<Class<? extends Throwable>> nonTransientExceptions)
CommunicationException.nonTransientExceptions - the exception classes that should be interpreted as non-transient
with regards to eager invalidation.public void destroy()
throws Exception
destroy in interface DisposableBeanExceptionprotected ContextSource getTarget()
DelegatingBaseLdapPathContextSourceSupportgetTarget in class DelegatingBaseLdapPathContextSourceSupportpublic DirContext getReadOnlyContext()
ContextSourceDirContext. The returned
DirContext must be possible to perform read-only operations
on.getReadOnlyContext in interface ContextSourcepublic DirContext getReadWriteContext()
ContextSourceDirContext instance.getReadWriteContext in interface ContextSourceDirContext instance, never null.protected DirContext getContext(DirContextType dirContextType)
dirContextType - The type of context to return.DataAccessResourceFailureException - If retrieving the object from
the pool throws an exceptionpublic DirContext getContext(String principal, String credentials)
ContextSourceDirContext instance authenticated using the supplied
principal and credentials. Typically to be used for plain authentication
purposes. Note that this method will never make use
of native Java LDAP pooling, even though this instance is configured to do so.
This is to force password changes in the target directory to take effect
as soon as possible.getContext in interface ContextSourceprincipal - The principal (typically a distinguished name of a user
in the LDAP tree) to use for authentication.credentials - The credentials to use for authentication.DirContext instance, never
null.