public interface Timer extends Meter
The precise set of information maintained by the timer depends on the implementation. Most
should try to provide a consistent implementation of count()
and totalTime()
,
but some implementations may not. In particular, the implementation from NoopRegistry
will always return 0.
Modifier and Type | Interface and Description |
---|---|
static interface |
Timer.BatchUpdater
See
batchUpdater(int) . |
Modifier and Type | Method and Description |
---|---|
default Timer.BatchUpdater |
batchUpdater(int batchSize)
Returns a helper that can be used to more efficiently update the timer within a
single thread.
|
default Clock |
clock()
The clock used for timing events.
|
long |
count()
The number of times that record has been called since this timer was last reset.
|
default <T> T |
record(Callable<T> f)
Deprecated.
Use
recordCallable(Callable) instead. |
default void |
record(Duration amount)
Updates the statistics kept by the timer with the specified amount.
|
default void |
record(Duration[] amounts,
int n)
Updates the statistics kept by the timer with the specified amounts.
|
default void |
record(long[] amounts,
int n,
TimeUnit unit)
Updates the statistics kept by the timer with the specified amounts.
|
void |
record(long amount,
TimeUnit unit)
Updates the statistics kept by the timer with the specified amount.
|
default void |
record(Runnable f)
Deprecated.
Use
recordRunnable(Runnable) instead. |
default boolean |
recordBooleanSupplier(BooleanSupplier f)
Executes the supplier `f` and records the time taken.
|
default <T> T |
recordCallable(Callable<T> f)
Executes the callable `f` and records the time taken.
|
default double |
recordDoubleSupplier(DoubleSupplier f)
Executes the supplier `f` and records the time taken.
|
default int |
recordIntSupplier(IntSupplier f)
Executes the supplier `f` and records the time taken.
|
default long |
recordLongSupplier(LongSupplier f)
Executes the supplier `f` and records the time taken.
|
default void |
recordRunnable(Runnable f)
Executes the runnable `f` and records the time taken.
|
default <T> T |
recordSupplier(Supplier<T> f)
Executes the supplier `f` and records the time taken.
|
long |
totalTime()
The total time in nanoseconds of all recorded events since this timer was last reset.
|
default <T,U> BiConsumer<T,U> |
wrapBiConsumer(BiConsumer<T,U> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T,U,R> BiFunction<T,U,R> |
wrapBiFunction(BiFunction<T,U,R> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> BinaryOperator<T> |
wrapBinaryOperator(BinaryOperator<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T,U> BiPredicate<T,U> |
wrapBiPredicate(BiPredicate<T,U> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default BooleanSupplier |
wrapBooleanSupplier(BooleanSupplier f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <V> Callable<V> |
wrapCallable(Callable<V> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> Consumer<T> |
wrapConsumer(Consumer<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default DoubleBinaryOperator |
wrapDoubleBinaryOperator(DoubleBinaryOperator f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default DoubleConsumer |
wrapDoubleConsumer(DoubleConsumer f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <R> DoubleFunction<R> |
wrapDoubleFunction(DoubleFunction<R> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default DoublePredicate |
wrapDoublePredicate(DoublePredicate f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default DoubleSupplier |
wrapDoubleSupplier(DoubleSupplier f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default DoubleToIntFunction |
wrapDoubleToIntFunction(DoubleToIntFunction f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default DoubleToLongFunction |
wrapDoubleToLongFunction(DoubleToLongFunction f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default DoubleUnaryOperator |
wrapDoubleUnaryOperator(DoubleUnaryOperator f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T,R> Function<T,R> |
wrapFunction(Function<T,R> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default IntBinaryOperator |
wrapIntBinaryOperator(IntBinaryOperator f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default IntConsumer |
wrapIntConsumer(IntConsumer f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <R> IntFunction<R> |
wrapIntFunction(IntFunction<R> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default IntPredicate |
wrapIntPredicate(IntPredicate f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default IntSupplier |
wrapIntSupplier(IntSupplier f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default IntToDoubleFunction |
wrapIntToDoubleFunction(IntToDoubleFunction f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default IntToLongFunction |
wrapIntToLongFunction(IntToLongFunction f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default IntUnaryOperator |
wrapIntUnaryOperator(IntUnaryOperator f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default LongBinaryOperator |
wrapLongBinaryOperator(LongBinaryOperator f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default LongConsumer |
wrapLongConsumer(LongConsumer f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <R> LongFunction<R> |
wrapLongFunction(LongFunction<R> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default LongPredicate |
wrapLongPredicate(LongPredicate f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default LongSupplier |
wrapLongSupplier(LongSupplier f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default LongToDoubleFunction |
wrapLongToDoubleFunction(LongToDoubleFunction f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default LongToIntFunction |
wrapLongToIntFunction(LongToIntFunction f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default LongUnaryOperator |
wrapLongUnaryOperator(LongUnaryOperator f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> ObjDoubleConsumer<T> |
wrapObjDoubleConsumer(ObjDoubleConsumer<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> ObjIntConsumer<T> |
wrapObjIntConsumer(ObjIntConsumer<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> ObjLongConsumer<T> |
wrapObjLongConsumer(ObjLongConsumer<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> Predicate<T> |
wrapPredicate(Predicate<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default Runnable |
wrapRunnable(Runnable f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> Supplier<T> |
wrapSupplier(Supplier<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T,U> ToDoubleBiFunction<T,U> |
wrapToDoubleBiFunction(ToDoubleBiFunction<T,U> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> ToDoubleFunction<T> |
wrapToDoubleFunction(ToDoubleFunction<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T,U> ToIntBiFunction<T,U> |
wrapToIntBiFunction(ToIntBiFunction<T,U> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> ToIntFunction<T> |
wrapToIntFunction(ToIntFunction<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T,U> ToLongBiFunction<T,U> |
wrapToLongBiFunction(ToLongBiFunction<T,U> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> ToLongFunction<T> |
wrapToLongFunction(ToLongFunction<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
default <T> UnaryOperator<T> |
wrapUnaryOperator(UnaryOperator<T> f)
Wraps the lambda `f` to update this timer each time the wrapper is invoked.
|
hasExpired, id, measure
default Clock clock()
void record(long amount, TimeUnit unit)
amount
- Duration of a single event being measured by this timer. If the amount is less than 0
the value will be dropped.unit
- Time unit for the amount being recorded.default void record(Duration amount)
amount
- Duration of a single event being measured by this timer.default void record(long[] amounts, int n, TimeUnit unit)
amounts
- Duration of events being measured by this timer. If the amount is less than 0
for a value, the value will be dropped.n
- The number of elements to write from the amounts array (starting from 0). If n is
<= 0 no entries will be recorded. If n is greater than amounts.length, all amounts
will be recorded.unit
- Time unit for the amounts being recorded.record(long, TimeUnit)
default void record(Duration[] amounts, int n)
amounts
- Duration of events being measured by this timer. If the amount is less than 0
for a value, the value will be dropped.n
- The number of elements to write from the amounts array (starting from 0). If n is
<= 0 no entries will be recorded. If n is greater than amounts.length, all amounts
will be recorded.record(Duration)
@Deprecated default <T> T record(Callable<T> f) throws Exception
recordCallable(Callable)
instead.f
- Function to execute and measure the execution time.Exception
@Deprecated default void record(Runnable f)
recordRunnable(Runnable)
instead.f
- Function to execute and measure the execution time.default <T> T recordCallable(Callable<T> f) throws Exception
f
- Function to execute and measure the execution time.Exception
default void recordRunnable(Runnable f)
f
- Function to execute and measure the execution time.default <T> T recordSupplier(Supplier<T> f)
f
- Function to execute and measure the execution time.default boolean recordBooleanSupplier(BooleanSupplier f)
f
- Function to execute and measure the execution time.default double recordDoubleSupplier(DoubleSupplier f)
f
- Function to execute and measure the execution time.default int recordIntSupplier(IntSupplier f)
f
- Function to execute and measure the execution time.default long recordLongSupplier(LongSupplier f)
f
- Function to execute and measure the execution time.default <V> Callable<V> wrapCallable(Callable<V> f)
f
- Function to execute and measure the execution time.default Runnable wrapRunnable(Runnable f)
f
- Function to execute and measure the execution time.default <T,U> BiConsumer<T,U> wrapBiConsumer(BiConsumer<T,U> f)
f
- Function to execute and measure the execution time.default <T,U,R> BiFunction<T,U,R> wrapBiFunction(BiFunction<T,U,R> f)
f
- Function to execute and measure the execution time.default <T> BinaryOperator<T> wrapBinaryOperator(BinaryOperator<T> f)
f
- Function to execute and measure the execution time.default <T,U> BiPredicate<T,U> wrapBiPredicate(BiPredicate<T,U> f)
f
- Function to execute and measure the execution time.default BooleanSupplier wrapBooleanSupplier(BooleanSupplier f)
f
- Function to execute and measure the execution time.default <T> Consumer<T> wrapConsumer(Consumer<T> f)
f
- Function to execute and measure the execution time.default DoubleBinaryOperator wrapDoubleBinaryOperator(DoubleBinaryOperator f)
f
- Function to execute and measure the execution time.default DoubleConsumer wrapDoubleConsumer(DoubleConsumer f)
f
- Function to execute and measure the execution time.default <R> DoubleFunction<R> wrapDoubleFunction(DoubleFunction<R> f)
f
- Function to execute and measure the execution time.default DoublePredicate wrapDoublePredicate(DoublePredicate f)
f
- Function to execute and measure the execution time.default DoubleSupplier wrapDoubleSupplier(DoubleSupplier f)
f
- Function to execute and measure the execution time.default DoubleToIntFunction wrapDoubleToIntFunction(DoubleToIntFunction f)
f
- Function to execute and measure the execution time.default DoubleToLongFunction wrapDoubleToLongFunction(DoubleToLongFunction f)
f
- Function to execute and measure the execution time.default DoubleUnaryOperator wrapDoubleUnaryOperator(DoubleUnaryOperator f)
f
- Function to execute and measure the execution time.default <T,R> Function<T,R> wrapFunction(Function<T,R> f)
f
- Function to execute and measure the execution time.default IntBinaryOperator wrapIntBinaryOperator(IntBinaryOperator f)
f
- Function to execute and measure the execution time.default IntConsumer wrapIntConsumer(IntConsumer f)
f
- Function to execute and measure the execution time.default <R> IntFunction<R> wrapIntFunction(IntFunction<R> f)
f
- Function to execute and measure the execution time.default IntPredicate wrapIntPredicate(IntPredicate f)
f
- Function to execute and measure the execution time.default IntSupplier wrapIntSupplier(IntSupplier f)
f
- Function to execute and measure the execution time.default IntToDoubleFunction wrapIntToDoubleFunction(IntToDoubleFunction f)
f
- Function to execute and measure the execution time.default IntToLongFunction wrapIntToLongFunction(IntToLongFunction f)
f
- Function to execute and measure the execution time.default IntUnaryOperator wrapIntUnaryOperator(IntUnaryOperator f)
f
- Function to execute and measure the execution time.default LongBinaryOperator wrapLongBinaryOperator(LongBinaryOperator f)
f
- Function to execute and measure the execution time.default LongConsumer wrapLongConsumer(LongConsumer f)
f
- Function to execute and measure the execution time.default <R> LongFunction<R> wrapLongFunction(LongFunction<R> f)
f
- Function to execute and measure the execution time.default LongPredicate wrapLongPredicate(LongPredicate f)
f
- Function to execute and measure the execution time.default LongSupplier wrapLongSupplier(LongSupplier f)
f
- Function to execute and measure the execution time.default LongToIntFunction wrapLongToIntFunction(LongToIntFunction f)
f
- Function to execute and measure the execution time.default LongToDoubleFunction wrapLongToDoubleFunction(LongToDoubleFunction f)
f
- Function to execute and measure the execution time.default LongUnaryOperator wrapLongUnaryOperator(LongUnaryOperator f)
f
- Function to execute and measure the execution time.default <T> ObjDoubleConsumer<T> wrapObjDoubleConsumer(ObjDoubleConsumer<T> f)
f
- Function to execute and measure the execution time.default <T> ObjIntConsumer<T> wrapObjIntConsumer(ObjIntConsumer<T> f)
f
- Function to execute and measure the execution time.default <T> ObjLongConsumer<T> wrapObjLongConsumer(ObjLongConsumer<T> f)
f
- Function to execute and measure the execution time.default <T> Predicate<T> wrapPredicate(Predicate<T> f)
f
- Function to execute and measure the execution time.default <T> Supplier<T> wrapSupplier(Supplier<T> f)
f
- Function to execute and measure the execution time.default <T,U> ToDoubleBiFunction<T,U> wrapToDoubleBiFunction(ToDoubleBiFunction<T,U> f)
f
- Function to execute and measure the execution time.default <T> ToDoubleFunction<T> wrapToDoubleFunction(ToDoubleFunction<T> f)
f
- Function to execute and measure the execution time.default <T,U> ToIntBiFunction<T,U> wrapToIntBiFunction(ToIntBiFunction<T,U> f)
f
- Function to execute and measure the execution time.default <T> ToIntFunction<T> wrapToIntFunction(ToIntFunction<T> f)
f
- Function to execute and measure the execution time.default <T,U> ToLongBiFunction<T,U> wrapToLongBiFunction(ToLongBiFunction<T,U> f)
f
- Function to execute and measure the execution time.default <T> ToLongFunction<T> wrapToLongFunction(ToLongFunction<T> f)
f
- Function to execute and measure the execution time.default <T> UnaryOperator<T> wrapUnaryOperator(UnaryOperator<T> f)
f
- Function to execute and measure the execution time.long count()
long totalTime()
default Timer.BatchUpdater batchUpdater(int batchSize)
The caller should ensure that the updater is closed after using to guarantee any resources associated with it are cleaned up. In some cases failure to close the updater could result in a memory leak.
batchSize
- Number of updates to batch before forcing a flush to the meter.