use of com.aerospike.client.command.BatchNode in project aerospike-client-java by aerospike.
the class AerospikeClient method get.
// -------------------------------------------------------
// Batch Read Operations
// -------------------------------------------------------
/**
* Read multiple records for specified batch keys in one batch call.
* This method allows different namespaces/bins to be requested for each key in the batch.
* The returned records are located in the same list.
* If the BatchRead key field is not found, the corresponding record field will be null.
* <p>
* If a batch request to a node fails, the entire batch is cancelled.
*
* @param policy batch configuration parameters, pass in null for defaults
* @param records list of unique record identifiers and the bins to retrieve.
* The returned records are located in the same list.
* @throws AerospikeException if read fails
*/
public final void get(BatchPolicy policy, List<BatchRead> records) throws AerospikeException {
if (records.size() == 0) {
return;
}
if (policy == null) {
policy = batchPolicyDefault;
}
List<BatchNode> batchNodes = BatchNodeList.generate(cluster, policy, records);
if (policy.maxConcurrentThreads == 1 || batchNodes.size() <= 1) {
// Run batch requests sequentially in same thread.
for (BatchNode batchNode : batchNodes) {
MultiCommand command = new Batch.ReadListCommand(cluster, null, batchNode, policy, records);
command.execute();
}
} else {
// Run batch requests in parallel in separate threads.
//
// Multiple threads write to the record list, so one might think that
// volatile or memory barriers are needed on the write threads and this read thread.
// This should not be necessary here because it happens in Executor which does a
// volatile write (completedCount.incrementAndGet()) at the end of write threads
// and a synchronized waitTillComplete() in this thread.
Executor executor = new Executor(cluster, batchNodes.size());
for (BatchNode batchNode : batchNodes) {
MultiCommand command = new Batch.ReadListCommand(cluster, executor, batchNode, policy, records);
executor.addCommand(command);
}
executor.execute(policy.maxConcurrentThreads);
}
}
Aggregations