Combine if/else branches. Improve comments and variables

This commit is contained in:
chimp1984 2020-08-31 10:38:46 -05:00
parent bc802c861d
commit f7951d5943
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -289,18 +289,14 @@ public class BroadcastHandler implements PeerManager.Listener {
.map(Broadcaster.BroadcastRequest::getListener) .map(Broadcaster.BroadcastRequest::getListener)
.forEach(listener -> listener.onSufficientlyBroadcast(broadcastRequests)); .forEach(listener -> listener.onSufficientlyBroadcast(broadcastRequests));
} else { } else {
// Number of open requests to peers is less than we need to reach numOfCompletedBroadcastsTarget. // We check if number of open requests to peers is less than we need to reach numOfCompletedBroadcastsTarget.
// Thus we never can reach required resilience as too many numOfFailedBroadcasts occurred. // Thus we never can reach required resilience as too many numOfFailedBroadcasts occurred.
int openRequests = numPeersForBroadcast - numOfCompletedBroadcasts - numOfFailedBroadcasts; int maxPossibleSuccessCases = numPeersForBroadcast - numOfFailedBroadcasts;
int maxPossibleSuccessCases = openRequests + numOfCompletedBroadcasts;
// We subtract 1 as we want to have it called only once, with a < comparision we would trigger repeatedly. // We subtract 1 as we want to have it called only once, with a < comparision we would trigger repeatedly.
if (maxPossibleSuccessCases == numOfCompletedBroadcastsTarget - 1) { boolean notEnoughSucceededOrOpen = maxPossibleSuccessCases == numOfCompletedBroadcastsTarget - 1;
broadcastRequests.stream() // We did not reach resilience level and timeout prevents to reach it later
.filter(broadcastRequest -> broadcastRequest.getListener() != null) boolean timeoutAndNotEnoughSucceeded = timeoutTriggered && numOfCompletedBroadcasts < numOfCompletedBroadcastsTarget;
.map(Broadcaster.BroadcastRequest::getListener) if (notEnoughSucceededOrOpen || timeoutAndNotEnoughSucceeded) {
.forEach(listener -> listener.onNotSufficientlyBroadcast(numOfCompletedBroadcasts, numOfFailedBroadcasts));
} else if (timeoutTriggered && numOfCompletedBroadcasts < numOfCompletedBroadcastsTarget) {
// We did not reach resilience level and timeout prevents to reach it later
broadcastRequests.stream() broadcastRequests.stream()
.filter(broadcastRequest -> broadcastRequest.getListener() != null) .filter(broadcastRequest -> broadcastRequest.getListener() != null)
.map(Broadcaster.BroadcastRequest::getListener) .map(Broadcaster.BroadcastRequest::getListener)