Search in sources :

Example 6 with AerospikeException

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;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Prototype(org.luaj.vm2.Prototype) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) AerospikeException(com.aerospike.client.AerospikeException)

Example 7 with AerospikeException

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;
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Prototype(org.luaj.vm2.Prototype) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AerospikeException(com.aerospike.client.AerospikeException)

Example 8 with AerospikeException

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);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) HashedWheelTimeout(com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)

Example 9 with AerospikeException

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();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException)

Example 10 with AerospikeException

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);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) HashedWheelTimeout(com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)71 Key (com.aerospike.client.Key)33 Record (com.aerospike.client.Record)18 Test (org.junit.Test)16 Bin (com.aerospike.client.Bin)13 Node (com.aerospike.client.cluster.Node)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)6 Value (com.aerospike.client.Value)5 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)5 WritePolicy (com.aerospike.client.policy.WritePolicy)5 HashMap (java.util.HashMap)5 HashedWheelTimeout (com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)4 Connection (com.aerospike.client.cluster.Connection)4 WriteListener (com.aerospike.client.listener.WriteListener)4 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 Partition (com.aerospike.client.cluster.Partition)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3