net.spy.util
Class TTL

java.lang.Object
  extended by java.util.TimerTask
      extended by net.spy.util.TTL
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
DBTTL

public class TTL
extends java.util.TimerTask

A TTL object is used to express an intent for a process to finish within a certain amount of time.

A TTL object must be registered with a TTLMonitor before it will report. The default implementation of report logs via Logger.


Constructor Summary
TTL(long ttl)
          Get an instance of TTL.
TTL(long ttl, java.lang.Object extraInfo)
          Get an instance of TTL with the given ttl and extra object.
 
Method Summary
 void close()
          Calling this method states that we are no longer interested in the progress of this TTL.
protected  void doReport()
          Called when an object's TTL has expired without closing.
 java.lang.Object getExtraInfo()
          Get the extra info provided for the TTL report.
protected  Logger getLogger()
          Get the logger for this TTL.
protected  java.lang.String getMessageFromBundle(java.lang.String bundleName, java.lang.String msgNoArg, java.lang.String msgWithArg)
          Get the message format string from the named bundle.
 int getReportInterval()
          Get the report interval.
 long getTTL()
          Get the number of milliseconds this TTL object is expected to be in use.
 boolean hasReported()
          True if the TTL object has reported.
 boolean isClosed()
          Return true if this TTL is no longer interesting.
 boolean isExpired()
          Ask a TTL if it's expired.
protected  void reportWithFormat(java.lang.String msg)
          Report a TTL expiration with the given format.
 void reset()
          Resets the counter by setting the time that the TTL started to right now.
 void run()
          Request a report of the TTL.
 void setExtraInfo(java.lang.Object o)
          Provide extra information for the TTL report.
 void setMaxReports(int to)
          Set the maximum number of reports this TTL should issue before automatically closing.
 void setReportInterval(int ms)
          Set the minimum interval at which doReport() should be called when TTLMonitor sees this object as expired.
 java.lang.String toString()
          String me.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TTL

public TTL(long ttl)
Get an instance of TTL.

Parameters:
ttl - Number of milliseconds until the TTL fires

TTL

public TTL(long ttl,
           java.lang.Object extraInfo)
Get an instance of TTL with the given ttl and extra object.

Parameters:
ttl - Number of milliseconds until the TTL fires
extraInfo - Extra info that will be toString()ed in the log
Method Detail

getLogger

protected Logger getLogger()
Get the logger for this TTL.


reset

public void reset()
Resets the counter by setting the time that the TTL started to right now.


toString

public java.lang.String toString()
String me.

Overrides:
toString in class java.lang.Object

getTTL

public long getTTL()
Get the number of milliseconds this TTL object is expected to be in use.


setReportInterval

public void setReportInterval(int ms)
Set the minimum interval at which doReport() should be called when TTLMonitor sees this object as expired.


getReportInterval

public int getReportInterval()
Get the report interval.


setMaxReports

public void setMaxReports(int to)
Set the maximum number of reports this TTL should issue before automatically closing.


hasReported

public boolean hasReported()
True if the TTL object has reported.


setExtraInfo

public void setExtraInfo(java.lang.Object o)
Provide extra information for the TTL report.


getExtraInfo

public java.lang.Object getExtraInfo()
Get the extra info provided for the TTL report.


close

public void close()
Calling this method states that we are no longer interested in the progress of this TTL.


isClosed

public boolean isClosed()
Return true if this TTL is no longer interesting.


isExpired

public boolean isExpired()
Ask a TTL if it's expired.

Returns:
true if the TTL is expired

reportWithFormat

protected void reportWithFormat(java.lang.String msg)
Report a TTL expiration with the given format.

Parameters:
msg - message format string to print when the TTL expires

getMessageFromBundle

protected java.lang.String getMessageFromBundle(java.lang.String bundleName,
                                                java.lang.String msgNoArg,
                                                java.lang.String msgWithArg)
Get the message format string from the named bundle.

Parameters:
bundleName - the name of the bundle from which to get the messages
msgNoArg - the key in the bundle to use when there's no extra info
msgWithArg - the key in the bundle to use when there's extra info
Returns:
the format string

doReport

protected void doReport()
Called when an object's TTL has expired without closing.


run

public final void run()
Request a report of the TTL. This is called whenever the TTLMonitor owning this object notices the object's TTL has expired.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask


Copyright © 1995-2005 SPY Internetworking. All Rights Reserved.