Search in sources :

Example 1 with ExecuteTask

use of com.aerospike.client.task.ExecuteTask in project aerospike-client-java by aerospike.

the class QueryExecute method runQueryExecute.

private void runQueryExecute(AerospikeClient client, Parameters params, String indexName, String binName1, String binName2) throws Exception {
    int begin = 3;
    int end = 9;
    console.info("For ns=%s set=%s index=%s bin=%s >= %s <= %s", params.namespace, params.set, indexName, binName1, begin, end);
    console.info("Even integers: add 100 to existing " + binName1);
    console.info("Multiple of 5: delete " + binName2 + " bin");
    console.info("Multiple of 9: delete record");
    Statement stmt = new Statement();
    stmt.setNamespace(params.namespace);
    stmt.setSetName(params.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    ExecuteTask task = client.execute(params.writePolicy, stmt, "record_example", "processRecord", Value.get(binName1), Value.get(binName2), Value.get(100));
    task.waitTillComplete();
}
Also used : Statement(com.aerospike.client.query.Statement) ExecuteTask(com.aerospike.client.task.ExecuteTask)

Example 2 with ExecuteTask

use of com.aerospike.client.task.ExecuteTask in project aerospike-client-java by aerospike.

the class TestQueryExecute method queryExecute.

@Test
public void queryExecute() {
    int begin = 3;
    int end = 9;
    Statement stmt = new Statement();
    stmt.setNamespace(args.namespace);
    stmt.setSetName(args.set);
    stmt.setFilter(Filter.range(binName1, begin, end));
    ExecuteTask task = client.execute(null, stmt, "record_example", "processRecord", Value.get(binName1), Value.get(binName2), Value.get(100));
    task.waitTillComplete();
    validateRecords();
}
Also used : Statement(com.aerospike.client.query.Statement) ExecuteTask(com.aerospike.client.task.ExecuteTask) Test(org.junit.Test)

Example 3 with ExecuteTask

use of com.aerospike.client.task.ExecuteTask in project aerospike-client-java by aerospike.

the class AerospikeClient method execute.

// ----------------------------------------------------------
// Query/Execute UDF
// ----------------------------------------------------------
/**
 * Apply user defined function on records that match the statement filter.
 * Records are not returned to the client.
 * This asynchronous server call will return before command is complete.
 * The user can optionally wait for command completion by using the returned
 * ExecuteTask instance.
 *
 * @param policy				write configuration parameters, pass in null for defaults
 * @param statement				record filter
 * @param packageName			server package where user defined function resides
 * @param functionName			function name
 * @param functionArgs			to pass to function name, if any
 * @throws AerospikeException	if command fails
 */
public final ExecuteTask execute(WritePolicy policy, Statement statement, String packageName, String functionName, Value... functionArgs) throws AerospikeException {
    if (policy == null) {
        policy = writePolicyDefault;
    }
    statement.setAggregateFunction(packageName, functionName, functionArgs);
    statement.prepare(false);
    Node[] nodes = cluster.getNodes();
    if (nodes.length == 0) {
        throw new AerospikeException(ResultCode.SERVER_NOT_AVAILABLE, "Command failed because cluster is empty.");
    }
    Executor executor = new Executor(cluster, policy, nodes.length);
    for (Node node : nodes) {
        ServerCommand command = new ServerCommand(policy, statement);
        executor.addCommand(node, command);
    }
    executor.execute(nodes.length);
    return new ExecuteTask(cluster, policy, statement);
}
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) Node(com.aerospike.client.cluster.Node) BatchNode(com.aerospike.client.command.BatchNode) ExecuteTask(com.aerospike.client.task.ExecuteTask) ServerCommand(com.aerospike.client.query.ServerCommand)

Aggregations

ExecuteTask (com.aerospike.client.task.ExecuteTask)3 Statement (com.aerospike.client.query.Statement)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 ServerCommand (com.aerospike.client.query.ServerCommand)1 Test (org.junit.Test)1