Class AbstractRemoteMetadataSource
java.lang.Object
org.dspace.importer.external.service.components.AbstractRemoteMetadataSource
- Direct Known Subclasses:
AbstractImportMetadataSourceService
This class contains primitives to handle request timeouts and to retry requests.
This is achieved by classifying exceptions as fatal or as non fatal/retryable.
Evidently only subclasses can make the proper determination of what is retryable and what isn't.
This is useful in case the service employs throttling and to deal with general network issues.
- Author:
- Roeland Dillen (roeland at atmire dot com), Antoine Snyers (antoine at atmire dot com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Exceptionprotected Map<Class,List<SourceExceptionHandler>> protected longprotected longprotected ReentrantLockprotected intprotected Stringprotected intprotected String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs an empty MetadataSource class object and initializes the Exceptionhandlers -
Method Summary
Modifier and TypeMethodDescriptiongetError()Retrieve the last encountered exceptionprotected List<SourceExceptionHandler>getExceptionHandler(Exception exception) Retrieve a list of SourceExceptionHandler objects that have an instanceof the exception configured to them.intReturn the number of max retries that can be undertaken before separate functionality kicks inRetrieve the operationIdintgetRetry()Return the number of retries that have currently been undertakenReturn the warning message used for logging during exception catchingprotected voidhandleException(int retry, Exception exception, String operationId) Handles a given exception or throws on aMetadataSourceExceptionif no ExceptionHandler is setabstract voidinit()Attempts to init a sessionprotected voidinitialize the exceptionHandlersMap with an emptyLinkedHashMapprotected <T> TCommand pattern implementation. the callable.call method will be retried until it either succeeds or reaches the try limit.voidSet the last encountered errorvoidsetInterRequestTime(long interRequestTime) voidsetMaxRetry(int maxRetry) Set the number of maximum retries before throwing on the exceptionvoidsetWarning(String warning) Set the warning message used for loggingprotected voidthrowSourceException(int retry, Exception exception, String operationId) Throw aMetadataSourceExceptionprotected voidA specified point where methods can be specified or callbacks can be executed
-
Field Details
-
lastRequest
protected long lastRequest -
interRequestTime
protected long interRequestTime -
lock
-
maxRetry
protected int maxRetry -
retry
protected int retry -
operationId
-
warning
-
exceptionHandlersMap
-
error
-
-
Constructor Details
-
AbstractRemoteMetadataSource
protected AbstractRemoteMetadataSource()Constructs an empty MetadataSource class object and initializes the Exceptionhandlers
-
-
Method Details
-
initExceptionHandlers
protected void initExceptionHandlers()initialize the exceptionHandlersMap with an emptyLinkedHashMap -
getWarning
Return the warning message used for logging during exception catching- Returns:
- a "warning" String
-
setWarning
Set the warning message used for logging- Parameters:
warning- warning message
-
getRetry
public int getRetry()Return the number of retries that have currently been undertaken- Returns:
- the number of retries
-
getMaxRetry
public int getMaxRetry()Return the number of max retries that can be undertaken before separate functionality kicks in- Returns:
- maximum number of retries
-
setMaxRetry
public void setMaxRetry(int maxRetry) Set the number of maximum retries before throwing on the exception- Parameters:
maxRetry- maximum number of retries
-
getOperationId
Retrieve the operationId- Returns:
- A randomly generated UUID. generated during the retry method
-
getError
Retrieve the last encountered exception- Returns:
- An Exception object, the last one encountered in the retry method
-
setError
Set the last encountered error- Parameters:
error- exception to set
-
retry
Command pattern implementation. the callable.call method will be retried until it either succeeds or reaches the try limit. Maybe this should have a backoff algorithm instead of waiting a fixed time.- Type Parameters:
T- return type. Generics for type safety.- Parameters:
callable- the callable to call. See the classes with the same name as the public methods of this class.- Returns:
- The result of the call
- Throws:
MetadataSourceException- if something unrecoverable happens (e.g . network failures)
-
handleException
protected void handleException(int retry, Exception exception, String operationId) throws MetadataSourceException Handles a given exception or throws on aMetadataSourceExceptionif no ExceptionHandler is set- Parameters:
retry- The number of retries before the exception was thrown onexception- The exception to handleoperationId- The id of the operation that threw the exception- Throws:
MetadataSourceException- if no ExceptionHandler is configured for the given exception
-
getExceptionHandler
Retrieve a list of SourceExceptionHandler objects that have an instanceof the exception configured to them.- Parameters:
exception- The exception to base the retrieval ofSourceExceptionHandleron- Returns:
- a list of
SourceExceptionHandlerobjects
-
throwSourceException
protected void throwSourceException(int retry, Exception exception, String operationId) throws MetadataSourceException Throw aMetadataSourceException- Parameters:
retry- The number of retries before the exception was thrown onexception- The exception to throwoperationId- The id of the operation that threw the exception- Throws:
MetadataSourceException- if no ExceptionHandler is configured for the given exception
-
throwSourceExceptionHook
protected void throwSourceExceptionHook()A specified point where methods can be specified or callbacks can be executed -
init
Attempts to init a session- Throws:
Exception- on generic exception
-
setInterRequestTime
public void setInterRequestTime(long interRequestTime)
-