public class TimeMeasure extends Object
TimeMeasuremeasure = newTimeMeasure(); try { doSomething(); measure.succeed(); } finally { measure.log(getLogger(), "Something"); }
| Modifier and Type | Class and Description |
|---|---|
private static class |
TimeMeasure.Result
The state of the completion.
|
| Modifier and Type | Field and Description |
|---|---|
private long |
duration
The end time.
|
private TimeMeasure.Result |
result
The
TimeMeasure.Result if duration time has been set and measure is completed or null if still in
progress. |
private long |
start
The start time.
|
| Constructor and Description |
|---|
TimeMeasure()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
complete(TimeMeasure.Result finalResult) |
void |
fail()
This method is to be called once after the operation(s) to measure failed (e.g.
|
void |
failIfNotSucceeded()
|
String |
getDurationAsString() |
long |
getDurationInNanos() |
boolean |
isCompleted() |
boolean |
isFailure() |
boolean |
isSuccess() |
void |
log(org.slf4j.Logger logger,
Object operation)
Calls
failIfNotSucceeded() and the logs the status and duration of this
measure. |
private void |
requireCompleted()
Throws an
IllegalStateException if not completed. |
void |
succeed()
This method is to be called once after the operation(s) to measure has successfully completed.
|
private final long start
private long duration
private TimeMeasure.Result result
TimeMeasure.Result if duration time has been set and measure is completed or null if still in
progress.public void succeed()
public void fail()
public void failIfNotSucceeded()
public boolean isFailure()
true if failed, false otherwise.public boolean isSuccess()
true if succeeded, false otherwise.public boolean isCompleted()
true if completed (isSuccess() or isFailure()), false otherwise.public void log(org.slf4j.Logger logger,
Object operation)
failIfNotSucceeded() and the logs the status and duration of this
measure.logger - is the Logger.operation - represents the operation that was measured. Typically a String. Its
string representation is logged and shall be a brief description of the measured
operation.public long getDurationInNanos()
throws IllegalStateException
IllegalStateException - if not completed.public String getDurationAsString() throws IllegalStateException
IllegalStateException - if not completed.private void requireCompleted()
IllegalStateException if not completed.private void complete(TimeMeasure.Result finalResult)
finalResult - is the TimeMeasure.Result to set together with the current end time.Copyright © 2001–2016 mmm-Team. All rights reserved.