Search in sources :

Example 1 with ServerCommand

use of com.aerospike.client.query.ServerCommand 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

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 ExecuteTask (com.aerospike.client.task.ExecuteTask)1