statement.taskId = r.nextInt(Integer.MAX_VALUE);
}
Node[] nodes = cluster.getNodes();
if (nodes.length == 0) {
throw new AerospikeException(ResultCode.SERVER_NOT_AVAILABLE, "Command failed because cluster is empty.");
}
threads = new ServerThread[nodes.length];
for (int i = 0; i < nodes.length; i++) {
ServerCommand command = new ServerCommand(nodes[i], policy, statement);
threads[i] = new ServerThread(command);
}
ExecutorService threadPool = cluster.getThreadPool();
for (int i = 0; i < nodes.length; i++) {
threadPool.execute(threads[i]);
}
waitTillComplete();
// Throw an exception if an error occurred.
if (exception != null) {
if (exception instanceof AerospikeException) {
throw (AerospikeException)exception;
}
else {
throw new AerospikeException(exception);
}
}
}