Search in sources :

Example 1 with CursorHasNextCommand

use of org.apache.ignite.internal.metastorage.common.command.cursor.CursorHasNextCommand 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 + ']';
        }
    }
}
Also used : GetCommand(org.apache.ignite.internal.metastorage.common.command.GetCommand) Entry(org.apache.ignite.internal.metastorage.server.Entry) ReadCommand(org.apache.ignite.raft.client.ReadCommand) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) MultipleEntryResponse(org.apache.ignite.internal.metastorage.common.command.MultipleEntryResponse) SingleEntryResponse(org.apache.ignite.internal.metastorage.common.command.SingleEntryResponse) CursorHasNextCommand(org.apache.ignite.internal.metastorage.common.command.cursor.CursorHasNextCommand) GetAllCommand(org.apache.ignite.internal.metastorage.common.command.GetAllCommand)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 GetAllCommand (org.apache.ignite.internal.metastorage.common.command.GetAllCommand)1 GetCommand (org.apache.ignite.internal.metastorage.common.command.GetCommand)1 MultipleEntryResponse (org.apache.ignite.internal.metastorage.common.command.MultipleEntryResponse)1 SingleEntryResponse (org.apache.ignite.internal.metastorage.common.command.SingleEntryResponse)1 CursorHasNextCommand (org.apache.ignite.internal.metastorage.common.command.cursor.CursorHasNextCommand)1 Entry (org.apache.ignite.internal.metastorage.server.Entry)1 ReadCommand (org.apache.ignite.raft.client.ReadCommand)1