|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ca.commons.jndi.beans.ResilientDirContextFactory
public class ResilientDirContextFactory
A factory that produces a directory context that can automatically
recover from communication failures. The DirContext
object returned by the getContext method is a
proxy that wraps the real DirContext object.
The proxy will catch any CommunicationExceptions or
ServiceUnavailableExceptions thrown by the real context,
and attempt to automatically retry the failed operation.
Such an occurrence is termed a transient failure.
A retry involves discarding the context that threw the exception,
waiting for a period of time, then attempting to create a new
context and re-issuing the original call using the new
context. If a transient failure occurs when retrying an operation,
a retry will again be attempted, until the limit on the number
of retries has been reached. If the retry limit is reached, the
exception is thrown to the caller and no more retry attempts are made.
The retry limit and the delay between retries can both be configured.
Instances of this class can be configured to automatically switch to alternate hosts whenever a transient failure occurs. This is useful if you have several identical hosts available and one of them goes down, in which case the context proxy will catch the failure and automatically switch to an alternate server.
To enable failover support, supply a list of available hosts via
the setFailoverList(java.util.List) method. This list should
be sorted with the preferred hosts first. If the value provided to
the setRetries(int) method is less than the size of the
failover list, then it is ignored. Therefore, each server in the
failover list is always tried at least once before giving up and
throwing the exception to the caller.
Note that failover support assumes that the JNDI environment contains
a Context.PROVIDER_URL property. The host name component of
this URL is replaced by the next value from the failover list when
a retry is performed.
| Field Summary | |
|---|---|
protected int |
defaultPort
|
protected long |
delay
|
protected Properties |
jndiEnv
|
static Logger |
LOGGER
|
protected DirContext |
realCtx
|
| Constructor Summary | |
|---|---|
ResilientDirContextFactory()
|
|
ResilientDirContextFactory(int defaultPort)
|
|
| Method Summary | |
|---|---|
void |
close()
Indicates that the JNDIBeanStore using this factory
has been closed down. |
protected Object |
doInvoke(Method method,
Object[] args)
|
DirContext |
getContext()
Returns a DirContext instance that is ready for use. |
List<String> |
getFailoverList()
Returns the list of host names being used for failover. |
Properties |
getJNDIEnv()
|
int |
getRetries()
|
long |
getRetryDelay()
Returns the delay between retries, in milliseconds. |
Object |
invoke(Object proxy,
Method method,
Object[] args)
|
void |
returnContext(DirContext ctx)
Called to indicate that a DirContext previously
provided by this factory is no longer needed. |
void |
setFailoverList(List<String> failoverList)
Sets the list of hosts names to use for failover. |
void |
setJNDIEnv(Properties jndiEnv)
Sets the JNDI environment to use to create directory contexts. |
void |
setRetries(int retries)
Sets the number of times an operation will be retried before giving up. |
void |
setRetryDelay(long retryDelay)
Sets the delay in milliseconds between retries. |
protected void |
testContexts()
Step through all hosts from most preferred to least, setting realCtx to first host that can be contacted. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Logger LOGGER
protected Properties jndiEnv
protected long delay
protected volatile DirContext realCtx
protected final int defaultPort
| Constructor Detail |
|---|
public ResilientDirContextFactory(int defaultPort)
public ResilientDirContextFactory()
| Method Detail |
|---|
public String toString()
toString in class Objectpublic final void setJNDIEnv(Properties jndiEnv)
jndiEnv - The environment to pass to the
InitialDirContext.InitialDirContext(java.util.Hashtable)
method.public final Properties getJNDIEnv()
public final void setRetries(int retries)
setFailoverList(java.util.List)public final int getRetries()
public final void setRetryDelay(long retryDelay)
retryDelay - The delay, in milliseconds.public final long getRetryDelay()
public final void setFailoverList(List<String> failoverList)
failoverList - A list of host name strings.public final List<String> getFailoverList()
public final DirContext getContext()
DirContextFactoryDirContext instance that is ready for use.
The object returned by this method will always be passed back
as a parameter to the returnContext method.
getContext in interface DirContextFactoryDirContextFactory.returnContext(javax.naming.directory.DirContext)public final void returnContext(DirContext ctx)
DirContextFactoryDirContext previously
provided by this factory is no longer needed.
returnContext in interface DirContextFactoryctx - The DirContext previously returned by
the getContext method.DirContextFactory.getContext()
public final void close()
throws NamingException
DirContextFactoryJNDIBeanStore using this factory
has been closed down. An implementation should free up any
resources it is using.
close in interface DirContextFactoryNamingException - If there was a problem when freeing resources.JNDIBeanStore.close()
protected void testContexts()
throws NamingException
NamingException
protected Object doInvoke(Method method,
Object[] args)
throws IllegalAccessException,
InterruptedException,
NamingException,
InvocationTargetException
IllegalAccessException
InterruptedException
NamingException
InvocationTargetException
public Object invoke(Object proxy,
Method method,
Object[] args)
throws Throwable
invoke in interface InvocationHandlerThrowable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||