Search in sources :

Example 1 with Level

use of com.aerospike.client.Log.Level in project aerospike-client-java by aerospike.

the class Batch method batchReadHeaders.

/**
 * Read record header data in one batch.
 */
private void batchReadHeaders(AerospikeClient client, Parameters params, String keyPrefix, int size) throws Exception {
    // Batch gets into one call.
    Key[] keys = new Key[size];
    for (int i = 0; i < size; i++) {
        keys[i] = new Key(params.namespace, params.set, keyPrefix + (i + 1));
    }
    Record[] records = client.getHeader(null, keys);
    for (int i = 0; i < records.length; i++) {
        Key key = keys[i];
        Record record = records[i];
        Level level = Level.ERROR;
        int generation = 0;
        int expiration = 0;
        if (record != null && (record.generation > 0 || record.expiration > 0)) {
            level = Level.INFO;
            generation = record.generation;
            expiration = record.expiration;
        }
        console.write(level, "Record: ns=%s set=%s key=%s generation=%d expiration=%d", key.namespace, key.setName, key.userKey, generation, expiration);
    }
    if (records.length != size) {
        console.error("Record size mismatch. Expected %d. Received %d.", size, records.length);
    }
}
Also used : Record(com.aerospike.client.Record) Level(com.aerospike.client.Log.Level) Key(com.aerospike.client.Key)

Example 2 with Level

use of com.aerospike.client.Log.Level in project aerospike-client-java by aerospike.

the class Batch method batchReads.

/**
 * Read records in one batch.
 */
private void batchReads(AerospikeClient client, Parameters params, String keyPrefix, String binName, int size) throws Exception {
    // Batch gets into one call.
    Key[] keys = new Key[size];
    for (int i = 0; i < size; i++) {
        keys[i] = new Key(params.namespace, params.set, keyPrefix + (i + 1));
    }
    Record[] records = client.get(null, keys, binName);
    for (int i = 0; i < records.length; i++) {
        Key key = keys[i];
        Record record = records[i];
        Level level = Level.ERROR;
        Object value = null;
        if (record != null) {
            level = Level.INFO;
            value = record.getValue(binName);
        }
        console.write(level, "Record: ns=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, binName, value);
    }
    if (records.length != size) {
        console.error("Record size mismatch. Expected %d. Received %d.", size, records.length);
    }
}
Also used : Record(com.aerospike.client.Record) Level(com.aerospike.client.Log.Level) Key(com.aerospike.client.Key)

Aggregations

Key (com.aerospike.client.Key)2 Level (com.aerospike.client.Log.Level)2 Record (com.aerospike.client.Record)2