org.perf4j
Class TimedCallable<V>

java.lang.Object
  extended by org.perf4j.TimedCallable<V>
All Implemented Interfaces:
Serializable, Callable<V>

public class TimedCallable<V>
extends Object
implements Callable<V>, Serializable

This helper wrapper class can be used to add timing statements to an existing Callable instance, logging how long it takes for the call method to execute. Note that instances of this class are only serializable if the wrapped Callable is serializable.

Author:
Alex Devine
See Also:
Serialized Form

Constructor Summary
TimedCallable(Callable<V> task, LoggingStopWatch stopWatch)
          Wraps the existing Callable in order to time its call method.
 
Method Summary
 V call()
          Executes the call method of the underlying task, using the LoggingStopWatch to track the execution time.
 LoggingStopWatch getStopWatch()
          Gets the LoggingStopWatch that will be used to time the call method execution.
 Callable<V> getWrappedTask()
          Gets the Callable task that is wrapped by this TimedCallable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimedCallable

public TimedCallable(Callable<V> task,
                     LoggingStopWatch stopWatch)
Wraps the existing Callable in order to time its call method.

Parameters:
task - The existing Callable whose call method is to be timed and executed. May not be null.
stopWatch - The LoggingStopWatch to use to time the call method execution. Note that this stop watch should already have its tag and message set to what should be logged when the task is run. May not be null.
Method Detail

getWrappedTask

public Callable<V> getWrappedTask()
Gets the Callable task that is wrapped by this TimedCallable.

Returns:
The wrapped Callable whose execution time is to be logged.

getStopWatch

public LoggingStopWatch getStopWatch()
Gets the LoggingStopWatch that will be used to time the call method execution.

Returns:
The LoggingStopWatch to use to log execution time.

call

public V call()
       throws Exception
Executes the call method of the underlying task, using the LoggingStopWatch to track the execution time.

Specified by:
call in interface Callable<V>
Throws:
Exception


Copyright © 2008-2009 perf4j.org. All Rights Reserved.