-
-
Save gunnarmorling/ddfdb70c19926c93c6fd to your computer and use it in GitHub Desktop.
OGM-465 Error handling SPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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