|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Throwable
java.lang.Exception
com.amazon.carbonado.RepositoryException
public class RepositoryException
General checked exception thrown when accessing a 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 Summary | |
|---|---|
RepositoryException()
|
|
RepositoryException(String message)
|
|
RepositoryException(String message,
Throwable cause)
|
|
RepositoryException(Throwable cause)
|
|
| Method Summary | ||
|---|---|---|
static
|
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. |
|
Throwable |
getRootCause()
Recursively calls getCause, until the root cause is found. |
|
protected FetchException |
makeFetchException(String message,
Throwable cause)
Subclasses can override this to provide a more specialized exception. |
|
protected PersistException |
makePersistException(String message,
Throwable cause)
Subclasses can override this to provide a more specialized exception. |
|
FetchException |
toFetchException()
Converts RepositoryException into an appropriate FetchException. |
|
FetchException |
toFetchException(String message)
Converts RepositoryException into an appropriate FetchException, prepending the specified message. |
|
PersistException |
toPersistException()
Converts RepositoryException into an appropriate PersistException. |
|
PersistException |
toPersistException(String message)
Converts RepositoryException into an appropriate PersistException, prepending the specified message. |
|
| Methods inherited from class java.lang.Throwable |
|---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public RepositoryException()
public RepositoryException(String message)
public RepositoryException(String message,
Throwable cause)
public RepositoryException(Throwable cause)
| Method Detail |
|---|
public static <E extends Throwable> int backoff(E e,
int retryCount,
int milliseconds)
throws E extends 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 wait
E - if retry count is zero
E extends Throwablepublic Throwable getRootCause()
public final PersistException toPersistException()
public final PersistException toPersistException(String message)
message - message to prepend, which may be nullpublic final FetchException toFetchException()
public final FetchException toFetchException(String message)
message - message to prepend, which may be null
protected PersistException makePersistException(String message,
Throwable cause)
message - exception message, which may be nullcause - non-null cause
protected FetchException makeFetchException(String message,
Throwable cause)
message - exception message, which may be nullcause - non-null cause
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||