use of com.aerospike.client.command.ScanCommand in project aerospike-client-java by aerospike.
the class AerospikeClient method scanNode.
/**
* Read all records in specified namespace and set for one node only.
* <p>
* This call will block until the scan is complete - callbacks are made
* within the scope of this call.
*
* @param policy scan configuration parameters, pass in null for defaults
* @param node server node
* @param namespace namespace - equivalent to database name
* @param setName optional set name - equivalent to database table
* @param callback read callback method - called with record data
* @param binNames optional bin to retrieve. All bins will be returned if not specified.
* Aerospike 2 servers ignore this parameter.
* @throws AerospikeException if transaction fails
*/
public final void scanNode(ScanPolicy policy, Node node, String namespace, String setName, ScanCallback callback, String... binNames) throws AerospikeException {
if (policy == null) {
policy = scanPolicyDefault;
}
if (policy.scanPercent <= 0 || policy.scanPercent > 100) {
throw new AerospikeException(ResultCode.PARAMETER_ERROR, "Invalid scan percent: " + policy.scanPercent);
}
long taskId = RandomShift.instance().nextLong();
ScanCommand command = new ScanCommand(policy, namespace, setName, callback, binNames, taskId);
command.execute(cluster, policy, null, node, true);
}
use of com.aerospike.client.command.ScanCommand in project aerospike-client-java by aerospike.
the class AerospikeClient method scanAll.
// -------------------------------------------------------
// Scan Operations
// -------------------------------------------------------
/**
* Read all records in specified namespace and set. If the policy's
* <code>concurrentNodes</code> is specified, each server node will be read in
* parallel. Otherwise, server nodes are read in series.
* <p>
* This call will block until the scan is complete - callbacks are made
* within the scope of this call.
*
* @param policy scan configuration parameters, pass in null for defaults
* @param namespace namespace - equivalent to database name
* @param setName optional set name - equivalent to database table
* @param callback read callback method - called with record data
* @param binNames optional bin to retrieve. All bins will be returned if not specified.
* Aerospike 2 servers ignore this parameter.
* @throws AerospikeException if scan fails
*/
public final void scanAll(ScanPolicy policy, String namespace, String setName, ScanCallback callback, String... binNames) throws AerospikeException {
if (policy == null) {
policy = scanPolicyDefault;
}
if (policy.scanPercent <= 0 || policy.scanPercent > 100) {
throw new AerospikeException(ResultCode.PARAMETER_ERROR, "Invalid scan percent: " + policy.scanPercent);
}
Node[] nodes = cluster.getNodes();
if (nodes.length == 0) {
throw new AerospikeException(ResultCode.SERVER_NOT_AVAILABLE, "Scan failed because cluster is empty.");
}
if (policy.concurrentNodes) {
Executor executor = new Executor(cluster, policy, nodes.length);
long taskId = RandomShift.instance().nextLong();
for (Node node : nodes) {
ScanCommand command = new ScanCommand(policy, namespace, setName, callback, binNames, taskId);
executor.addCommand(node, command);
}
executor.execute(policy.maxConcurrentNodes);
} else {
for (Node node : nodes) {
scanNode(policy, node, namespace, setName, callback, binNames);
}
}
}
Aggregations