int failedConns = 0;
int iterations = 0;
// Execute command until successful, timed out or maximum iterations have been reached.
while (true) {
Node node = null;
try {
node = getNode();
Connection conn = node.getConnection(remainingMillis);
try {
// Set command buffer.
writeBuffer();
// Reset timeout in send buffer (destined for server) and socket.
Buffer.intToBytes(remainingMillis, dataBuffer, 22);
// Send command.
conn.write(dataBuffer, dataOffset);
// Parse results.
parseResult(conn);
// Reflect healthy status.
conn.updateLastUsed();
node.restoreHealth();
// Put connection back in pool.
node.putConnection(conn);
// Command has completed successfully. Exit method.
return;
}
catch (AerospikeException ae) {
// Close socket to flush out possible garbage. Do not put back in pool.
conn.close();
throw ae;
}
catch (RuntimeException re) {
// All runtime exceptions are considered fatal. Do not retry.
// Close socket to flush out possible garbage. Do not put back in pool.
conn.close();
throw re;
}
catch (IOException ioe) {
// IO errors are considered temporary anomalies. Retry.
// Close socket to flush out possible garbage. Do not put back in pool.
conn.close();
if (Log.debugEnabled()) {
Log.debug("Node " + node + ": " + Util.getErrorMessage(ioe));
}
// IO error means connection to server node is unhealthy.
// Reflect this status.
node.decreaseHealth();
}
}
catch (AerospikeException.InvalidNode ine) {
// Node is currently inactive. Retry.
failedNodes++;
}
catch (AerospikeException.Connection ce) {
// Socket connection error has occurred. Decrease health and retry.
node.decreaseHealth();
if (Log.debugEnabled()) {
Log.debug("Node " + node + ": " + Util.getErrorMessage(ce));
}
failedConns++;