|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface MessageRecorder
Records warnings and errors during the processing of a task. Contexts can be added and removed. This allows one to collect more than one warning/error, keep processing, and then the code that initiated the processing can determine what to do with the warnings/errors if they exist.
A typical usage might be:
void process(MessageRecorder msgRecorder) {
msgRecorder.pushContextName(getName());
try {
// prcess task
....
// need to generate warning message
String msg = ...
msgRecorder.reportWarning(msg);
....
} finally {
msgRecorder.popContextName();
}
}
Implementations must provide the means for extracting the error/warning messages.
Code that is processing should not catch the MessageRecorder.RTException. This Exception is thrown by the MessageRecorder when too many errors have been seen. Throwing this Exception is the mechanism used to stop processing and return to the initiating code. The initiating code should expect to catch the MessageRecorder.RTException Exception.
void initiatingCode(MessageRecorder msgRecorder) {
// get MessageRecorder implementation
MessageRecorder msgRecorder = ....
try {
processingCode(msgRecorder);
} catch (MessageRecorder.RTException mrex) {
// empty
}
if (msgRecorder.hasErrors()) {
// handle errors
} else if (msgRecorder.hasWarnings()) {
// handle warnings
}
}
The reporting methods all have variations that take an "info" Object. This can be used to pass something, beyond a text message, from the point of warning/error to the initiating code.
Concerning logging, it is a rule that a message, if logged by the code creating the MessageRecorder implementation, is logged at is reporting level, errors are logged at the error log level, warnings at the warning level and info at the info level. This allows the client code to "know" what log level their messages might appear at.
Method Summary | |
---|---|
void |
clear()
Clear all context, warnings and errors from the MessageRecorder. |
String |
getContext()
Get the current context string. |
long |
getRunTimeMillis()
How long the MessageRecorder has been running since it was created or the last time clear was called. |
long |
getStartTimeMillis()
Get the time when the MessageRecorder was created or the last time that the clear method was called. |
boolean |
hasErrors()
Returns true if there are one or more error messages. |
boolean |
hasInformation()
Returns true if there are one or more informational messages. |
boolean |
hasWarnings()
Returns true if there are one or more warning messages. |
void |
popContextName()
Remove the last context name added. |
void |
pushContextName(String name)
Add the name parameter to the current context. |
void |
reportError(Exception ex)
Add an Exception. |
void |
reportError(Exception ex,
Object info)
Add an Exception and extra informaton. |
void |
reportError(String msg)
Add an error message. |
void |
reportError(String msg,
Object info)
Add an error message and extra information. |
void |
reportInfo(String msg)
Add an informational message. |
void |
reportInfo(String msg,
Object info)
Add an informational message and extra information. |
void |
reportWarning(String msg)
Add a warning message. |
void |
reportWarning(String msg,
Object info)
Add a warning message and extra information. |
void |
throwRTException()
This simply throws a RTException. |
Method Detail |
---|
void clear()
long getStartTimeMillis()
long getRunTimeMillis()
boolean hasInformation()
boolean hasWarnings()
boolean hasErrors()
String getContext()
void pushContextName(String name)
name
- void popContextName()
void throwRTException() throws RecorderException
RecorderException
void reportError(Exception ex) throws RecorderException
RecorderException
- if too many error messages have been added.ex
- the Exception added.void reportError(Exception ex, Object info) throws RecorderException
RecorderException
- if too many error messages have been added.ex
- the Exception added.info
- extra information (not meant to be part of printed message)void reportError(String msg) throws RecorderException
RecorderException
- if too many error messages have been added.msg
- the text of the error message.void reportError(String msg, Object info) throws RecorderException
RecorderException
- if too many error messages have been added.msg
- the text of the error message.info
- extra information (not meant to be part of printed message)void reportWarning(String msg)
msg
- the text of the warning message.void reportWarning(String msg, Object info)
msg
- the text of the warning message.info
- extra information (not meant to be part of printed message)void reportInfo(String msg)
msg
- the text of the info message.void reportInfo(String msg, Object info)
msg
- the text of the info message.info
- extra information (not meant to be part of printed message)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |