|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.curator.SessionFailRetryLoop
public class SessionFailRetryLoop
See RetryLoop
for the main details on retry loops. All Curator/ZooKeeper operations
should be done in a retry loop.
The standard retry loop treats session failure as a type of connection failure. i.e. the fact that it is a session failure isn't considered. This can be problematic if you are performing a series of operations that rely on ephemeral nodes. If the session fails after the ephemeral node has been created, future Curator/ZooKeeper operations may succeed even though the ephemeral node has been removed by ZooKeeper.
Here's an example:
The SessionFailRetryLoop prevents this type of scenario. When a session failure is detected,
the thread is marked as failed which will cause all future Curator operations to fail. The
SessionFailRetryLoop will then either retry the entire
set of operations or fail (depending on SessionFailRetryLoop.Mode
)
SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(mode); retryLoop.start(); try { while ( retryLoop.shouldContinue() ) { try { // do work } catch ( Exception e ) { retryLoop.takeException(e); } } } finally { retryLoop.close(); }
Nested Class Summary | |
---|---|
static class |
SessionFailRetryLoop.Mode
|
static class |
SessionFailRetryLoop.SessionFailedException
|
Method Summary | ||
---|---|---|
static
|
callWithRetry(CuratorZookeeperClient client,
SessionFailRetryLoop.Mode mode,
Callable<T> proc)
Convenience utility: creates a "session fail" retry loop calling the given proc |
|
void |
close()
Must be called in a finally handler when done with the loop |
|
boolean |
shouldContinue()
If true is returned, make an attempt at the set of operations |
|
void |
start()
SessionFailRetryLoop must be started |
|
void |
takeException(Exception exception)
Pass any caught exceptions here |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T callWithRetry(CuratorZookeeperClient client, SessionFailRetryLoop.Mode mode, Callable<T> proc) throws Exception
T
- return typeclient
- Zookeepermode
- how to handle session failuresproc
- procedure to call with retry
SessionFailRetryLoop.SessionFailedException
- any non-retriable errors
Exception
public void start()
public boolean shouldContinue()
public void close()
close
in interface Closeable
public void takeException(Exception exception) throws Exception
exception
- the exception
SessionFailRetryLoop.SessionFailedException
- if not retry-able or the retry policy returned negative
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |