Search in sources :

Example 1 with PartitionFilter

use of com.aerospike.client.query.PartitionFilter in project aerospike-client-java by aerospike.

the class AsyncScanPage method runScan.

private void runScan(AerospikeClient client, EventLoop eventLoop) {
    int pageSize = 30;
    console.info("Scan max " + pageSize + " records.");
    ScanPolicy policy = new ScanPolicy();
    policy.maxRecords = pageSize;
    PartitionFilter filter = PartitionFilter.all();
    RecordSequenceListener listener = new RecordSequenceListener() {

        private int count = 0;

        @Override
        public void onRecord(Key key, Record record) throws AerospikeException {
            count++;
        }

        @Override
        public void onSuccess() {
            console.info("Records returned: " + count);
            notifyComplete();
        }

        @Override
        public void onFailure(AerospikeException e) {
            console.error("Scan failed: " + Util.getErrorMessage(e));
            notifyComplete();
        }
    };
    client.scanPartitions(eventLoop, listener, policy, filter, params.namespace, setName);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) PartitionFilter(com.aerospike.client.query.PartitionFilter) RecordSequenceListener(com.aerospike.client.listener.RecordSequenceListener) ScanPolicy(com.aerospike.client.policy.ScanPolicy) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 2 with PartitionFilter

use of com.aerospike.client.query.PartitionFilter in project aerospike-client-java by aerospike.

the class ScanResume method runExample.

/**
 * Terminate a scan and then resume scan later.
 */
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
    String binName = "bin";
    String setName = "resume";
    writeRecords(client, params, setName, binName, 200);
    // Serialize node scans so scan callback atomics are not necessary.
    ScanPolicy policy = new ScanPolicy();
    policy.concurrentNodes = false;
    PartitionFilter filter = PartitionFilter.all();
    recordCount = 0;
    recordMax = 50;
    console.info("Start scan terminate");
    try {
        client.scanPartitions(policy, filter, params.namespace, setName, this);
    } catch (AerospikeException.ScanTerminated e) {
        console.info("Scan terminated as expected");
    }
    console.info("Records returned: " + recordCount);
    // PartitionFilter could be serialized at this point.
    // Resume scan now.
    recordCount = 0;
    recordMax = 0;
    console.info("Start scan resume");
    client.scanPartitions(policy, filter, params.namespace, setName, this);
    console.info("Records returned: " + recordCount);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) PartitionFilter(com.aerospike.client.query.PartitionFilter) ScanPolicy(com.aerospike.client.policy.ScanPolicy)

Example 3 with PartitionFilter

use of com.aerospike.client.query.PartitionFilter in project aerospike-client-java by aerospike.

the class ScanPage method runExample.

/**
 * Scan in pages.
 */
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
    String binName = "bin";
    String setName = "page";
    writeRecords(client, params, setName, binName, 190);
    recordCount = new AtomicInteger();
    ScanPolicy policy = new ScanPolicy();
    policy.maxRecords = 100;
    PartitionFilter filter = PartitionFilter.all();
    // Scan 3 pages of records.
    for (int i = 0; i < 3 && !filter.isDone(); i++) {
        recordCount.set(0);
        console.info("Scan page: " + i);
        client.scanPartitions(policy, filter, params.namespace, setName, this);
        console.info("Records returned: " + recordCount.get());
    }
}
Also used : PartitionFilter(com.aerospike.client.query.PartitionFilter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScanPolicy(com.aerospike.client.policy.ScanPolicy)

Aggregations

ScanPolicy (com.aerospike.client.policy.ScanPolicy)3 PartitionFilter (com.aerospike.client.query.PartitionFilter)3 AerospikeException (com.aerospike.client.AerospikeException)2 Key (com.aerospike.client.Key)1 Record (com.aerospike.client.Record)1 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1