use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class LuaCache method loadPackageFromFile.
/**
* Load lua package from a file.
*/
public static final Prototype loadPackageFromFile(String packageName) throws AerospikeException {
Prototype prototype = Packages.get(packageName);
if (prototype == null) {
File source = new File(LuaConfig.SourceDirectory, packageName + ".lua");
try {
InputStream is = new FileInputStream(source);
prototype = compile(packageName, is);
Packages.put(packageName, prototype);
} catch (Exception e) {
throw new AerospikeException("Failed to read file: " + source.getAbsolutePath());
}
}
return prototype;
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class LuaCache method loadPackageFromResource.
/**
* Load lua package from a resource.
*/
public static final Prototype loadPackageFromResource(ClassLoader resourceLoader, String resourcePath, String packageName) throws AerospikeException {
Prototype prototype = Packages.get(packageName);
if (prototype == null) {
try {
InputStream is = resourceLoader.getResourceAsStream(resourcePath);
if (is == null) {
throw new Exception();
}
prototype = compile(packageName, is);
Packages.put(packageName, prototype);
} catch (Exception e) {
throw new AerospikeException("Failed to read resource: " + resourcePath);
}
}
return prototype;
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NettyCommand 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 NettyCommand method run.
public void run() {
if (eventState.pending++ == -1) {
eventState.pending = -1;
eventState.errors++;
state = AsyncCommand.COMPLETE;
notifyFailure(new AerospikeException("Cluster has been closed"));
return;
}
if (state == AsyncCommand.REGISTERED && hasTotalTimeout) {
// Command was queued to event loop thread. Check if timed out.
long currentTime = System.nanoTime();
if (currentTime >= deadline) {
eventState.pending--;
eventState.errors++;
state = AsyncCommand.COMPLETE;
notifyFailure(new AerospikeException.Timeout(null, command.policy.totalTimeout, iteration, true));
return;
}
if (command.policy.socketTimeout > 0) {
timeoutTask = eventLoop.timer.addTimeout(this, currentTime + TimeUnit.MILLISECONDS.toNanos(command.policy.socketTimeout));
}
} else if (command.policy.socketTimeout > 0) {
timeoutTask = eventLoop.timer.addTimeout(this, System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(command.policy.socketTimeout));
}
executeCommand();
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NettyCommand method onServerTimeout.
protected final void onServerTimeout() {
if (state == AsyncCommand.COMPLETE) {
return;
}
putConnection();
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);
}
Aggregations