long startTimeNs = -1;
if(logger.isDebugEnabled()) {
startTimeMs = System.currentTimeMillis();
}
ClientRequestExecutor clientRequestExecutor = pool.checkout(destination);
String debugMsgStr = "";
startTimeNs = System.nanoTime();
BlockingClientRequest<T> blockingClientRequest = null;
try {
blockingClientRequest = new BlockingClientRequest<T>(delegate, timeoutMs);
clientRequestExecutor.addClientRequest(blockingClientRequest,
timeoutMs,
System.nanoTime() - startTimeNs);
boolean awaitResult = blockingClientRequest.await();
if(awaitResult == false) {
blockingClientRequest.timeOut();
}
if(logger.isDebugEnabled())
debugMsgStr += "success";
return blockingClientRequest.getResult();
} catch(InterruptedException e) {
if(logger.isDebugEnabled())
debugMsgStr += "unreachable: " + e.getMessage();
throw new UnreachableStoreException("Failure in " + operationName + " on "
+ destination + ": " + e.getMessage(), e);
} catch(IOException e) {
clientRequestExecutor.close();
if(logger.isDebugEnabled())
debugMsgStr += "failure: " + e.getMessage();
throw new UnreachableStoreException("Failure in " + operationName + " on "
+ destination + ": " + e.getMessage(), e);
} finally {
if(blockingClientRequest != null && !blockingClientRequest.isComplete()) {
// close the executor if we timed out
clientRequestExecutor.close();
}
// Record operation time
long opTimeNs = Utils.elapsedTimeNs(startTimeNs, System.nanoTime());
if (stats != null) {
stats.recordSyncOpTimeNs(destination, opTimeNs);
}
if(logger.isDebugEnabled()) {
logger.debug("Sync request end, type: "
+ operationName
+ " requestRef: "
+ System.identityHashCode(delegate)
+ " totalTimeNs: "
+ opTimeNs
+ " start time: "
+ startTimeMs
+ " end time: "
+ System.currentTimeMillis()
+ " client:"
+ clientRequestExecutor.getSocketChannel().socket().getLocalAddress()
+ ":"
+ clientRequestExecutor.getSocketChannel().socket().getLocalPort()
+ " server: "
+ clientRequestExecutor.getSocketChannel()
.socket()
.getRemoteSocketAddress() + " outcome: "
+ debugMsgStr);
}