use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.
the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.
@SuppressWarnings("checkstyle:cyclomaticcomplexity")
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, ServerConnection connection) {
Address targetAddress = joinMessage.getAddress();
MemberImpl member = clusterService.getMember(targetAddress);
if (member == null) {
return checkIfUsingAnExistingMemberUuid(joinMessage);
}
if (joinMessage.getUuid().equals(member.getUuid())) {
sendMasterAnswer(targetAddress);
if (clusterService.isMaster() && !isMastershipClaimInProgress()) {
if (logger.isFineEnabled()) {
logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
}
// send members update back to node trying to join again...
boolean deferPartitionProcessing = isMemberRestartingWithPersistence(member.getAttributes());
OnJoinOp preJoinOp = preparePreJoinOps();
OnJoinOp postJoinOp = preparePostJoinOp();
PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
Operation op = new FinalizeJoinOp(member.getUuid(), clusterService.getMembershipManager().getMembersView(), preJoinOp, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, deferPartitionProcessing);
op.setCallerUuid(clusterService.getThisUuid());
invokeClusterOp(op, targetAddress);
}
return true;
}
// after I suspect from the target.
if (clusterService.isMaster() || targetAddress.equals(clusterService.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.suspectMember(member, msg, false);
ServerConnection existing = node.getServer().getConnectionManager(MEMBER).get(targetAddress);
if (existing != connection) {
if (existing != null) {
existing.close(msg, null);
}
node.getServer().getConnectionManager(MEMBER).register(targetAddress, joinMessage.getUuid(), connection);
}
}
return true;
}
use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.
the class MemberProtocolEncoder method onWrite.
@Override
public HandlerStatus onWrite() {
compactOrClear(dst);
try {
if (!clusterProtocolBuffered) {
clusterProtocolBuffered = true;
dst.put(stringToBytes(CLUSTER));
// Return false because ProtocolEncoder is not ready yet; but first we need to flush protocol
return DIRTY;
}
if (!isProtocolBufferDrained()) {
// Return false because ProtocolEncoder is not ready yet; but first we need to flush protocol
return DIRTY;
}
if (encoderCanReplace) {
// replace!
ServerConnection connection = (TcpServerConnection) channel.attributeMap().get(ServerConnection.class);
connection.setConnectionType(ConnectionType.MEMBER);
channel.outboundPipeline().replace(this, outboundHandlers);
}
return CLEAN;
} finally {
upcast(dst).flip();
}
}
use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.
the class TcpServerConnectionManager method register.
@Override
public synchronized boolean register(Address primaryAddress, Address targetAddress, Collection<Address> remoteAddressAliases, UUID remoteUuid, final ServerConnection c, int planeIndex) {
Plane plane = planes[planeIndex];
TcpServerConnection connection = (TcpServerConnection) c;
try {
if (!connection.isAlive()) {
if (logger.isFinestEnabled()) {
logger.finest(connection + " to " + remoteUuid + " is not registered since connection is not active.");
}
return false;
}
connection.setRemoteAddress(primaryAddress);
connection.setRemoteUuid(remoteUuid);
if (!connection.isClient()) {
connection.setErrorHandler(getErrorHandler(primaryAddress, plane.index).reset());
}
registerAddresses(remoteUuid, primaryAddress, targetAddress, remoteAddressAliases);
// handle self connection
if (remoteUuid.equals(serverContext.getThisUuid())) {
connection.close("Connecting to self!", null);
return false;
}
plane.putConnection(remoteUuid, connection);
serverContext.getEventService().executeEventCallback(new StripedRunnable() {
@Override
public void run() {
connectionListeners.forEach(listener -> listener.connectionAdded(connection));
}
@Override
public int getKey() {
return primaryAddress.hashCode();
}
});
return true;
} finally {
if (targetAddress != null) {
plane.removeConnectionInProgress(targetAddress);
}
}
}
use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.
the class UnifiedProtocolDecoder method initChannelForClient.
private void initChannelForClient() {
protocolEncoder.signalEncoderCanReplace();
channel.options().setOption(SO_RCVBUF, clientRcvBuf()).setOption(DIRECT_BUF, false);
ServerConnection connection = (TcpServerConnection) channel.attributeMap().get(ServerConnection.class);
channel.inboundPipeline().replace(this, new ClientMessageDecoder(connection, serverContext.getClientEngine(), props));
}
use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.
the class PacketDispatcher method accept.
@Override
public void accept(Packet packet) {
try {
switch(packet.getPacketType()) {
case OPERATION:
if (packet.isFlagRaised(FLAG_OP_RESPONSE)) {
responseHandler.accept(packet);
} else if (packet.isFlagRaised(FLAG_OP_CONTROL)) {
invocationMonitor.accept(packet);
} else {
operationExecutor.accept(packet);
}
break;
case EVENT:
eventService.accept(packet);
break;
case SERVER_CONTROL:
ServerConnection connection = packet.getConn();
ServerConnectionManager connectionManager = connection.getConnectionManager();
connectionManager.accept(packet);
break;
case JET:
jetServiceBackend.accept(packet);
break;
default:
logger.severe("Header flags [" + Integer.toBinaryString(packet.getFlags()) + "] specify an undefined packet type " + packet.getPacketType().name());
}
} catch (Throwable t) {
inspectOutOfMemoryError(t);
logger.severe("Failed to process: " + packet, t);
}
}
Aggregations