private <T, E extends Exception> T execute(Request request, ResponseHandler<T, E> responseHandler, AtomicReference<String> state)
throws E
{
state.set("PROCESSING_REQUEST");
Response response;
Duration requestProcessingTime = null;
try {
long requestStart = System.nanoTime();
response = processor.apply(request);
requestProcessingTime = Duration.nanosSince(requestStart);
}
catch (Throwable e) {
state.set("FAILED");
stats.record(request.getMethod(),
0,
0,
0,
requestProcessingTime,
null);
if (e instanceof Exception) {
return responseHandler.handleException(request, (Exception) e);
}
else {
throw e;
}
}
checkState(response != null, "response is null");
// notify handler
state.set("PROCESSING_RESPONSE");
long responseStart = System.nanoTime();
try {
return responseHandler.handle(request, response);
}
finally {
state.set("DONE");
Duration responseProcessingTime = Duration.nanosSince(responseStart);
stats.record(request.getMethod(),
response.getStatusCode(),
response.getBytesRead(),
response.getBytesRead(),
requestProcessingTime,