public class AsyncClient extends AerospikeClient implements IAsyncClient, Closeable
The new efficient asynchronous API is located directly in AerospikeClient. This class is just a thin wrapper over the new AerospikeClient asynchronous API. This class exists solely to provide compatibility with legacy applications.
Asynchronous Aerospike client.
Your application uses this class to perform asynchronous database operations such as writing and reading records, and selecting sets of records. Write operations include specialized functionality such as append/prepend and arithmetic addition.
This client is thread-safe. One client instance should be used per cluster. Multiple threads should share this cluster instance.
Each record may have multiple bins, unless the Aerospike server nodes are configured as "single-bin". In "multi-bin" mode, partial records may be written or read by specifying the relevant subset of bins.
Modifier and Type | Field and Description |
---|---|
BatchPolicy |
asyncBatchPolicyDefault
Default batch policy that is used when asynchronous batch command policy is null.
|
QueryPolicy |
asyncQueryPolicyDefault
Default query policy that is used when asynchronous query command policy is null.
|
Policy |
asyncReadPolicyDefault
Default read policy that is used when asynchronous read command policy is null.
|
ScanPolicy |
asyncScanPolicyDefault
Default scan policy that is used when asynchronous scan command policy is null.
|
WritePolicy |
asyncWritePolicyDefault
Default write policy that is used when asynchronous write command policy is null.
|
batchPolicyDefault, infoPolicyDefault, queryPolicyDefault, readPolicyDefault, scanPolicyDefault, writePolicyDefault
Constructor and Description |
---|
AsyncClient(AsyncClientPolicy policy,
Host... hosts)
Initialize asynchronous client with suitable hosts to seed the cluster map.
|
AsyncClient(AsyncClientPolicy policy,
String hostname,
int port)
Initialize asynchronous client.
|
AsyncClient(String hostname,
int port)
Initialize asynchronous client.
|
Modifier and Type | Method and Description |
---|---|
void |
add(WritePolicy policy,
WriteListener listener,
Key key,
Bin... bins)
Asynchronously add integer bin values to existing record bin values.
|
void |
append(WritePolicy policy,
WriteListener listener,
Key key,
Bin... bins)
Asynchronously append bin string values to existing record bin values.
|
void |
close()
Close all client connections to database server nodes.
|
void |
delete(WritePolicy policy,
DeleteListener listener,
Key key)
Asynchronously delete record for specified key.
|
void |
execute(WritePolicy policy,
ExecuteListener listener,
Key key,
String packageName,
String functionName,
Value... functionArgs)
Asynchronously execute user defined function on server and return results.
|
void |
exists(BatchPolicy policy,
ExistsArrayListener listener,
Key[] keys)
Asynchronously check if multiple record keys exist in one batch call.
|
void |
exists(BatchPolicy policy,
ExistsSequenceListener listener,
Key[] keys)
Asynchronously check if multiple record keys exist in one batch call.
|
void |
exists(Policy policy,
ExistsListener listener,
Key key)
Asynchronously determine if a record key exists.
|
void |
get(BatchPolicy policy,
BatchListListener listener,
List<BatchRead> records)
Asynchronously read multiple records for specified batch keys in one batch call.
|
void |
get(BatchPolicy policy,
BatchSequenceListener listener,
List<BatchRead> records)
Asynchronously read multiple records for specified batch keys in one batch call.
|
void |
get(BatchPolicy policy,
RecordArrayListener listener,
Key[] keys)
Asynchronously read multiple records for specified keys in one batch call.
|
void |
get(BatchPolicy policy,
RecordArrayListener listener,
Key[] keys,
String... binNames)
Asynchronously read multiple record headers and bins for specified keys in one batch call.
|
void |
get(BatchPolicy policy,
RecordSequenceListener listener,
Key[] keys)
Asynchronously read multiple records for specified keys in one batch call.
|
void |
get(BatchPolicy policy,
RecordSequenceListener listener,
Key[] keys,
String... binNames)
Asynchronously read multiple record headers and bins for specified keys in one batch call.
|
void |
get(Policy policy,
RecordListener listener,
Key key)
Asynchronously read entire record for specified key.
|
void |
get(Policy policy,
RecordListener listener,
Key key,
String... binNames)
Asynchronously read record header and bins for specified key.
|
BatchPolicy |
getAsyncBatchPolicyDefault() |
QueryPolicy |
getAsyncQueryPolicyDefault() |
Policy |
getAsyncReadPolicyDefault() |
ScanPolicy |
getAsyncScanPolicyDefault() |
WritePolicy |
getAsyncWritePolicyDefault() |
void |
getHeader(BatchPolicy policy,
RecordArrayListener listener,
Key[] keys)
Asynchronously read multiple record header data for specified keys in one batch call.
|
void |
getHeader(BatchPolicy policy,
RecordSequenceListener listener,
Key[] keys)
Asynchronously read multiple record header data for specified keys in one batch call.
|
void |
getHeader(Policy policy,
RecordListener listener,
Key key)
Asynchronously read record generation and expiration only for specified key.
|
void |
operate(WritePolicy policy,
RecordListener listener,
Key key,
Operation... operations)
Asynchronously perform multiple read/write operations on a single key in one batch call.
|
void |
prepend(WritePolicy policy,
WriteListener listener,
Key key,
Bin... bins)
Asynchronously prepend bin string values to existing record bin values.
|
void |
put(WritePolicy policy,
WriteListener listener,
Key key,
Bin... bins)
Asynchronously write record bin(s).
|
void |
query(QueryPolicy policy,
RecordSequenceListener listener,
Statement statement)
Asynchronously execute query on all server nodes.
|
void |
scanAll(ScanPolicy policy,
RecordSequenceListener listener,
String namespace,
String setName,
String... binNames)
Asynchronously read all records in specified namespace and set.
|
void |
touch(WritePolicy policy,
WriteListener listener,
Key key)
Asynchronously create record if it does not already exist.
|
add, add, append, append, changePassword, createIndex, createIndex, createRole, createUser, delete, delete, dropIndex, dropRole, dropUser, execute, execute, execute, exists, exists, exists, exists, exists, get, get, get, get, get, get, get, get, get, get, get, get, get, getBatchPolicyDefault, getClusterStats, getHeader, getHeader, getHeader, getHeader, getHeader, getInfoPolicyDefault, getNode, getNodeNames, getNodes, getQueryPolicyDefault, getReadPolicyDefault, getScanPolicyDefault, getWritePolicyDefault, grantPrivileges, grantRoles, isConnected, operate, operate, prepend, prepend, put, put, query, query, queryAggregate, queryAggregate, queryAggregateNode, queryNode, queryRole, queryRoles, queryUser, queryUsers, register, register, registerUdfString, removeUdf, revokePrivileges, revokeRoles, scanAll, scanAll, scanNode, scanNode, touch, touch, truncate
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, add, append, append, changePassword, createIndex, createIndex, createRole, createUser, delete, delete, dropIndex, dropRole, dropUser, execute, execute, execute, exists, exists, exists, exists, exists, get, get, get, get, get, get, get, get, get, get, get, get, get, getBatchPolicyDefault, getClusterStats, getHeader, getHeader, getHeader, getHeader, getHeader, getInfoPolicyDefault, getNode, getNodeNames, getNodes, getQueryPolicyDefault, getReadPolicyDefault, getScanPolicyDefault, getWritePolicyDefault, grantPrivileges, grantRoles, isConnected, operate, operate, prepend, prepend, put, put, query, query, queryAggregate, queryAggregate, queryAggregateNode, queryNode, queryRole, queryRoles, queryUser, queryUsers, register, register, registerUdfString, removeUdf, revokePrivileges, revokeRoles, scanAll, scanAll, scanNode, scanNode, touch, touch, truncate
public final Policy asyncReadPolicyDefault
public final WritePolicy asyncWritePolicyDefault
public final ScanPolicy asyncScanPolicyDefault
public final QueryPolicy asyncQueryPolicyDefault
public final BatchPolicy asyncBatchPolicyDefault
public AsyncClient(String hostname, int port) throws AerospikeException
- Add host to the cluster map
- Request host's list of other nodes in cluster
- Add these nodes to cluster map
If the connection succeeds, the client is ready to process database requests. If the connection fails, the cluster will remain in a disconnected state until the server is activated.
hostname
- host nameport
- host portAerospikeException
- if host connection failspublic AsyncClient(AsyncClientPolicy policy, String hostname, int port) throws AerospikeException
- Add host to the cluster map
- Request host's list of other nodes in cluster
- Add these nodes to cluster map
If the connection succeeds, the client is ready to process database requests. If the connection fails and the policy's failIfNotConnected is true, a connection exception will be thrown. Otherwise, the cluster will remain in a disconnected state until the server is activated.
policy
- client configuration parameters, pass in null for defaultshostname
- host nameport
- host portAerospikeException
- if host connection failspublic AsyncClient(AsyncClientPolicy policy, Host... hosts) throws AerospikeException
- Add host to the cluster map
- Request host's list of other nodes in cluster
- Add these nodes to cluster map
In most cases, only one host is necessary to seed the cluster. The remaining hosts are added as future seeds in case of a complete network failure.
If one connection succeeds, the client is ready to process database requests. If all connections fail and the policy's failIfNotConnected is true, a connection exception will be thrown. Otherwise, the cluster will remain in a disconnected state until the server is activated.
policy
- client configuration parameters, pass in null for defaultshosts
- array of potential hosts to seed the clusterAerospikeException
- if all host connections failpublic final void close()
close
in interface IAerospikeClient
close
in interface Closeable
close
in interface AutoCloseable
close
in class AerospikeClient
public final Policy getAsyncReadPolicyDefault()
getAsyncReadPolicyDefault
in interface IAsyncClient
public final WritePolicy getAsyncWritePolicyDefault()
getAsyncWritePolicyDefault
in interface IAsyncClient
public final ScanPolicy getAsyncScanPolicyDefault()
getAsyncScanPolicyDefault
in interface IAsyncClient
public final QueryPolicy getAsyncQueryPolicyDefault()
getAsyncQueryPolicyDefault
in interface IAsyncClient
public final BatchPolicy getAsyncBatchPolicyDefault()
getAsyncBatchPolicyDefault
in interface IAsyncClient
public final void put(WritePolicy policy, WriteListener listener, Key key, Bin... bins) throws AerospikeException
The policy specifies the transaction timeout, record expiration and how the transaction is handled when the record already exists.
put
in interface IAsyncClient
policy
- write configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifierbins
- array of bin name/value pairsAerospikeException
- if queue is fullpublic final void append(WritePolicy policy, WriteListener listener, Key key, Bin... bins) throws AerospikeException
The policy specifies the transaction timeout, record expiration and how the transaction is handled when the record already exists. This call only works for string values.
append
in interface IAsyncClient
policy
- write configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifierbins
- array of bin name/value pairsAerospikeException
- if queue is fullpublic final void prepend(WritePolicy policy, WriteListener listener, Key key, Bin... bins) throws AerospikeException
The policy specifies the transaction timeout, record expiration and how the transaction is handled when the record already exists. This call works only for string values.
prepend
in interface IAsyncClient
policy
- write configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifierbins
- array of bin name/value pairsAerospikeException
- if queue is fullpublic final void add(WritePolicy policy, WriteListener listener, Key key, Bin... bins) throws AerospikeException
The policy specifies the transaction timeout, record expiration and how the transaction is handled when the record already exists. This call only works for integer values.
add
in interface IAsyncClient
policy
- write configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifierbins
- array of bin name/value pairsAerospikeException
- if queue is fullpublic final void delete(WritePolicy policy, DeleteListener listener, Key key) throws AerospikeException
The policy specifies the transaction timeout.
delete
in interface IAsyncClient
policy
- delete configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifierAerospikeException
- if queue is fullpublic final void touch(WritePolicy policy, WriteListener listener, Key key) throws AerospikeException
This method schedules the touch command with a channel selector and returns. Another thread will process the command and send the results to the listener.
touch
in interface IAsyncClient
policy
- write configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifierAerospikeException
- if queue is fullpublic final void exists(Policy policy, ExistsListener listener, Key key) throws AerospikeException
The policy can be used to specify timeouts.
exists
in interface IAsyncClient
policy
- generic configuration parameters, pass in null for defaultslistener
- where to send resultskey
- unique record identifierAerospikeException
- if queue is fullpublic final void exists(BatchPolicy policy, ExistsArrayListener listener, Key[] keys) throws AerospikeException
The policy can be used to specify timeouts and maximum parallel commands.
exists
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersAerospikeException
- if queue is fullpublic final void exists(BatchPolicy policy, ExistsSequenceListener listener, Key[] keys) throws AerospikeException
The policy can be used to specify timeouts and maximum parallel commands.
exists
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersAerospikeException
- if queue is fullpublic final void get(Policy policy, RecordListener listener, Key key) throws AerospikeException
The policy can be used to specify timeouts.
get
in interface IAsyncClient
policy
- generic configuration parameters, pass in null for defaultslistener
- where to send resultskey
- unique record identifierAerospikeException
- if queue is fullpublic final void get(Policy policy, RecordListener listener, Key key, String... binNames) throws AerospikeException
The policy can be used to specify timeouts.
get
in interface IAsyncClient
policy
- generic configuration parameters, pass in null for defaultslistener
- where to send resultskey
- unique record identifierbinNames
- bins to retrieveAerospikeException
- if queue is fullpublic final void getHeader(Policy policy, RecordListener listener, Key key) throws AerospikeException
The policy can be used to specify timeouts.
getHeader
in interface IAsyncClient
policy
- generic configuration parameters, pass in null for defaultslistener
- where to send resultskey
- unique record identifierAerospikeException
- if queue is fullpublic final void get(BatchPolicy policy, BatchListListener listener, List<BatchRead> records) throws AerospikeException
This method schedules the get command with a channel selector and returns. Another thread will process the command and send the results to the listener in a single call. This method requires Aerospike Server version >= 3.6.0.
get
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultsrecords
- list of unique record identifiers and the bins to retrieve.AerospikeException
- if read failspublic final void get(BatchPolicy policy, BatchSequenceListener listener, List<BatchRead> records) throws AerospikeException
This method schedules the get command with a channel selector and returns. Another thread will process the command and send the results to the listener in a single call. This method requires Aerospike Server version >= 3.6.0.
get
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultsrecords
- list of unique record identifiers and the bins to retrieve.AerospikeException
- if read failspublic final void get(BatchPolicy policy, RecordArrayListener listener, Key[] keys) throws AerospikeException
If a key is not found, the record will be null. The policy can be used to specify timeouts and maximum parallel commands.
get
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersAerospikeException
- if queue is fullpublic final void get(BatchPolicy policy, RecordSequenceListener listener, Key[] keys) throws AerospikeException
If a key is not found, the record will be null. The policy can be used to specify timeouts and maximum parallel commands.
get
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersAerospikeException
- if queue is fullpublic final void get(BatchPolicy policy, RecordArrayListener listener, Key[] keys, String... binNames) throws AerospikeException
If a key is not found, the record will be null. The policy can be used to specify timeouts and maximum parallel commands.
get
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersbinNames
- array of bins to retrieveAerospikeException
- if queue is fullpublic final void get(BatchPolicy policy, RecordSequenceListener listener, Key[] keys, String... binNames) throws AerospikeException
If a key is not found, the record will be null. The policy can be used to specify timeouts and maximum parallel commands.
get
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersbinNames
- array of bins to retrieveAerospikeException
- if queue is fullpublic final void getHeader(BatchPolicy policy, RecordArrayListener listener, Key[] keys) throws AerospikeException
If a key is not found, the record will be null. The policy can be used to specify timeouts and maximum parallel commands.
getHeader
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersAerospikeException
- if queue is fullpublic final void getHeader(BatchPolicy policy, RecordSequenceListener listener, Key[] keys) throws AerospikeException
If a key is not found, the record will be null. The policy can be used to specify timeouts and maximum parallel commands.
getHeader
in interface IAsyncClient
policy
- batch configuration parameters, pass in null for defaultslistener
- where to send resultskeys
- array of unique record identifiersAerospikeException
- if queue is fullpublic final void operate(WritePolicy policy, RecordListener listener, Key key, Operation... operations) throws AerospikeException
This method schedules the operate command with a channel selector and returns. Another thread will process the command and send the results to the listener.
Both scalar bin operations (Operation) and list bin operations (ListOperation) can be performed in same call.
operate
in interface IAsyncClient
policy
- write configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifieroperations
- database operations to performAerospikeException
- if queue is fullpublic final void scanAll(ScanPolicy policy, RecordSequenceListener listener, String namespace, String setName, String... binNames) throws AerospikeException
concurrentNodes
is specified, each server node will be read in
parallel. Otherwise, server nodes are read in series.
This method schedules the scan command with a channel selector and returns. Another thread will process the command and send the results to the listener.
scanAll
in interface IAsyncClient
policy
- scan configuration parameters, pass in null for defaultslistener
- where to send resultsnamespace
- namespace - equivalent to database namesetName
- optional set name - equivalent to database tablebinNames
- optional bin to retrieve. All bins will be returned if not specified.
Aerospike 2 servers ignore this parameter.AerospikeException
- if queue is fullpublic final void execute(WritePolicy policy, ExecuteListener listener, Key key, String packageName, String functionName, Value... functionArgs) throws AerospikeException
udf file =
This method schedules the execute command with a channel selector and returns.
Another thread will process the command and send the results to the listener.
execute
in interface IAsyncClient
policy
- write configuration parameters, pass in null for defaultslistener
- where to send results, pass in null for fire and forgetkey
- unique record identifierpackageName
- server package name where user defined function residesfunctionName
- user defined functionfunctionArgs
- arguments passed in to user defined functionAerospikeException
- if transaction failspublic final void query(QueryPolicy policy, RecordSequenceListener listener, Statement statement) throws AerospikeException
maxConcurrentNodes
dictate how many nodes can be queried in parallel.
The default is to query all nodes in parallel.
This method schedules the node's query commands with channel selectors and returns. Selector threads will process the commands and send the results to the listener.
query
in interface IAsyncClient
policy
- query configuration parameters, pass in null for defaultslistener
- where to send resultsstatement
- database query command parametersAerospikeException
- if query failsCopyright ? 2012–2018 Aerospike, Inc. All rights reserved.