org.javasimon.callback.logging
Class PeriodicLogTemplate<C>

java.lang.Object
  extended by org.javasimon.callback.logging.LogTemplate<C>
      extended by org.javasimon.callback.logging.DelegateLogTemplate<C>
          extended by org.javasimon.callback.logging.PeriodicLogTemplate<C>

public class PeriodicLogTemplate<C>
extends DelegateLogTemplate<C>

Log template that logs something after every N milliseconds. The isEnabled(Object) is only true after N milliseconds from the last log.

Author:
gquintana

Field Summary
private  long nextTime
          Timestamp of next invocation.
private  long period
          Maximum time between two calls to log method.
 
Constructor Summary
PeriodicLogTemplate(LogTemplate delegate, long period)
          Constructor with other template and the required period in ms.
 
Method Summary
private  long getCurrentTime()
          Get current timestamp.
 long getNextTime()
          Get next invocation time time.
private  void initNextTime()
          Computes the next timestamp.
 boolean isEnabled(C context)
          Tell whether logging is enabled.
 boolean isNextTimePassed()
          Indicates whether next timestamp is in past.
 void log(String message)
          Log a message.
 
Methods inherited from class org.javasimon.callback.logging.DelegateLogTemplate
getDelegate
 
Methods inherited from class org.javasimon.callback.logging.LogTemplate
log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

period

private final long period
Maximum time between two calls to log method.


nextTime

private long nextTime
Timestamp of next invocation.

Constructor Detail

PeriodicLogTemplate

public PeriodicLogTemplate(LogTemplate delegate,
                           long period)
Constructor with other template and the required period in ms.

Parameters:
delegate - concrete log template
period - logging period in milliseconds
Method Detail

getNextTime

public long getNextTime()
Get next invocation time time.

Returns:
next time

getCurrentTime

private long getCurrentTime()
Get current timestamp.

Returns:
current timestamp

initNextTime

private void initNextTime()
Computes the next timestamp.


isNextTimePassed

public boolean isNextTimePassed()
Indicates whether next timestamp is in past.


isEnabled

public boolean isEnabled(C context)
Tell whether logging is enabled.

Overrides:
isEnabled in class DelegateLogTemplate<C>
Returns:
true if delegate is true and enough time passed since last log

log

public void log(String message)
Log a message. Next time is updated after delegate log is called.

Overrides:
log in class DelegateLogTemplate<C>


Copyright © 2013. All Rights Reserved.