Resolves checkstyle errors for api-gateway, lazy-loading, leader-election (#1066)

* Reduces checkstyle errors in lazy-loading

* Reduces checkstyle errors in leader-election

* Reduces checkstyle errors in api-gateway
This commit is contained in:
Anurag Agarwal
2019-11-10 22:43:40 +05:30
committed by Ilkka Seppälä
parent 7f06f3b78c
commit eae09fc07e
30 changed files with 188 additions and 172 deletions
@@ -27,13 +27,12 @@ import com.iluwatar.leaderelection.AbstractMessageManager;
import com.iluwatar.leaderelection.Instance;
import com.iluwatar.leaderelection.Message;
import com.iluwatar.leaderelection.MessageType;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Implementation of BullyMessageManager
* Implementation of BullyMessageManager.
*/
public class BullyMessageManager extends AbstractMessageManager {
@@ -46,6 +45,7 @@ public class BullyMessageManager extends AbstractMessageManager {
/**
* Send heartbeat message to current leader instance to check the health.
*
* @param leaderId leaderID
* @return {@code true} if the leader is alive.
*/
@@ -58,8 +58,9 @@ public class BullyMessageManager extends AbstractMessageManager {
/**
* Send election message to all the instances with smaller ID.
*
* @param currentId Instance ID of which sends this message.
* @param content Election message content.
* @param content Election message content.
* @return {@code true} if no alive instance has smaller ID, so that the election is accepted.
*/
@Override
@@ -70,29 +71,31 @@ public class BullyMessageManager extends AbstractMessageManager {
} else {
Message electionMessage = new Message(MessageType.ELECTION_INVOKE, "");
candidateList.stream()
.forEach((i) -> instanceMap.get(i).onMessage(electionMessage));
.forEach((i) -> instanceMap.get(i).onMessage(electionMessage));
return false;
}
}
/**
* Send leader message to all the instances to notify the new leader.
*
* @param currentId Instance ID of which sends this message.
* @param leaderId Leader message content.
* @param leaderId Leader message content.
* @return {@code true} if the message is accepted.
*/
@Override
public boolean sendLeaderMessage(int currentId, int leaderId) {
Message leaderMessage = new Message(MessageType.LEADER, String.valueOf(leaderId));
instanceMap.keySet()
.stream()
.filter((i) -> i != currentId)
.forEach((i) -> instanceMap.get(i).onMessage(leaderMessage));
.stream()
.filter((i) -> i != currentId)
.forEach((i) -> instanceMap.get(i).onMessage(leaderMessage));
return false;
}
/**
* Send heartbeat invoke message to the next instance.
*
* @param currentId Instance ID of which sends this message.
*/
@Override
@@ -104,14 +107,15 @@ public class BullyMessageManager extends AbstractMessageManager {
/**
* Find all the alive instances with smaller ID than current instance.
*
* @param currentId ID of current instance.
* @return ID list of all the candidate instance.
*/
private List<Integer> findElectionCandidateInstanceList(int currentId) {
return instanceMap.keySet()
.stream()
.filter((i) -> i < currentId && instanceMap.get(i).isAlive())
.collect(Collectors.toList());
.stream()
.filter((i) -> i < currentId && instanceMap.get(i).isAlive())
.collect(Collectors.toList());
}
}