use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class AbstractJoiner method sendSplitBrainJoinMessage.
protected SplitBrainJoinMessage sendSplitBrainJoinMessage(Address target) {
if (logger.isFineEnabled()) {
logger.fine("Sending SplitBrainJoinMessage to " + target);
}
Connection conn = node.connectionManager.getOrConnect(target, true);
long timeout = SPLIT_BRAIN_CONN_TIMEOUT;
while (conn == null) {
timeout -= SPLIT_BRAIN_SLEEP_TIME;
if (timeout < 0) {
return null;
}
try {
//noinspection BusyWait
Thread.sleep(SPLIT_BRAIN_SLEEP_TIME);
} catch (InterruptedException e) {
EmptyStatement.ignore(e);
return null;
}
conn = node.connectionManager.getConnection(target);
}
NodeEngine nodeEngine = node.nodeEngine;
Future future = nodeEngine.getOperationService().createInvocationBuilder(ClusterServiceImpl.SERVICE_NAME, new SplitBrainMergeValidationOperation(node.createSplitBrainJoinMessage()), target).setTryCount(1).invoke();
try {
return (SplitBrainJoinMessage) future.get(SPLIT_BRAIN_JOIN_CHECK_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (TimeoutException e) {
logger.fine("Timeout during join check!", e);
} catch (Exception e) {
logger.warning("Error during join check!", e);
}
return null;
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, Connection connection) {
Address target = joinMessage.getAddress();
MemberImpl member = clusterService.getMember(target);
if (member == null) {
return checkIfUsingAnExistingMemberUuid(joinMessage);
}
if (joinMessage.getUuid().equals(member.getUuid())) {
sendMasterAnswer(target);
if (node.isMaster()) {
if (logger.isFineEnabled()) {
logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
}
// send members update back to node trying to join again...
Operation[] postJoinOps = nodeEngine.getPostJoinOperations();
boolean isPostJoinOperation = postJoinOps != null && postJoinOps.length > 0;
PostJoinOperation postJoinOp = isPostJoinOperation ? new PostJoinOperation(postJoinOps) : null;
PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
List<MemberInfo> memberInfos = createMemberInfoList(clusterService.getMemberImpls());
Operation operation = new FinalizeJoinOperation(member.getUuid(), memberInfos, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, false);
nodeEngine.getOperationService().send(operation, target);
}
return true;
}
// and wants to join back, so drop old member and process join request if this node becomes master
if (node.isMaster() || target.equals(node.getMasterAddress())) {
String msg = format("New join request has been received from an existing endpoint %s." + " Removing old member and processing join request...", member);
logger.warning(msg);
clusterService.doRemoveAddress(target, msg, false);
Connection existing = node.connectionManager.getConnection(target);
if (existing != connection) {
if (existing != null) {
existing.close(msg, null);
}
node.connectionManager.registerConnection(target, connection);
}
return false;
}
return true;
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class MemberInfoUpdateOperation method getConnectionEndpointOrThisAddress.
final Address getConnectionEndpointOrThisAddress() {
ClusterServiceImpl clusterService = getService();
NodeEngineImpl nodeEngine = clusterService.getNodeEngine();
Node node = nodeEngine.getNode();
Connection conn = getConnection();
return conn != null ? conn.getEndPoint() : node.getThisAddress();
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class FirewallingMockConnectionManager method getOrConnect.
@Override
public synchronized Connection getOrConnect(Address address) {
Connection connection = getConnection(address);
if (connection != null && connection.isAlive()) {
return connection;
}
if (blockedAddresses.contains(address)) {
connection = new DroppingConnection(address, this);
registerConnection(address, connection);
return connection;
} else {
return super.getOrConnect(address);
}
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class FirewallingMockConnectionManager method block.
public synchronized void block(Address address) {
blockedAddresses.add(address);
Connection connection = getConnection(address);
if (connection != null) {
connection.close("Blocked by connection manager", null);
}
}
Aggregations