use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NioCommand method onServerTimeout.
protected final void onServerTimeout() {
conn.unregister();
command.node.putAsyncConnection(conn, eventLoop.index);
if (command.isRead) {
// Read commands shift to prole node on timeout.
command.sequence++;
}
AerospikeException ae = new AerospikeException.Timeout(command.node, command.policy.socketTimeout, iteration, false);
retry(ae);
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NioCommand method totalTimeout.
private final void totalTimeout() {
AerospikeException ae = new AerospikeException.Timeout(command.node, command.policy.socketTimeout, iteration, true);
// Attempt timeout delay.
if (command.policy.timeoutDelay > 0) {
// Notify user of timeout, but allow transaction to continue in hope of reusing the socket.
timeoutDelay = true;
notifyFailure(ae);
deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(command.policy.timeoutDelay);
timeoutTask = eventLoop.timer.addTimeout(this, deadline);
return;
}
// Perform timeout.
timeoutTask = null;
fail();
notifyFailure(ae);
}
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 {
//Parse each message response and add it to the result array
dataOffset = 0;
while (dataOffset < receiveSize) {
readBytes(MSG_REMAINING_HEADER_SIZE);
resultCode = dataBuffer[5] & 0xFF;
// If other return codes are received, then abort the batch.
if (resultCode != 0) {
if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR) {
if (stopOnNotFound) {
return false;
}
} else {
throw new AerospikeException(resultCode);
}
}
byte info3 = dataBuffer[3];
// If this is the end marker of the response, do not proceed further
if ((info3 & Command.INFO3_LAST) == Command.INFO3_LAST) {
return false;
}
generation = Buffer.bytesToInt(dataBuffer, 6);
expiration = Buffer.bytesToInt(dataBuffer, 10);
batchIndex = Buffer.bytesToInt(dataBuffer, 14);
fieldCount = Buffer.bytesToShort(dataBuffer, 18);
opCount = Buffer.bytesToShort(dataBuffer, 20);
Key key = parseKey(fieldCount);
parseRow(key);
}
return true;
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class Util method readResource.
public static byte[] readResource(ClassLoader resourceLoader, String resourcePath) {
try {
URL url = resourceLoader.getResource(resourcePath);
InputStream is = url.openStream();
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
byte[] bytes = new byte[8192];
int length;
while ((length = is.read(bytes)) > 0) {
bos.write(bytes, 0, length);
}
return bos.toByteArray();
} finally {
is.close();
}
} catch (Exception e) {
throw new AerospikeException("Failed to read resource " + resourcePath, e);
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class IndexTask method queryStatus.
/**
* Query all nodes for task completion status.
*/
@Override
public int queryStatus() throws AerospikeException {
// All nodes must respond with load_pct of 100 to be considered done.
Node[] nodes = cluster.getNodes();
if (nodes.length == 0) {
throw new AerospikeException("Cluster is empty");
}
String command = "sindex/" + namespace + '/' + indexName;
for (Node node : nodes) {
String response = Info.request(policy, node, command);
String find = "load_pct=";
int index = response.indexOf(find);
if (index < 0) {
if (response.indexOf("FAIL:201") >= 0 || response.indexOf("FAIL:203") >= 0) {
// Index not found or not readable.
return Task.NOT_FOUND;
} else {
// Throw exception immediately.
throw new AerospikeException(command + " failed: " + response);
}
}
int begin = index + find.length();
int end = response.indexOf(';', begin);
String str = response.substring(begin, end);
int pct = Integer.parseInt(str);
if (pct != 100) {
return Task.IN_PROGRESS;
}
}
return Task.COMPLETE;
}
Aggregations