Refactor ExchangeClient#pollPage
Merges ExchangeClient#postProcessPage into ExchangeClient#pollPage
(its only usage) to avoid a redundant lock holder check, removes
a redundant peek into the pagesBuffer for NO_MORE_PAGES, and coalesces
the synchronized section of scheduleRequestIfNecessary into the
synchronized block that immediately preceeded it anyway
@@ -294,13 +294,6 @@ public class ExchangeClient
}
SerializedPage page = pageBuffer.poll();
- return postProcessPage(page);
- }
-
- private SerializedPage postProcessPage(SerializedPage page)
- {
- checkState(!Thread.holdsLock(this), "Can not get next page while holding a lock on this");
-
if (page == null) {
return null;
}
@@ -319,12 +312,10 @@ public class ExchangeClient
if (!closed.get()) {
bufferRetainedSizeInBytes -= page.getRetainedSizeInBytes();
systemMemoryContext.setBytes(bufferRetainedSizeInBytes);
- if (pageBuffer.peek() == NO_MORE_PAGES) {
- close();
- }
- }
}
scheduleRequestIfNecessary();
+ }
+
return page;
}
