Source:
public void run() { while (running) { try { if (connection == null) { connection = serverSocket.accept(); inStream = new DataInputViewStreamWrapper(this.connection.getInputStream()); outStream = new DataOutputViewStreamWrapper(this.connection.getOutputStream()); LOG.info("Coordinator connection received"); } CollectCoordinationRequest request = new CollectCoordinationRequest(inStream); String requestVersion = request.getVersion(); long requestOffset = request.getOffset(); if (LOG.isDebugEnabled()) { LOG.debug( "Request received, version = " + requestVersion + ", offset = " + requestOffset); LOG.debug( "Expecting version = " + version + ", firstBufferedOffset = " + firstBufferedResultOffset); } if (!version.equals(requestVersion) || requestOffset < firstBufferedResultOffset) { LOG.warn("Invalid request. Received version = " + requestVersion + ", offset = " + requestOffset + "while expected version = " + version + ", firstBufferedOffset = " + firstBufferedResultOffset); sendBackResults(Collections.emptyList()); continue; } List<IN> results; try { bufferedResultsLock.lock(); int oldSize = bufferedResults.size(); int start = Math.min((int) (requestOffset - firstBufferedResultOffset), oldSize); int end = Math.min(start + maxResultsPerBatch, oldSize); if (LOG.isDebugEnabled()) { LOG.debug("Preparing " + (end - start) + " results"); } results = prepareResultBatch(start, end - start); if (oldSize >= maxResultsBuffered && bufferedResults.size() < maxResultsBuffered) { bufferNotFullCondition.signal(); } } finally { bufferedResultsLock.unlock(); } sendBackResults(results); } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Collect sink server encounters an IOException", e); } closeCurrentConnection(); } } }

Target:
public void run() { while (running) { try { if (connection == null) { connection = serverSocket.accept(); inStream = new DataInputViewStreamWrapper(this.connection.getInputStream()); outStream = new DataOutputViewStreamWrapper(this.connection.getOutputStream()); LOG.info("Coordinator connection received"); } CollectCoordinationRequest request = new CollectCoordinationRequest(inStream); String requestVersion = request.getVersion(); long requestOffset = request.getOffset(); if (LOG.isDebugEnabled()) { LOG.debug( "Request received, version = " + requestVersion + ", offset = " + requestOffset); LOG.debug( "Expecting version = " + version + ", offset = " + offset); } if (!version.equals(requestVersion) || requestOffset < offset) { LOG.warn("Invalid request. Received version = " + requestVersion + ", offset = " + requestOffset + ", while expected version = " + version + ", offset = " + offset); sendBackResults(Collections.emptyList()); continue; } List<IN> results; bufferedResultsLock.lock(); try { int oldSize = bufferedResults.size(); int ackedNum = Math.min((int) (requestOffset - offset), oldSize); int nextBatchSize = Math.min(ackedNum + maxResultsPerBatch, oldSize) - ackedNum; if (LOG.isDebugEnabled()) { LOG.debug("Preparing " + nextBatchSize + " results"); } for (int i = 0; i < ackedNum; i++) { bufferedResults.removeFirst(); offset++; } results = new ArrayList<>(bufferedResults.subList(0, nextBatchSize)); if (oldSize >= maxResultsBuffered && bufferedResults.size() < maxResultsBuffered) { bufferNotFullCondition.signal(); } } finally { bufferedResultsLock.unlock(); } sendBackResults(results); } catch (Exception e) { LOG.warn("Collect sink server encounters an exception", e); closeCurrentConnection(); } } }