commits some fixes but still and issue with "wire entry set"

This commit is contained in:
Rob Austin
2015-03-12 21:26:32 +00:00
parent 9cc5b854ae
commit baf9013904
4 changed files with 85 additions and 27 deletions
@@ -125,7 +125,7 @@ class MapWireHandler<K, V> implements WireHandler {
}
private void writeChunked(long transactionId,
@NotNull final Function<Map, Iterator<byte[]>> function,
@NotNull final Function<BytesChronicleMap, Iterator> function,
@NotNull final Consumer<Iterator<byte[]>> c) {
final BytesChronicleMap m = bytesMap(channelId);
@@ -155,6 +155,37 @@ class MapWireHandler<K, V> implements WireHandler {
}
private void writeEntryChunked(long transactionId,
@NotNull final Function<BytesChronicleMap, Iterator> function,
@NotNull final Consumer<Iterator<Map.Entry<byte[], byte[]>>> c) {
final BytesChronicleMap m = bytesMap(channelId);
final Iterator<Map.Entry<byte[], byte[]>> iterator = function.apply(m);
// this allows us to write more data than the buffer will allow
out = () -> {
// each chunk has its own transaction-id
outWire.write(TRANSACTION_ID).int64(transactionId);
write(map -> {
boolean hasNext = iterator.hasNext();
outWire.write(HAS_NEXT).bool(hasNext);
if (hasNext)
c.accept(iterator);
else
// setting out to NULL denotes that there are no more chunks
out = null;
});
};
out.run();
}
@SuppressWarnings("UnusedReturnValue")
void onEvent() {
@@ -182,12 +213,12 @@ class MapWireHandler<K, V> implements WireHandler {
}
if ("VALUES".contentEquals(methodName)) {
writeChunked(transactionId, map -> map.values().iterator(), writeElement);
writeChunked(transactionId, map -> map.delegate.values().iterator(), writeElement);
return;
}
if ("ENTRY_SET".contentEquals(methodName)) {
writeChunked(transactionId, map -> map.entrySet().iterator(), writeEntry);
writeEntryChunked(transactionId, m -> m.delegate.entrySet().iterator(), writeEntry);
return;
}
@@ -303,10 +334,6 @@ class MapWireHandler<K, V> implements WireHandler {
return;
}
if ("TO_STRING".contentEquals(methodName)) {
write(b -> outWire.write(RESULT).text(b.toString()));
return;
}
if ("APPLICATION_VERSION".contentEquals(methodName)) {
write(b -> outWire.write(RESULT).text(applicationVersion()));