use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class AsyncMultiCommand method parseGroup.
final boolean parseGroup(int receiveSize) {
// Parse each message response and add it to the result array
dataOffset = 0;
while (dataOffset < receiveSize) {
resultCode = dataBuffer[dataOffset + 5] & 0xFF;
if (resultCode != 0) {
if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR) {
if (stopOnNotFound) {
return true;
}
} else {
throw new AerospikeException(resultCode);
}
}
// If this is the end marker of the response, do not proceed further
if ((dataBuffer[dataOffset + 3] & Command.INFO3_LAST) != 0) {
return true;
}
generation = Buffer.bytesToInt(dataBuffer, dataOffset + 6);
expiration = Buffer.bytesToInt(dataBuffer, dataOffset + 10);
batchIndex = Buffer.bytesToInt(dataBuffer, dataOffset + 14);
fieldCount = Buffer.bytesToShort(dataBuffer, dataOffset + 18);
opCount = Buffer.bytesToShort(dataBuffer, dataOffset + 20);
dataOffset += Command.MSG_REMAINING_HEADER_SIZE;
Key key = parseKey();
parseRow(key);
}
return false;
}
use of com.aerospike.client.AerospikeException in project YCSB by brianfrankcooper.
the class AerospikeClient method init.
@Override
public void init() throws DBException {
insertPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY;
updatePolicy.recordExistsAction = RecordExistsAction.REPLACE_ONLY;
Properties props = getProperties();
namespace = props.getProperty("as.namespace", DEFAULT_NAMESPACE);
String host = props.getProperty("as.host", DEFAULT_HOST);
String user = props.getProperty("as.user");
String password = props.getProperty("as.password");
int port = Integer.parseInt(props.getProperty("as.port", DEFAULT_PORT));
int timeout = Integer.parseInt(props.getProperty("as.timeout", DEFAULT_TIMEOUT));
readPolicy.timeout = timeout;
insertPolicy.timeout = timeout;
updatePolicy.timeout = timeout;
deletePolicy.timeout = timeout;
ClientPolicy clientPolicy = new ClientPolicy();
if (user != null && password != null) {
clientPolicy.user = user;
clientPolicy.password = password;
}
try {
client = new com.aerospike.client.AerospikeClient(clientPolicy, host, port);
} catch (AerospikeException e) {
throw new DBException(String.format("Error while creating Aerospike " + "client for %s:%d.", host, port), e);
}
}
use of com.aerospike.client.AerospikeException in project YCSB by brianfrankcooper.
the class AerospikeClient method write.
private Status write(String table, String key, WritePolicy writePolicy, HashMap<String, ByteIterator> values) {
Bin[] bins = new Bin[values.size()];
int index = 0;
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
bins[index] = new Bin(entry.getKey(), entry.getValue().toArray());
++index;
}
Key keyObj = new Key(namespace, table, key);
try {
client.put(writePolicy, keyObj, bins);
return Status.OK;
} catch (AerospikeException e) {
System.err.println("Error while writing key " + key + ": " + e);
return Status.ERROR;
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class QueryPredExp method createIndex.
private void createIndex(AerospikeClient client, Parameters params, String indexName, String binName) throws Exception {
console.info("Create index: ns=%s set=%s index=%s bin=%s", params.namespace, params.set, indexName, binName);
Policy policy = new Policy();
// Do not timeout on index create.
policy.socketTimeout = 0;
try {
IndexTask task = client.createIndex(policy, params.namespace, params.set, indexName, binName, IndexType.NUMERIC);
task.waitTillComplete();
} catch (AerospikeException ae) {
if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
throw ae;
}
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class Cluster method seedNodes.
private final boolean seedNodes(boolean failIfNotConnected) throws AerospikeException {
// Must copy array reference for copy on write semantics to work.
Host[] seedArray = seeds;
Exception[] exceptions = null;
// Add all nodes at once to avoid copying entire array multiple times.
HashMap<String, Node> nodesToAdd = new HashMap<String, Node>(seedArray.length + 16);
for (int i = 0; i < seedArray.length; i++) {
Host seed = seedArray[i];
try {
NodeValidator nv = new NodeValidator();
nv.seedNodes(this, seed, nodesToAdd);
} catch (Exception e) {
// Store exception and try next host
if (failIfNotConnected) {
if (exceptions == null) {
exceptions = new Exception[seedArray.length];
}
exceptions[i] = e;
} else {
if (Log.warnEnabled()) {
Log.warn("Seed " + seed + " failed: " + Util.getErrorMessage(e));
}
}
}
}
if (nodesToAdd.size() > 0) {
addNodes(nodesToAdd);
return true;
} else if (failIfNotConnected) {
StringBuilder sb = new StringBuilder(500);
sb.append("Failed to connect to host(s): ");
sb.append(Environment.Newline);
for (int i = 0; i < seedArray.length; i++) {
sb.append(seedArray[i]);
sb.append(' ');
Exception ex = exceptions == null ? null : exceptions[i];
if (ex != null) {
sb.append(ex.getMessage());
sb.append(Environment.Newline);
}
}
throw new AerospikeException.Connection(sb.toString());
}
return false;
}
Aggregations