Skip to content

Instantly share code, notes, and snippets.

@gunnarmorling
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunnarmorling/ddfdb70c19926c93c6fd to your computer and use it in GitHub Desktop.
Save gunnarmorling/ddfdb70c19926c93c6fd to your computer and use it in GitHub Desktop.
OGM-465 Error handling SPI
public class MyErrorHandler implements ErrorHandler {
// invoked if there is any anticipated error in the context of executing an operation; implementor
// can retry/skip or abort; engine will raise a UnrecoverableGridOperationException when returning ABORT
public ErrorHandlingStrategy onFailedOperation(ErrorType errorType, Operation failedOperation) {
boolean retrySuccessful;
switch ( errorType ) {
case OPTIMISTIC_LOCK_VIOLATION:
// refreshAndRetry() would re-read the tuple/assoc and re-apply the change
retrySuccessful = failedOperation.refreshAndRetry();
return retrySuccessful ? ErrorHandlingStrategy.CONTINUE : ErrorHandlingStrategy.ABORT;
case TIMEOUT:
// retry() would just run it again
retrySuccessful = failedOperation.retry();
return retrySuccessful ? ErrorHandlingStrategy.CONTINUE : ErrorHandlingStrategy.ABORT;
default:
return ErrorHandlingStrategy.ABORT;
}
}
// invoked if there is any un-anticipated error (including UnrecoverableGridOperationException raised when ABORT
// has been returned by failed operation handler); I guess only sensible reaction is to revert() on a best-effort basis
public ErrorHandlingStrategy onExeption(Exception e, List<Operation> executedOperations) {
for ( Operation operation : executedOperations ) {
operation.revert();
}
return ErrorHandlingStrategy.ABORT;
}
}
public enum ErrorHandlingStrategy {
ABORT, CONTINUE;
}
public enum ErrorType {
OPTIMISTIC_LOCK_VIOLATION, TIMEOUT;
}
// UC-1: As a user of OGM, upon an exception during flush(), I want to log all operations applied so far and abort the
// processing of the flush cycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment