Fixed most reported issues by SonarCloud.
This commit is contained in:
@@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory;
|
||||
public class BullyInstance extends AbstractInstance {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BullyInstance.class);
|
||||
private static final String INSTANCE = "Instance ";
|
||||
|
||||
/**
|
||||
* Constructor of BullyInstance.
|
||||
@@ -59,20 +60,20 @@ public class BullyInstance extends AbstractInstance {
|
||||
try {
|
||||
boolean isLeaderAlive = messageManager.sendHeartbeatMessage(leaderId);
|
||||
if (isLeaderAlive) {
|
||||
LOGGER.info("Instance " + localId + "- Leader is alive.");
|
||||
LOGGER.info(INSTANCE + localId + "- Leader is alive.");
|
||||
Thread.sleep(HEARTBEAT_INTERVAL);
|
||||
messageManager.sendHeartbeatInvokeMessage(localId);
|
||||
} else {
|
||||
LOGGER.info("Instance " + localId + "- Leader is not alive. Start election.");
|
||||
LOGGER.info(INSTANCE + localId + "- Leader is not alive. Start election.");
|
||||
boolean electionResult =
|
||||
messageManager.sendElectionMessage(localId, String.valueOf(localId));
|
||||
if (electionResult) {
|
||||
LOGGER.info("Instance " + localId + "- Succeed in election. Start leader notification.");
|
||||
LOGGER.info(INSTANCE + localId + "- Succeed in election. Start leader notification.");
|
||||
messageManager.sendLeaderMessage(localId, localId);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.info("Instance " + localId + "- Interrupted.");
|
||||
LOGGER.info(INSTANCE + localId + "- Interrupted.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,10 +85,10 @@ public class BullyInstance extends AbstractInstance {
|
||||
@Override
|
||||
protected void handleElectionInvokeMessage() {
|
||||
if (!isLeader()) {
|
||||
LOGGER.info("Instance " + localId + "- Start election.");
|
||||
LOGGER.info(INSTANCE + localId + "- Start election.");
|
||||
boolean electionResult = messageManager.sendElectionMessage(localId, String.valueOf(localId));
|
||||
if (electionResult) {
|
||||
LOGGER.info("Instance " + localId + "- Succeed in election. Start leader notification.");
|
||||
LOGGER.info(INSTANCE + localId + "- Succeed in election. Start leader notification.");
|
||||
leaderId = localId;
|
||||
messageManager.sendLeaderMessage(localId, localId);
|
||||
messageManager.sendHeartbeatInvokeMessage(localId);
|
||||
@@ -101,25 +102,25 @@ public class BullyInstance extends AbstractInstance {
|
||||
@Override
|
||||
protected void handleLeaderMessage(Message message) {
|
||||
leaderId = Integer.valueOf(message.getContent());
|
||||
LOGGER.info("Instance " + localId + " - Leader update done.");
|
||||
LOGGER.info(INSTANCE + localId + " - Leader update done.");
|
||||
}
|
||||
|
||||
private boolean isLeader() {
|
||||
return localId == leaderId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not used in Bully instance.
|
||||
*/
|
||||
@Override
|
||||
protected void handleLeaderInvokeMessage() {
|
||||
// Not used in Bully Instance
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleHeartbeatMessage(Message message) {
|
||||
// Not used in Bully Instance
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleElectionMessage(Message message) {
|
||||
// Not used in Bully Instance
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user