Package ome.formats.importer.util
Class ErrorHandler
- java.lang.Object
-
- ome.formats.importer.util.ErrorHandler
-
- All Implemented Interfaces:
IObservable,IObserver
- Direct Known Subclasses:
ErrorHandler
public abstract class ErrorHandler extends java.lang.Object implements IObserver, IObservable
Top of the error handling hierarchy. Will add errors to a queue which can be sent withsendErrors(). Subclasses will get a chance to handle allImportEventinstances, but should try not to duplicate handling.- Since:
- Beta4.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classErrorHandler.EXCEPTION_EVENTstatic classErrorHandler.FILE_EXCEPTIONErrorHandler.FILE_EXCEPTIONs are thrown any time in the context of a particular file and otherwise unspecified exception takes place.static classErrorHandler.INTERNAL_EXCEPTIONstatic classErrorHandler.MISSING_LIBRARYAErrorHandler.FILE_EXCEPTIONcaused specifically by some library (native or otherwise) not being installed locally.static classErrorHandler.UNKNOWN_FORMATUnlikeErrorHandler.FILE_EXCEPTION, UNKNOWN_FORMAT does not have a reader since bio-formats is telling us that it does not know how to handle the given file.static classErrorHandler.UNREADABLE_FILESimilar toErrorHandler.UNKNOWN_FORMATUNREADABLE_FILE specifies that the file which is being accessed is unreadable (does not exist or canRead is false), so if the user is specifically saying that the file should be imported, there may be some underlying issue.
-
Field Summary
Fields Modifier and Type Field Description protected booleancancelUploadsprotected ImportConfigconfigprotected java.util.List<ErrorContainer>errorsbooleanfileUploadErrorsprotected java.util.Map<java.lang.String,ImportContainer>icMapHost information about the file and its corresponding import candidate.protected org.slf4j.Loggerlogprotected java.util.List<IObserver>observersprotected booleansendFilesprotected booleansendLogsprotected inttotalErrors
-
Constructor Summary
Constructors Constructor Description ErrorHandler(ImportConfig config)Initialize
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddError(java.lang.Throwable error, java.io.File file, java.lang.String[] files, java.lang.String readerType)Add detailed error to error container arraybooleanaddObserver(IObserver object)Add observer for notificationprotected voidclearErrors(int index)booleandeleteObserver(IObserver object)Delete observerinterrorCount()voidexecutePost(java.lang.String sendUrl, java.util.Map<java.lang.String,java.lang.String> postList)Execute a post with the given post list.protected voidfinishCancelled()Action to take when finish cancelledprotected voidfinishComplete()Action to take when finish completedprotected voidfinishWithErroredFiles()Action to take when finish completed but with some errors (For example, missing files)static java.lang.StringgetStackTrace(java.lang.Throwable throwable)Return the stack trace from aThrowable.protected booleanisSend(int index)Check if files need sending at error container indexvoidnotifyObservers(ImportEvent event)Notify observers of eventprotected voidonAddError(ErrorContainer errorContainer, java.lang.String message)Action to take on adding an error to containerprotected voidonCancel()action to take on cancelprotected voidonException(java.lang.Exception exception)Action to take on exceptionprotected voidonNotSending(int index, java.lang.String serverReply)protected voidonSending(int index)protected voidonSent(int index)protected abstract voidonUpdate(IObservable importLibrary, ImportEvent event)abstract on update methodprotected voidsendErrors()Send existing errors in ErrorContainer array to servervoidupdate(IObservable observable, ImportEvent event)Update observable on eventvoiduploadFile(ErrorContainer errorContainer)Upload a singleErrorContainer.
-
-
-
Field Detail
-
log
protected final org.slf4j.Logger log
-
observers
protected final java.util.List<IObserver> observers
-
errors
protected final java.util.List<ErrorContainer> errors
-
config
protected final ImportConfig config
-
cancelUploads
protected boolean cancelUploads
-
sendFiles
protected boolean sendFiles
-
sendLogs
protected boolean sendLogs
-
fileUploadErrors
public boolean fileUploadErrors
-
totalErrors
protected int totalErrors
-
icMap
protected java.util.Map<java.lang.String,ImportContainer> icMap
Host information about the file and its corresponding import candidate.
-
-
Constructor Detail
-
ErrorHandler
public ErrorHandler(ImportConfig config)
Initialize- Parameters:
config- the import configuration
-
-
Method Detail
-
update
public final void update(IObservable observable, ImportEvent event)
Description copied from interface:IObserverUpdate observable on event
-
errorCount
public int errorCount()
- Returns:
- number of errors in ErrorContainer array
-
onUpdate
protected abstract void onUpdate(IObservable importLibrary, ImportEvent event)
abstract on update method- Parameters:
importLibrary- the import libraryevent- - importEvent
-
sendErrors
protected void sendErrors()
Send existing errors in ErrorContainer array to server
-
addError
protected void addError(java.lang.Throwable error, java.io.File file, java.lang.String[] files, java.lang.String readerType)Add detailed error to error container array- Parameters:
error- - error thrownfile- - head file for errorfiles- - all files in import collectionreaderType- - reader type supplied from bio-formats
-
clearErrors
protected void clearErrors(int index)
-
addObserver
public final boolean addObserver(IObserver object)
Description copied from interface:IObservableAdd observer for notification- Specified by:
addObserverin interfaceIObservable- Parameters:
object- - observer object- Returns:
- true if added
-
deleteObserver
public final boolean deleteObserver(IObserver object)
Description copied from interface:IObservableDelete observer- Specified by:
deleteObserverin interfaceIObservable- Parameters:
object- - observer to delete- Returns:
- true if deleted
-
notifyObservers
public final void notifyObservers(ImportEvent event)
Description copied from interface:IObservableNotify observers of event- Specified by:
notifyObserversin interfaceIObservable- Parameters:
event- - event that happened
-
onCancel
protected void onCancel()
action to take on cancel
-
onAddError
protected void onAddError(ErrorContainer errorContainer, java.lang.String message)
Action to take on adding an error to container- Parameters:
errorContainer- - error containermessage- - message string for action (if needed)
-
isSend
protected boolean isSend(int index)
Check if files need sending at error container index- Parameters:
index- - index in error container- Returns:
- - true if file is to be sent
-
onSending
protected void onSending(int index)
- Parameters:
index- the index in the error container
-
onSent
protected void onSent(int index)
- Parameters:
index- the index in the error container
-
onNotSending
protected void onNotSending(int index, java.lang.String serverReply)- Parameters:
index- the index in the error containerserverReply- the reply from the server
-
onException
protected void onException(java.lang.Exception exception)
Action to take on exception- Parameters:
exception- the exception
-
finishCancelled
protected void finishCancelled()
Action to take when finish cancelled
-
finishComplete
protected void finishComplete()
Action to take when finish completed
-
finishWithErroredFiles
protected void finishWithErroredFiles()
Action to take when finish completed but with some errors (For example, missing files)
-
executePost
public void executePost(java.lang.String sendUrl, java.util.Map<java.lang.String,java.lang.String> postList) throws HtmlMessengerExceptionExecute a post with the given post list. This can be overwritten in order to test error handling without touching QA. The server reply should be non-null, but is otherwise unimportant.- Parameters:
sendUrl- the HTTP POST URLpostList- the form values- Throws:
HtmlMessengerException- if POST fails
-
uploadFile
public void uploadFile(ErrorContainer errorContainer)
Upload a singleErrorContainer. This can be overwritten in order to test error handling without touching QA.- Parameters:
errorContainer- the error container
-
getStackTrace
public static java.lang.String getStackTrace(java.lang.Throwable throwable)
Return the stack trace from aThrowable.- Parameters:
throwable- theThrowableto inspect- Returns:
- the stack trace
-
-