use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class TestAsyncQuery method asyncQuery.
@Test
public void asyncQuery() {
WriteListener listener = new WriteListener() {
private int count = 0;
public void onSuccess(final Key key) {
// in the same event loop thread.
if (++count == size) {
runQuery();
}
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
};
for (int i = 1; i <= size; i++) {
final Key key = new Key(args.namespace, args.set, keyPrefix + i);
Bin bin = new Bin(binName, i);
client.put(eventLoop, listener, null, key, bin);
}
waitTillComplete();
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class QueryInteger 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 QuerySum 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 PartitionTracker method isComplete.
public boolean isComplete(Policy policy) {
long recordCount = 0;
int partsRequested = 0;
int partsReceived = 0;
for (NodePartitions np : nodePartitionsList) {
recordCount += np.recordCount;
partsRequested += np.partsRequested;
partsReceived += np.partsReceived;
// System.out.println("Node " + np.node + " partsFull=" + np.partsFull.size() + " partsPartial=" + np.partsPartial.size() +
// " partsReceived=" + np.partsReceived + " recordsRequested=" + np.recordMax + " recordsReceived=" + np.recordCount);
}
if (partsReceived >= partsRequested) {
if (partitionFilter != null && recordCount == 0) {
partitionFilter.done = true;
}
return true;
}
if (maxRecords > 0 && recordCount >= maxRecords) {
return true;
}
// Check if limits have been reached.
if (iteration > policy.maxRetries) {
StringBuilder sb = new StringBuilder(2048);
sb.append("Max retries exceeded: ");
sb.append(policy.maxRetries);
sb.append(System.lineSeparator());
if (exceptions != null) {
sb.append("sub-exceptions:");
sb.append(System.lineSeparator());
for (AerospikeException ae : exceptions) {
sb.append(ae.getMessage());
sb.append(System.lineSeparator());
}
}
AerospikeException ae = new AerospikeException(ResultCode.MAX_RETRIES_EXCEEDED, sb.toString());
ae.setPolicy(policy);
ae.setIteration(iteration);
throw ae;
}
if (policy.totalTimeout > 0) {
// Check for total timeout.
long remaining = deadline - System.nanoTime() - TimeUnit.MILLISECONDS.toNanos(sleepBetweenRetries);
if (remaining <= 0) {
throw new AerospikeException.Timeout(policy, iteration);
}
// Convert back to milliseconds for remaining check.
remaining = TimeUnit.NANOSECONDS.toMillis(remaining);
if (remaining < totalTimeout) {
totalTimeout = (int) remaining;
if (socketTimeout > totalTimeout) {
socketTimeout = totalTimeout;
}
}
}
// Prepare for next iteration.
if (maxRecords > 0) {
maxRecords -= recordCount;
}
iteration++;
return false;
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class MultiCommand method parseGroup.
/**
* Parse all records in the group.
*/
private final boolean parseGroup(int receiveSize) throws IOException {
while (dataOffset < receiveSize) {
dataOffset += 3;
info3 = dataBuffer[dataOffset] & 0xFF;
dataOffset += 2;
resultCode = dataBuffer[dataOffset] & 0xFF;
// If this is the end marker of the response, do not proceed further.
if ((info3 & Command.INFO3_LAST) != 0) {
if (resultCode != 0) {
// The server returned a fatal error.
throw new AerospikeException(resultCode);
}
return false;
}
dataOffset++;
generation = Buffer.bytesToInt(dataBuffer, dataOffset);
dataOffset += 4;
expiration = Buffer.bytesToInt(dataBuffer, dataOffset);
dataOffset += 4;
batchIndex = Buffer.bytesToInt(dataBuffer, dataOffset);
dataOffset += 4;
fieldCount = Buffer.bytesToShort(dataBuffer, dataOffset);
dataOffset += 2;
opCount = Buffer.bytesToShort(dataBuffer, dataOffset);
dataOffset += 2;
if (isBatch) {
skipKey(fieldCount);
parseRow(null);
} else {
Key key = parseKey(fieldCount);
parseRow(key);
}
}
return true;
}
Aggregations