/** @param page Page. */ public final void addPage(GridResultPage page) { int pageRowsCnt = page.rowsInPage(); if (pageRowsCnt != 0) addPage0(page); Counter cnt = remainingRows.get(page.source()); int allRows = page.response().allRows(); if (allRows != -1) { // Only the first page contains allRows count and is allowed to init counter. assert !cnt.initialized : "Counter is already initialized."; cnt.addAndGet(allRows); expRowsCnt.addAndGet(allRows); // We need this separate flag to handle case when the first source contains only one page // and it will signal that all remaining counters are zero and fetch is finished. cnt.initialized = true; } if (cnt.addAndGet(-pageRowsCnt) == 0) { // Result can be negative in case of race between messages, it is ok. boolean last = true; for (Counter c : remainingRows.values()) { // Check all the sources. if (c.get() != 0 || !c.initialized) { last = false; break; } } if (last && lastSubmitted.compareAndSet(false, true)) { addPage0( new GridResultPage(null, page.source(), null) { @Override public boolean isLast() { return true; } }); } } }
/** @param page Page. */ protected void fetchNextPage(GridResultPage page) { if (remainingRows.get(page.source()).get() != 0) page.fetchNextPage(); }