use of org.apache.ignite.internal.metastorage.common.command.GetAllCommand in project ignite-3 by apache.
the class MetaStorageListener method onRead.
/**
* {@inheritDoc}
*/
@Override
public void onRead(Iterator<CommandClosure<ReadCommand>> iter) {
while (iter.hasNext()) {
CommandClosure<ReadCommand> clo = iter.next();
ReadCommand command = clo.command();
if (command instanceof GetCommand) {
GetCommand getCmd = (GetCommand) command;
Entry e;
if (getCmd.revision() != 0) {
e = storage.get(getCmd.key(), getCmd.revision());
} else {
e = storage.get(getCmd.key());
}
SingleEntryResponse resp = new SingleEntryResponse(e.key(), e.value(), e.revision(), e.updateCounter());
clo.result(resp);
} else if (command instanceof GetAllCommand) {
GetAllCommand getAllCmd = (GetAllCommand) command;
Collection<Entry> entries;
if (getAllCmd.revision() != 0) {
entries = storage.getAll(getAllCmd.keys(), getAllCmd.revision());
} else {
entries = storage.getAll(getAllCmd.keys());
}
List<SingleEntryResponse> res = new ArrayList<>(entries.size());
for (Entry e : entries) {
res.add(new SingleEntryResponse(e.key(), e.value(), e.revision(), e.updateCounter()));
}
clo.result(new MultipleEntryResponse(res));
} else if (command instanceof CursorHasNextCommand) {
CursorHasNextCommand cursorHasNextCmd = (CursorHasNextCommand) command;
CursorMeta cursorDesc = cursors.get(cursorHasNextCmd.cursorId());
clo.result(!(cursorDesc == null) && cursorDesc.cursor().hasNext());
} else {
assert false : "Command was not found [cmd=" + command + ']';
}
}
}
Aggregations