www.sdmetrics.com

com.sdmetrics.app
Class ConsoleMessageHandler

java.lang.Object
  extended by com.sdmetrics.app.MessageHandler
      extended by com.sdmetrics.app.ConsoleMessageHandler

public class ConsoleMessageHandler
extends MessageHandler

Message handler for console-based applications. Writes messages to print streams, by default "standard out" and "standard err".


Field Summary
protected  java.io.PrintStream err
          Print stream for error messages.
protected  java.io.PrintStream out
          Print stream for progress messages.
protected  boolean verbose
          Indicates if stack traces for exceptions should be shown.
 
Constructor Summary
ConsoleMessageHandler()
          Creates a new handler that writes to the "standard out" and "standard err" streams of the process.
ConsoleMessageHandler(java.io.PrintStream out)
          Creates a message handler writing all messages to a single stream.
ConsoleMessageHandler(java.io.PrintStream out, java.io.PrintStream err)
          Creates a message handler writing progress and error messages to separate streams.
 
Method Summary
static java.lang.String getErrorMessageText(java.util.List<Problem> problems, boolean verbose)
          Creates an error report for a list of problems.
 void message(java.lang.String s, int progress)
          Reports a calculation progress message.
 void reportError(java.util.List<Problem> problems)
          Reports a list of errors.
 void setVerbose(boolean verbose)
          Switch verbose output on or off.
 
Methods inherited from class com.sdmetrics.app.MessageHandler
finishedComputation, reportError, reportError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.PrintStream out
Print stream for progress messages.


err

protected java.io.PrintStream err
Print stream for error messages.


verbose

protected boolean verbose
Indicates if stack traces for exceptions should be shown.

Constructor Detail

ConsoleMessageHandler

public ConsoleMessageHandler()
Creates a new handler that writes to the "standard out" and "standard err" streams of the process.


ConsoleMessageHandler

public ConsoleMessageHandler(java.io.PrintStream out)
Creates a message handler writing all messages to a single stream.

Parameters:
out - The stream to write to.

ConsoleMessageHandler

public ConsoleMessageHandler(java.io.PrintStream out,
                             java.io.PrintStream err)
Creates a message handler writing progress and error messages to separate streams.

Parameters:
out - Stream for progress messages.
err - Stream for error messages.
Method Detail

setVerbose

public void setVerbose(boolean verbose)
Switch verbose output on or off. Verbose output shows stack traces of exceptions in problem reports.

Parameters:
verbose - true for verbose output

message

public void message(java.lang.String s,
                    int progress)
Description copied from class: MessageHandler
Reports a calculation progress message.

Specified by:
message in class MessageHandler
Parameters:
s - Describes the calculation currently being performed. If the string is null, the currently shown message remains the same, only the progress indicator is to be updated.
progress - Integer between 0 and 100 indicating the progress (100=finished). If progress is negative, the currently shown progress remains the same, only the message is to be updated.

reportError

public void reportError(java.util.List<Problem> problems)
Description copied from class: MessageHandler
Reports a list of errors. Recoverable errors need not be reported immediately, but can be collected and reported en bloc at the end of the operation.

Specified by:
reportError in class MessageHandler
Parameters:
problems - The list of problems to report.

getErrorMessageText

public static java.lang.String getErrorMessageText(java.util.List<Problem> problems,
                                                   boolean verbose)
Creates an error report for a list of problems.

Returns a string containing the error reported created by reportError(List).

Parameters:
problems - List of problems to report.
verbose - Set to true for verbose output with exception stack traces
Returns:
Error report for the list of problems

www.sdmetrics.com