Search in sources :

Example 1 with ServerConnection

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;
}
Also used : Address(com.hazelcast.cluster.Address) OnJoinOp(com.hazelcast.internal.cluster.impl.operations.OnJoinOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ServerConnection(com.hazelcast.internal.server.ServerConnection) Operation(com.hazelcast.spi.impl.operationservice.Operation) FinalizeJoinOp(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp)

Example 2 with ServerConnection

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();
    }
}
Also used : ServerConnection(com.hazelcast.internal.server.ServerConnection)

Example 3 with ServerConnection

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);
        }
    }
}
Also used : REST_CLIENT(com.hazelcast.internal.nio.ConnectionType.REST_CLIENT) Address(com.hazelcast.cluster.Address) TCP_TAG_ENDPOINT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_TAG_ENDPOINT) ServerConnection(com.hazelcast.internal.server.ServerConnection) TimeoutException(java.util.concurrent.TimeoutException) Packet(com.hazelcast.internal.nio.Packet) TCP_PREFIX_CONNECTION(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_PREFIX_CONNECTION) TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT) Future(java.util.concurrent.Future) SocketChannel(java.nio.channels.SocketChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) ChannelInitializer(com.hazelcast.internal.networking.ChannelInitializer) TCP_DISCRIMINATOR_BINDADDRESS(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_BINDADDRESS) ServerContext(com.hazelcast.internal.server.ServerContext) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) IOUtil.close(com.hazelcast.internal.nio.IOUtil.close) UUID(java.util.UUID) EndpointConfig(com.hazelcast.config.EndpointConfig) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) TCP_METRIC_CLIENT_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_CLIENT_COUNT) Arrays.stream(java.util.Arrays.stream) MANDATORY(com.hazelcast.internal.metrics.ProbeLevel.MANDATORY) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TCP_DISCRIMINATOR_ENDPOINT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_ENDPOINT) Function(java.util.function.Function) ProtocolType(com.hazelcast.instance.ProtocolType) IOUtil.setChannelOptions(com.hazelcast.internal.nio.IOUtil.setChannelOptions) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) NetworkStats(com.hazelcast.internal.server.NetworkStats) Networking(com.hazelcast.internal.networking.Networking) Nonnull(javax.annotation.Nonnull) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) IOUtil(com.hazelcast.internal.nio.IOUtil) COUNT(com.hazelcast.internal.metrics.ProbeUnit.COUNT) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) StripedRunnable(com.hazelcast.internal.util.executor.StripedRunnable) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MEMCACHE_CLIENT(com.hazelcast.internal.nio.ConnectionType.MEMCACHE_CLIENT) IOException(java.io.IOException) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) Channel(com.hazelcast.internal.networking.Channel) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) TCP_METRIC_ENDPOINT_MANAGER_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_COUNT) Collections(java.util.Collections) TCP_METRIC_TEXT_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_TEXT_COUNT) StripedRunnable(com.hazelcast.internal.util.executor.StripedRunnable)

Example 4 with ServerConnection

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));
}
Also used : ClientMessageDecoder(com.hazelcast.client.impl.protocol.util.ClientMessageDecoder) ServerConnection(com.hazelcast.internal.server.ServerConnection)

Example 5 with ServerConnection

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);
    }
}
Also used : ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) ServerConnection(com.hazelcast.internal.server.ServerConnection)

Aggregations

ServerConnection (com.hazelcast.internal.server.ServerConnection)22 Address (com.hazelcast.cluster.Address)6 ClientMessageDecoder (com.hazelcast.client.impl.protocol.util.ClientMessageDecoder)2 InboundHandler (com.hazelcast.internal.networking.InboundHandler)2 OutboundHandler (com.hazelcast.internal.networking.OutboundHandler)2 ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)2 TcpServerConnection (com.hazelcast.internal.server.tcp.TcpServerConnection)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 ClientEndpointImpl (com.hazelcast.client.impl.ClientEndpointImpl)1 ClientMessageEncoder (com.hazelcast.client.impl.protocol.util.ClientMessageEncoder)1 ClusterState (com.hazelcast.cluster.ClusterState)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 EndpointConfig (com.hazelcast.config.EndpointConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 CPGroup (com.hazelcast.cp.CPGroup)1