Class StatusReport

  • All Implemented Interfaces:
    TimerTaskListener

    public final class StatusReport
    extends 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 default java.util.logging.Logger is the application's root log. The default logging level is java.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
    • 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:
        handleTimeout in interface TimerTaskListener
        Parameters:
        event - the expired timer event.
      • getLogger

        public Logger getLogger()
        Returns the java.util.logging.Logger to which the status report is written.
        Returns:
        the java.util.logging.Logger to which the status report is written.
      • getLevel

        public Level getLevel()
        Returns the java.util.logging.Level at which the status report is logged.
        Returns:
        the java.util.logging.Level at 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 is true, then the active threds are listed in the report. This flag is false by default.
        Returns:
        the "dump threads" flag.
      • setLogger

        public void setLogger​(Logger logger)
        Sets the java.util.logging.Logger. The status report is written to this logger.
        Parameters:
        logger - write the status report to this log.
      • setLevel

        public void setLevel​(Level level)
        Sets the java.util.logging.Level at which the status report is logged.
        Parameters:
        level - log the status report at this level.
        Throws:
        NullPointerException - if level is null.
      • 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 an java.lang.IllegalArgumentException is 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 is true, then the active threads are listed in the report.
        Parameters:
        flag - set the "dump threads" flag to this value.
      • setApplicationInfo

        public void setApplicationInfo​(String name,
                                       String version,
                                       Date buildDate,
                                       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:
        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.
      • formatTime

        public static 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.