Source:
public void requestBlocks() { if (stopped) { log.warn("We have stopped already. We ignore that requestData call."); return; } GetBlocksRequest getBlocksRequest = new GetBlocksRequest(startBlockHeight, nonce, networkNode.getNodeAddress()); if (timeoutTimer != null) { log.warn("We had a timer already running and stop it."); timeoutTimer.stop(); } timeoutTimer = UserThread.runAfter(() -> { if (!stopped) { String errorMessage = "A timeout occurred when sending getBlocksRequest:" + getBlocksRequest + " on peersNodeAddress:" + nodeAddress; log.debug("{} / RequestDataHandler={}", errorMessage, RequestBlocksHandler.this); handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_TIMEOUT); } else { log.warn("We have stopped already. We ignore that timeoutTimer.run call. " + "Might be caused by an previous networkNode.sendMessage.onFailure."); } }, TIMEOUT_MIN, TimeUnit.MINUTES); log.info("We request blocks from peer from block height {}.", nodeAddress, getBlocksRequest.getFromBlockHeight()); networkNode.addMessageListener(this); SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getBlocksRequest); Futures.addCallback(future, new FutureCallback<>() { @Override public void onSuccess(Connection connection) { log.info("Sending of GetBlocksRequest message to peer succeeded.", nodeAddress.getFullAddress()); } @Override public void onFailure(@NotNull Throwable throwable) { if (!stopped) { String errorMessage = "Sending getBlocksRequest to " + nodeAddress + " failed. That is expected if the peer is offline.\n\t" + "getBlocksRequest=" + getBlocksRequest + "." + "\n\tException=" + throwable.getMessage(); log.error(errorMessage); handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_FAILURE); } else { log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call."); } } }, MoreExecutors.directExecutor()); }

Target:
public void requestBlocks() { if (stopped) { log.warn("We have stopped already. We ignore that requestData call."); return; } GetBlocksRequest getBlocksRequest = new GetBlocksRequest(startBlockHeight, nonce, networkNode.getNodeAddress()); if (timeoutTimer != null) { log.warn("We had a timer already running and stop it."); timeoutTimer.stop(); } timeoutTimer = UserThread.runAfter(() -> { if (!stopped) { String errorMessage = "A timeout occurred when sending getBlocksRequest:" + getBlocksRequest + " on peersNodeAddress:" + nodeAddress; log.debug("{} / RequestDataHandler={}", errorMessage, RequestBlocksHandler.this); handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_TIMEOUT); } else { log.warn("We have stopped already. We ignore that timeoutTimer.run call. " + "Might be caused by a previous networkNode.sendMessage.onFailure."); } }, TIMEOUT_MIN, TimeUnit.MINUTES); log.info("We request blocks from peer from block height {}.", nodeAddress, getBlocksRequest.getFromBlockHeight()); networkNode.addMessageListener(this); SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getBlocksRequest); Futures.addCallback(future, new FutureCallback<>() { @Override public void onSuccess(Connection connection) { log.info("Sending of GetBlocksRequest message to peer succeeded.", nodeAddress.getFullAddress()); } @Override public void onFailure(@NotNull Throwable throwable) { if (!stopped) { String errorMessage = "Sending getBlocksRequest to " + nodeAddress + " failed. That is expected if the peer is offline.\n\t" + "getBlocksRequest=" + getBlocksRequest + "." + "\n\tException=" + throwable.getMessage(); log.error(errorMessage); handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_FAILURE); } else { log.warn("We have stopped already. We ignore that networkNode.sendMessage.onFailure call."); } } }, MoreExecutors.directExecutor()); }