public class RepositoryException
extends java.lang.Exception
Repository
.
Some repository exceptions are the result of an optimistic lock failure or deadlock. One resolution strategy is to exit all transactions and try the operation again, after waiting some bounded random amount of time. As a convenience, this class provides a mechanism to support such a backoff strategy. For example:
// Retry at most three more times for (int retryCount = 3;;) { try { ... myObject.load(); ... myObject.update(); break; } catch (OptimisticLockException e) { // Wait up to one second before retrying retryCount = e.backoff(e, retryCount, 1000); } }If the retry count is zero (or less) when backoff is called, then the original exception is rethrown, indicating retry failure.
Constructor and Description |
---|
RepositoryException() |
RepositoryException(java.lang.String message) |
RepositoryException(java.lang.String message,
java.lang.Throwable cause) |
RepositoryException(java.lang.Throwable cause) |
Modifier and Type | Method and Description |
---|---|
static <E extends java.lang.Throwable> |
backoff(E e,
int retryCount,
int milliseconds)
One strategy for resolving an optimistic lock failure is to try the
operation again, after waiting some bounded random amount of time.
|
java.lang.Throwable |
getRootCause()
Recursively calls getCause, until the root cause is found.
|
protected FetchException |
makeFetchException(java.lang.String message,
java.lang.Throwable cause)
Subclasses can override this to provide a more specialized exception.
|
protected PersistException |
makePersistException(java.lang.String message,
java.lang.Throwable cause)
Subclasses can override this to provide a more specialized exception.
|
FetchException |
toFetchException()
Converts RepositoryException into an appropriate FetchException.
|
FetchException |
toFetchException(java.lang.String message)
Converts RepositoryException into an appropriate FetchException, prepending
the specified message.
|
PersistException |
toPersistException()
Converts RepositoryException into an appropriate PersistException.
|
PersistException |
toPersistException(java.lang.String message)
Converts RepositoryException into an appropriate PersistException, prepending
the specified message.
|
public RepositoryException()
public RepositoryException(java.lang.String message)
public RepositoryException(java.lang.String message, java.lang.Throwable cause)
public RepositoryException(java.lang.Throwable cause)
public static <E extends java.lang.Throwable> int backoff(E e, int retryCount, int milliseconds) throws E extends java.lang.Throwable
A retry count is required as well, which is decremented and returned by this method. If the retry count is zero (or less) when this method is called, then this exception is thrown again, indicating retry failure.
retryCount
- current retry count, if zero, throw this exception againmilliseconds
- upper bound on the random amount of time to waitE
- if retry count is zeroE extends java.lang.Throwable
public java.lang.Throwable getRootCause()
public final PersistException toPersistException()
public final PersistException toPersistException(java.lang.String message)
message
- message to prepend, which may be nullpublic final FetchException toFetchException()
public final FetchException toFetchException(java.lang.String message)
message
- message to prepend, which may be nullprotected PersistException makePersistException(java.lang.String message, java.lang.Throwable cause)
message
- exception message, which may be nullcause
- non-null causeprotected FetchException makeFetchException(java.lang.String message, java.lang.Throwable cause)
message
- exception message, which may be nullcause
- non-null causeCopyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.