Package net.sf.eBus.util.logging
Class StatusReport
- java.lang.Object
-
- net.sf.eBus.util.logging.StatusReport
-
- All Implemented Interfaces:
TimerTaskListener
public final class StatusReport extends java.lang.Object implements TimerTaskListener
Writes a status report to a log at a specified interval. The default interval is every 15 minutes on the quarter hour. The defaultjava.util.logging.Loggeris the application's root log. The default logging level isjava.util.logging.Level.INFO.When the timer expires it generates a report containing:
- The application name, version and build date.
- The JVM's statistics: version and memory usage.
-
Each registered
StatusReporter's statistics.
- Author:
- Charles Rapp
- See Also:
StatusReporter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStatusReport.ReportFrequencyEnumerates the allowed status report frequencies: FIVE_MINUTE: generate a report every five minutes on the five minute.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidderegister(StatusReporter reporter)Deregisters a status reporter.static java.lang.StringformatTime(long delta)Given a millisecond duration, generate a string that reports the duration in human-readable form.booleangetDumpThreads()Returns the "dump threads" flag.java.util.logging.LevelgetLevel()Returns thejava.util.logging.Levelat which the status report is logged.java.util.logging.LoggergetLogger()Returns thejava.util.logging.Loggerto which the status report is written.StatusReport.ReportFrequencygetReportFrequency()Returns the current status report frequency in milliseconds.static StatusReportgetsInstance()Returns the singletonStatusReportinstance.voidhandleTimeout(TimerEvent event)Time to output another status report.voidregister(StatusReporter reporter)Registers a status reporter.voidsetApplicationInfo(java.lang.String name, java.lang.String version, java.util.Date buildDate, java.lang.String boilerPlate)Sets the application's name, version and build date.voidsetDumpThreads(boolean flag)Sets the "dump threads" flag to the given value.voidsetLevel(java.util.logging.Level level)Sets thejava.util.logging.Levelat which the status report is logged.voidsetLogger(java.util.logging.Logger logger)Sets thejava.util.logging.Logger.voidsetReportFrequency(StatusReport.ReportFrequency frequency)Sets the status report frequency.
-
-
-
Method Detail
-
handleTimeout
public void handleTimeout(TimerEvent event)
Time to output another status report.DO NOT CALL THIS METHOD! This method is called when the report timer expires.
- Specified by:
handleTimeoutin interfaceTimerTaskListener- Parameters:
event- the expired timer event.
-
getLogger
public java.util.logging.Logger getLogger()
Returns thejava.util.logging.Loggerto which the status report is written.- Returns:
- the
java.util.logging.Loggerto which the status report is written.
-
getLevel
public java.util.logging.Level getLevel()
Returns thejava.util.logging.Levelat which the status report is logged.- Returns:
- the
java.util.logging.Levelat which the status report is logged.
-
getReportFrequency
public StatusReport.ReportFrequency getReportFrequency()
Returns the current status report frequency in milliseconds.- Returns:
- the current status report frequency in milliseconds.
-
getDumpThreads
public boolean getDumpThreads()
Returns the "dump threads" flag. If this flag istrue, then the active threds are listed in the report. This flag isfalseby default.- Returns:
- the "dump threads" flag.
-
setLogger
public void setLogger(java.util.logging.Logger logger)
Sets thejava.util.logging.Logger. The status report is written to this logger.- Parameters:
logger- write the status report to this log.
-
setLevel
public void setLevel(java.util.logging.Level level)
Sets thejava.util.logging.Levelat which the status report is logged.- Parameters:
level- log the status report at this level.- Throws:
java.lang.NullPointerException- iflevelisnull.
-
setReportFrequency
public void setReportFrequency(StatusReport.ReportFrequency frequency)
Sets the status report frequency. The allowed frequencies are: 5 minute, 10 minute, 15 minute, 20 minute, 30 minute and hourly. The default is 15 minute. If the frequency is none of the above, then anjava.lang.IllegalArgumentExceptionis thrown.- Parameters:
frequency- the status report frequency.
-
setDumpThreads
public void setDumpThreads(boolean flag)
Sets the "dump threads" flag to the given value. If this flag istrue, then the active threads are listed in the report.- Parameters:
flag- set the "dump threads" flag to this value.
-
setApplicationInfo
public void setApplicationInfo(java.lang.String name, java.lang.String version, java.util.Date buildDate, java.lang.String boilerPlate)Sets the application's name, version and build date. This information is placed at the start of each status report log message.- Parameters:
name- the application's name.version- the application's version.buildDate- the application's build date.boilerPlate- usually a copyright statement.- Throws:
java.lang.IllegalStateException- if the application information is already set.
-
register
public void register(StatusReporter reporter)
Registers a status reporter. If the reporter is already registered, then it is not added again.Note: When the status report is generated, reporters will be called in the order they register.
- Parameters:
reporter- register this status reporter.
-
deregister
public void deregister(StatusReporter reporter)
Deregisters a status reporter. If the reporter is not registered, then nothing is done.- Parameters:
reporter- deregister this reporter.
-
getsInstance
public static StatusReport getsInstance()
Returns the singletonStatusReportinstance.- Returns:
- the singleton
StatusReportinstance.
-
formatTime
public static java.lang.String formatTime(long delta)
Given a millisecond duration, generate a string that reports the duration in human-readable form.- Parameters:
delta- The millisecond duration.- Returns:
- the textual representation of a duration.
-
-