Search in sources :

Example 1 with ScanCommand

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);
}
Also used : ScanCommand(com.aerospike.client.command.ScanCommand)

Example 2 with ScanCommand

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);
        }
    }
}
Also used : AsyncQueryExecutor(com.aerospike.client.async.AsyncQueryExecutor) BatchExecutor(com.aerospike.client.command.BatchExecutor) QueryRecordExecutor(com.aerospike.client.query.QueryRecordExecutor) QueryAggregateExecutor(com.aerospike.client.query.QueryAggregateExecutor) AsyncScanExecutor(com.aerospike.client.async.AsyncScanExecutor) Executor(com.aerospike.client.command.Executor) ScanCommand(com.aerospike.client.command.ScanCommand) Node(com.aerospike.client.cluster.Node) BatchNode(com.aerospike.client.command.BatchNode)

Aggregations

ScanCommand (com.aerospike.client.command.ScanCommand)2 AsyncQueryExecutor (com.aerospike.client.async.AsyncQueryExecutor)1 AsyncScanExecutor (com.aerospike.client.async.AsyncScanExecutor)1 Node (com.aerospike.client.cluster.Node)1 BatchExecutor (com.aerospike.client.command.BatchExecutor)1 BatchNode (com.aerospike.client.command.BatchNode)1 Executor (com.aerospike.client.command.Executor)1 QueryAggregateExecutor (com.aerospike.client.query.QueryAggregateExecutor)1 QueryRecordExecutor (com.aerospike.client.query.QueryRecordExecutor)1