Search in sources :

Example 6 with ServerConnection

use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.

the class OperationRunnerImpl method run.

@Override
public boolean run(Packet packet) throws Exception {
    long startNanos = System.nanoTime();
    boolean publishCurrentTask = publishCurrentTask();
    if (publishCurrentTask) {
        currentTask = packet;
    }
    ServerConnection connection = packet.getConn();
    Address caller = connection.getRemoteAddress();
    UUID callerUuid = connection.getRemoteUuid();
    Operation op = null;
    try {
        Object object = nodeEngine.toObject(packet);
        op = (Operation) object;
        op.setNodeEngine(nodeEngine);
        setCallerAddress(op, caller);
        setConnection(op, connection);
        setCallerUuidIfNotSet(op, callerUuid);
        setOperationResponseHandler(op);
        if (!ensureValidMember(op)) {
            return false;
        }
        if (publishCurrentTask) {
            currentTask = null;
        }
        return run(op, startNanos);
    } catch (Throwable throwable) {
        // If exception happens we need to extract the callId from the bytes directly!
        long callId = extractOperationCallId(packet);
        outboundResponseHandler.send(connection.getConnectionManager(), caller, new ErrorResponse(throwable, callId, packet.isUrgent()));
        logOperationDeserializationException(throwable, callId);
        throw ExceptionUtil.rethrow(throwable);
    } finally {
        if (op != null) {
            op.clearThreadContext();
        }
        if (publishCurrentTask) {
            currentTask = null;
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.impl.operationservice.OperationAccessor.setCallerAddress) ServerConnection(com.hazelcast.internal.server.ServerConnection) Operations.isJoinOperation(com.hazelcast.spi.impl.operationservice.Operations.isJoinOperation) ReadonlyOperation(com.hazelcast.spi.impl.operationservice.ReadonlyOperation) BlockingOperation(com.hazelcast.spi.impl.operationservice.BlockingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) Operations.isMigrationOperation(com.hazelcast.spi.impl.operationservice.Operations.isMigrationOperation) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operations.isWanReplicationOperation(com.hazelcast.spi.impl.operationservice.Operations.isWanReplicationOperation) UUID(java.util.UUID) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 7 with ServerConnection

use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.

the class ClientEngineImpl method bind.

@Override
public boolean bind(final ClientEndpoint endpoint) {
    if (!isClientAllowed(endpoint)) {
        return false;
    }
    ServerConnection conn = endpoint.getConnection();
    InetSocketAddress socketAddress = conn.getRemoteSocketAddress();
    // socket address can be null if connection closed before bind
    if (socketAddress != null) {
        conn.setRemoteAddress(new Address(socketAddress));
    }
    if (endpointManager.registerEndpoint(endpoint)) {
        // will be cleaned up by ClientHeartbeatMonitor#cleanupEndpointsWithDeadConnections later.
        if (conn.getRemoteAddress() != null && endpoint.getUuid() != null) {
            node.getServer().getConnectionManager(CLIENT).register(conn.getRemoteAddress(), endpoint.getUuid(), conn);
        }
    }
    // Second check to catch concurrent change done via applySelector
    if (!isClientAllowed(endpoint)) {
        endpointManager.removeEndpoint(endpoint);
        return false;
    }
    return true;
}
Also used : Address(com.hazelcast.cluster.Address) InetSocketAddress(java.net.InetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) ServerConnection(com.hazelcast.internal.server.ServerConnection)

Example 8 with ServerConnection

use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.

the class ClientEndpointManagerImpl method registerEndpoint.

@Override
public boolean registerEndpoint(ClientEndpoint endpoint) {
    checkNotNull(endpoint, "endpoint can't be null");
    final ServerConnection conn = endpoint.getConnection();
    if (endpoints.putIfAbsent(conn, endpoint) != null) {
        return false;
    } else {
        totalRegistrations.inc();
        ClientEvent event = new ClientEvent(endpoint.getUuid(), ClientEventType.CONNECTED, endpoint.getSocketAddress(), endpoint.getClientType(), endpoint.getName(), endpoint.getLabels());
        sendClientEvent(event);
        return true;
    }
}
Also used : ServerConnection(com.hazelcast.internal.server.ServerConnection)

Example 9 with ServerConnection

use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.

the class IOBalancerStressTest method debug.

private StringBuilder debug(HazelcastInstance hz) {
    TcpServer networkingService = (TcpServer) getNode(hz).getServer();
    NioNetworking networking = (NioNetworking) networkingService.getNetworking();
    ServerConnectionManager cm = getNode(hz).getServer().getConnectionManager(EndpointQualifier.MEMBER);
    StringBuilder sb = new StringBuilder();
    sb.append("in owners\n");
    for (NioThread in : networking.getInputThreads()) {
        sb.append(in).append(": ").append(in.getEventCount()).append("\n");
        for (ServerConnection connection : cm.getConnections()) {
            TcpServerConnection tcpConnection = (TcpServerConnection) connection;
            NioInboundPipeline inboundPipeline = ((NioChannel) tcpConnection.getChannel()).inboundPipeline();
            if (inboundPipeline.owner() == in) {
                sb.append("\t").append(inboundPipeline).append(" load: ").append(inboundPipeline.load()).append("\n");
            }
        }
    }
    sb.append("out owners\n");
    for (NioThread in : networking.getOutputThreads()) {
        sb.append(in).append(": ").append(in.getEventCount()).append("\n");
        for (ServerConnection connection : cm.getConnections()) {
            TcpServerConnection tcpConnection = (TcpServerConnection) connection;
            NioOutboundPipeline outboundPipeline = ((NioChannel) tcpConnection.getChannel()).outboundPipeline();
            if (outboundPipeline.owner() == in) {
                sb.append("\t").append(outboundPipeline).append(" load:").append(outboundPipeline.load()).append("\n");
            }
        }
    }
    return sb;
}
Also used : NioThread(com.hazelcast.internal.networking.nio.NioThread) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) NioChannel(com.hazelcast.internal.networking.nio.NioChannel) ServerConnection(com.hazelcast.internal.server.ServerConnection) TcpServerConnection(com.hazelcast.internal.server.tcp.TcpServerConnection) NioNetworking(com.hazelcast.internal.networking.nio.NioNetworking) NioOutboundPipeline(com.hazelcast.internal.networking.nio.NioOutboundPipeline) TcpServer(com.hazelcast.internal.server.tcp.TcpServer) TcpServerConnection(com.hazelcast.internal.server.tcp.TcpServerConnection) NioInboundPipeline(com.hazelcast.internal.networking.nio.NioInboundPipeline)

Example 10 with ServerConnection

use of com.hazelcast.internal.server.ServerConnection in project hazelcast by hazelcast.

the class AuthenticationBaseMessageTask method prepareAuthenticatedClientMessage.

private ClientMessage prepareAuthenticatedClientMessage() {
    ServerConnection connection = endpoint.getConnection();
    setConnectionType();
    endpoint.authenticated(clientUuid, credentials, clientVersion, clientMessage.getCorrelationId(), clientName, labels);
    validateNodeStart();
    final UUID clusterId = clientEngine.getClusterService().getClusterId();
    // see AbstractMessageTask#acceptOnIncompleteStart
    if (clusterId == null) {
        throw new HazelcastInstanceNotActiveException("Hazelcast instance is not ready yet!");
    }
    if (!clientEngine.bind(endpoint)) {
        return prepareNotAllowedInCluster();
    }
    logger.info("Received auth from " + connection + ", successfully authenticated, clientUuid: " + clientUuid + ", client name: " + clientName + ", client version: " + clientVersion);
    final Address thisAddress = clientEngine.getThisAddress();
    UUID uuid = clientEngine.getClusterService().getLocalMember().getUuid();
    byte status = AUTHENTICATED.getId();
    boolean clientFailoverSupported = nodeEngine.getNode().getNodeExtension().isClientFailoverSupported();
    return encodeAuth(status, thisAddress, uuid, serializationService.getVersion(), clientEngine.getPartitionService().getPartitionCount(), clusterId, clientFailoverSupported);
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) Address(com.hazelcast.cluster.Address) ServerConnection(com.hazelcast.internal.server.ServerConnection) UUID(java.util.UUID)

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