HCOLL-167 added support for keyset

This commit is contained in:
Rob Austin
2014-10-27 20:09:53 +00:00
parent 8136b5e298
commit accebbfeea
2 changed files with 81 additions and 43 deletions
@@ -570,14 +570,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
}
@NotNull
public synchronized Set<K> keySet() {
long sizeLocation = writeEvent(KEY_SET);
// get the data back from the server
return readKeySet(blockingFetch(sizeLocation));
}
@NotNull
public synchronized Collection<V> values() {
@@ -637,6 +629,42 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
}
@NotNull
public synchronized Set<K> keySet() {
final long sizeLocation = writeEvent(KEY_SET);
final long startTime = System.currentTimeMillis();
final long transactionId = nextUniqueTransaction(startTime);
final long timeoutTime = System.currentTimeMillis() + builder.timeoutMs();
// get the data back from the server
Bytes in = blockingFetch0(sizeLocation, transactionId, startTime);
final Set<K> result = new HashSet<>();
for (; ; ) {
boolean hasMoreEntries = in.readBoolean();
LOG.info("entrySet - hasMoreEntries=" + hasMoreEntries);
// number of entries in the chunk
long size = in.readInt();
for (int i = 0; i < size; i++) {
K k = keyValueSerializer.readKey(in);
result.add(k);
}
if (!hasMoreEntries)
break;
in = blockingFetchReadOnly(timeoutTime, transactionId);
}
return result;
}
private long writeEvent(EventId event) {
buffer.clear();