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);
}
Aggregations