I'm trying to read N items from a RingBuffer using readManyAsync but It's always returns an empty resultSet. If I use readOne I get data.
I'm using the readManyAsync as the documentation specify. There is another way to do that?
Enviroment:
Example:
Ringbuffer<String> buffer = this.hazelcastInstance.getRingbuffer("testBuffer");
buffer.add("a");
buffer.add("b");
buffer.add("c");
Long sequence = buffer.headSequence();
ICompletableFuture<ReadResultSet<String>> resultSetFuture = buffer.readManyAsync(sequence, 0, 3, null);
ReadResultSet<String> resultSet = resultSetFuture.get();
System.out.println("*** readManyAsync *** readCount: " + resultSet.readCount());
int count = 0;
for (String s : resultSet) {
System.out.println(count + " - " + s);
count++;
}
System.out.println("*** readOne ***");
for (int i = 0; i < 3; i++) {
System.out.println(i + " - " + buffer.readOne(i));
}
Output:
*** readManyAsync *** readCount: 0
*** readOne ***
0 - a
1 - b
2 - c
You are happy with receiving zero results:
buffer.readManyAsync(sequence, 0, 3, null);
Try changing 0 to 1.
buffer.readManyAsync(sequence, 1, 3, null);
Now the call will block till there is at least 1 result.
Probably you can make things more efficient by asking for more than 3 items. In most cases, retrieving data is cheap, but the io/operation scheduling is expensive. So try to batch as much as possible. So try to get as many results as possible.. e.g. 100... or 1000 (which is the max).
Ok, but how do you use readManyAsync in a non-blocking way, with minCount to 0 ?
I made a minimal test case, and I really can't figure it out. I posted a support topic here :
https://groups.google.com/forum/#!topic/hazelcast/FGnLWDGrzb8
As an answer : I use readManyAsync with a timeout, like so :
try{
buffer.readManyAsync(sequence, 1, 3, null).get(500, TimeUnit.MILLISECONDS);
} catch (TimeoutException e){
// We timed out, shame, let's move on
}
That seems the only way to make a graceful non-blocking thread, but by reading the doc, I really thought a minCount=0 would do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With