org.apache.commons.monitoring.reporting
Class AbstractPeriodicLogger

java.lang.Object
  extended by java.util.TimerTask
      extended by org.apache.commons.monitoring.reporting.AbstractPeriodicLogger
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
HistorizedRepositoryDecorator, SelectorPeriodicLogger

public abstract class AbstractPeriodicLogger
extends java.util.TimerTask

An helper class to build a periodic task that logs the monitored application state for a period.

Typical use of this class is to implement the log method to format the indicators and append the result for each period in a log file.

Author:
Nicolas De Loof

Constructor Summary
AbstractPeriodicLogger(int period, java.util.Date firstTime, Repository.Observable repository)
          Create and start a PeriodicLogger to observe and log the repository data.
AbstractPeriodicLogger(int period, Repository.Observable repository)
           
 
Method Summary
protected  SecondaryRepository getRepositoryForActivePeriod()
           
protected  void handleError(java.lang.Throwable t)
          Warn when logging the repository failed.
protected abstract  void log(SecondaryRepository period)
          Log the data from the (secondary) repository generated during the period
 void run()
          
 void stop()
           
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPeriodicLogger

public AbstractPeriodicLogger(int period,
                              Repository.Observable repository)
Parameters:
period - the period (in ms) to log the monitoring state
repository - the observed repository

AbstractPeriodicLogger

public AbstractPeriodicLogger(int period,
                              java.util.Date firstTime,
                              Repository.Observable repository)
Create and start a PeriodicLogger to observe and log the repository data. If firstTime is null, the first time to log will be computed to log first at current date + period.

Parameters:
period - the period (in ms) to log the monitoring state
firstTime - the first time to log the observed repository (may be null)
repository - the observed repository
Method Detail

stop

public void stop()

run

public void run()

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask
See Also:
TimerTask.run()

handleError

protected void handleError(java.lang.Throwable t)
Warn when logging the repository failed.

This method is expected to be override by user to avoid System.err outputs and use the application logging strategy.

Parameters:
t - error during logging

log

protected abstract void log(SecondaryRepository period)
                     throws java.io.IOException
Log the data from the (secondary) repository generated during the period

Parameters:
period - secondary repository that observed the monitored state during the last active period
Throws:
java.io.IOException

getRepositoryForActivePeriod

protected SecondaryRepository getRepositoryForActivePeriod()
Returns:
the SecondaryRepository active for the current period.


Copyright © 2008 The Apache Software Foundation. All Rights Reserved.