use of com.twitter.common.stats.StatsProvider.RequestTimer in project commons by twitter.
the class StatTrackingCaller method call.
@Override
public Object call(Method method, Object[] args, @Nullable AsyncMethodCallback callback, @Nullable Amount<Long, Time> connectTimeoutOverride) throws Throwable {
final RequestTimer requestStats = stats.get(method);
final long startTime = System.nanoTime();
ResultCapture capture = new ResultCapture() {
@Override
public void success() {
requestStats.requestComplete(TimeUnit.NANOSECONDS.toMicros(System.nanoTime() - startTime));
}
@Override
public boolean fail(Throwable t) {
// backoff mechanism - consider how to plumb something similar.
if (t instanceof TTimeoutException || t instanceof TimeoutException) {
requestStats.incTimeouts();
return true;
}
// it stands.
if (!(t instanceof TResourceExhaustedException)) {
requestStats.incReconnects();
}
// TODO(John Sirois): provide more detailed stats: track counts for distinct exceptions types,
// track retries-per-method, etc...
requestStats.incErrors();
return true;
}
};
return invoke(method, args, callback, capture, connectTimeoutOverride);
}
Aggregations