try {
validJoinRequest = validateJoinMessage(joinMessage);
} catch (Exception e) {
validJoinRequest = false;
}
final Connection conn = joinRequest.getConnection();
if (validJoinRequest) {
final MemberImpl member = getMember(joinMessage.getAddress());
if (member != null) {
if (joinMessage.getUuid().equals(member.getUuid())) {
if (logger.isFinestEnabled()) {
String message = "Ignoring join request, member already exists.. => " + joinMessage;
logger.finest(message);
}
// send members update back to node trying to join again...
nodeEngine.getOperationService().send(new MemberInfoUpdateOperation(createMemberInfos(getMemberList(), true), getClusterTime(), false),
member.getAddress());
return;
}
// If this node is master then remove old member and process join request.
// If requesting address is equal to master node's address, that means master node
// somehow disconnected and wants to join back.
// So drop old member and process join request if this node becomes master.
if (node.isMaster() || member.getAddress().equals(node.getMasterAddress())) {
logger.warning("New join request has been received from an existing endpoint! => " + member
+ " Removing old member and processing join request...");
doRemoveAddress(member.getAddress(), false);
}
}
final boolean multicastEnabled = node.getConfig().getNetworkConfig().getJoin().getMulticastConfig().isEnabled();
if (!multicastEnabled && node.isActive() && node.joined() && node.getMasterAddress() != null && !node.isMaster()) {
sendMasterAnswer(joinMessage);
}
if (node.isMaster() && node.joined() && node.isActive()) {
final MemberInfo newMemberInfo = new MemberInfo(joinMessage.getAddress(), joinMessage.getUuid(), joinMessage.getAttributes());
if (node.securityContext != null && !setJoins.contains(newMemberInfo)) {
final Credentials cr = joinMessage.getCredentials();
ILogger securityLogger = node.loggingService.getLogger("com.hazelcast.security");
if (cr == null) {
securityLogger.severe("Expecting security credentials " +
"but credentials could not be found in JoinRequest!");
nodeEngine.getOperationService().send(new AuthenticationFailureOperation(), joinMessage.getAddress());
return;
} else {
try {
LoginContext lc = node.securityContext.createMemberLoginContext(cr);
lc.login();
} catch (LoginException e) {
securityLogger.severe("Authentication has failed for " + cr.getPrincipal()
+ '@' + cr.getEndpoint() + " => (" + e.getMessage() +
")");
securityLogger.finest(e);
nodeEngine.getOperationService().send(new AuthenticationFailureOperation(), joinMessage.getAddress());
return;
}
}
}
if (!joinInProgress) {
if (firstJoinRequest != 0 && now - firstJoinRequest >= maxWaitSecondsBeforeJoin * 1000) {
startJoin();
} else {
if (setJoins.add(newMemberInfo)) {
sendMasterAnswer(joinMessage);
if (firstJoinRequest == 0) {
firstJoinRequest = now;
}
if (now - firstJoinRequest < maxWaitSecondsBeforeJoin * 1000) {
timeToStartJoin = now + waitMillisBeforeJoin;
}
}
if (now > timeToStartJoin) {
startJoin();
}
}
}
}
} else {
conn.close();
}
} finally {
lock.unlock();
}
}