Search in sources :

Example 6 with Connection

use of com.aerospike.client.cluster.Connection in project aerospike-client-java by aerospike.

the class Info method request.

/**
 * Get many info values by name from the specified database server node.
 * This method supports user authentication.
 *
 * @param policy	info command configuration parameters, pass in null for defaults
 * @param node		server node
 * @param names		names of variables to retrieve
 */
public static Map<String, String> request(InfoPolicy policy, Node node, String... names) throws AerospikeException {
    int timeout = (policy == null) ? DEFAULT_TIMEOUT : policy.timeout;
    Connection conn = node.getConnection(timeout);
    try {
        Map<String, String> result = request(conn, names);
        node.putConnection(conn);
        return result;
    } catch (RuntimeException re) {
        node.closeConnection(conn);
        throw re;
    }
}
Also used : Connection(com.aerospike.client.cluster.Connection)

Example 7 with Connection

use of com.aerospike.client.cluster.Connection in project aerospike-client-java by aerospike.

the class Info method request.

// -------------------------------------------------------
// Get Info via Node
// -------------------------------------------------------
/**
 * Get one info value by name from the specified database server node.
 * This method supports user authentication.
 *
 * @param node		server node
 * @param name		name of variable to retrieve
 */
public static String request(Node node, String name) throws AerospikeException {
    Connection conn = node.getConnection(DEFAULT_TIMEOUT);
    try {
        String response = Info.request(conn, name);
        node.putConnection(conn);
        return response;
    } catch (RuntimeException re) {
        node.closeConnection(conn);
        throw re;
    }
}
Also used : Connection(com.aerospike.client.cluster.Connection)

Example 8 with Connection

use of com.aerospike.client.cluster.Connection in project aerospike-client-java by aerospike.

the class AdminCommand method executeCommand.

private void executeCommand(Cluster cluster, AdminPolicy policy) {
    writeSize();
    Node node = cluster.getRandomNode();
    int timeout = (policy == null) ? 1000 : policy.timeout;
    Connection conn = node.getConnection(timeout);
    try {
        conn.write(dataBuffer, dataOffset);
        conn.readFully(dataBuffer, HEADER_SIZE);
        conn.updateLastUsed();
        node.putConnection(conn);
    } catch (Exception e) {
        // All IO exceptions are considered fatal.  Do not retry.
        // Close socket to flush out possible garbage.  Do not put back in pool.
        node.closeConnection(conn);
        throw new AerospikeException(e);
    }
    int result = dataBuffer[RESULT_CODE] & 0xFF;
    if (result != 0) {
        throw new AerospikeException(result);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Node(com.aerospike.client.cluster.Node) Connection(com.aerospike.client.cluster.Connection) IOException(java.io.IOException) AerospikeException(com.aerospike.client.AerospikeException)

Example 9 with Connection

use of com.aerospike.client.cluster.Connection in project aerospike-client-java by aerospike.

the class RegisterCommand method register.

public static RegisterTask register(Cluster cluster, Policy policy, byte[] bytes, String serverPath, Language language) {
    String content = Crypto.encodeBase64(bytes);
    StringBuilder sb = new StringBuilder(serverPath.length() + content.length() + 100);
    sb.append("udf-put:filename=");
    sb.append(serverPath);
    sb.append(";content=");
    sb.append(content);
    sb.append(";content-len=");
    sb.append(content.length());
    sb.append(";udf-type=");
    sb.append(language);
    sb.append(";");
    // Send UDF to one node. That node will distribute the UDF to other nodes.
    String command = sb.toString();
    Node node = cluster.getRandomNode();
    Connection conn = node.getConnection(policy.socketTimeout);
    try {
        Info info = new Info(conn, command);
        NameValueParser parser = info.getNameValueParser();
        String error = null;
        String file = null;
        String line = null;
        String message = null;
        while (parser.next()) {
            String name = parser.getName();
            if (name.equals("error")) {
                error = parser.getValue();
            } else if (name.equals("file")) {
                file = parser.getValue();
            } else if (name.equals("line")) {
                line = parser.getValue();
            } else if (name.equals("message")) {
                message = parser.getStringBase64();
            }
        }
        if (error != null) {
            throw new AerospikeException("Registration failed: " + error + System.lineSeparator() + "File: " + file + System.lineSeparator() + "Line: " + line + System.lineSeparator() + "Message: " + message);
        }
        node.putConnection(conn);
        return new RegisterTask(cluster, policy, serverPath);
    } catch (RuntimeException re) {
        node.closeConnection(conn);
        throw re;
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Node(com.aerospike.client.cluster.Node) Connection(com.aerospike.client.cluster.Connection) RegisterTask(com.aerospike.client.task.RegisterTask) Info(com.aerospike.client.Info) NameValueParser(com.aerospike.client.Info.NameValueParser)

Aggregations

Connection (com.aerospike.client.cluster.Connection)9 AerospikeException (com.aerospike.client.AerospikeException)5 Node (com.aerospike.client.cluster.Node)5 IOException (java.io.IOException)4 SocketTimeoutException (java.net.SocketTimeoutException)2 Info (com.aerospike.client.Info)1 NameValueParser (com.aerospike.client.Info.NameValueParser)1 ConnectionRecover (com.aerospike.client.cluster.ConnectionRecover)1 Partition (com.aerospike.client.cluster.Partition)1 BatchNode (com.aerospike.client.command.BatchNode)1 RegisterTask (com.aerospike.client.task.RegisterTask)1