Search in sources :

Example 16 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class ClientHeartbeatMonitor method monitor.

private void monitor(ClientEndpoint clientEndpoint) {
    Connection connection = clientEndpoint.getConnection();
    long lastTimePacketReceived = connection.lastReadTimeMillis();
    long timeoutInMillis = SECONDS.toMillis(heartbeatTimeoutSeconds);
    long currentTimeMillis = Clock.currentTimeMillis();
    if (lastTimePacketReceived + timeoutInMillis < currentTimeMillis) {
        String message = "Client heartbeat is timed out, closing connection to " + connection + ". Now: " + timeToString(currentTimeMillis) + ". LastTimePacketReceived: " + timeToString(lastTimePacketReceived);
        connection.close(message, null);
    }
}
Also used : Connection(com.hazelcast.internal.nio.Connection) StringUtil.timeToString(com.hazelcast.internal.util.StringUtil.timeToString)

Example 17 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class MembersUpdateOp method getConnectionEndpointOrThisAddress.

final Address getConnectionEndpointOrThisAddress() {
    ClusterServiceImpl clusterService = getService();
    NodeEngineImpl nodeEngine = clusterService.getNodeEngine();
    Node node = nodeEngine.getNode();
    Connection conn = getConnection();
    return conn != null ? conn.getRemoteAddress() : node.getThisAddress();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Connection(com.hazelcast.internal.nio.Connection)

Example 18 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class AuthenticationBaseMessageTask method prepareUnauthenticatedClientMessage.

private ClientMessage prepareUnauthenticatedClientMessage() {
    boolean clientFailoverSupported = nodeEngine.getNode().getNodeExtension().isClientFailoverSupported();
    Connection connection = endpoint.getConnection();
    logger.warning("Received auth from " + connection + " with clientUuid " + clientUuid + " and clientName " + clientName + ", authentication failed");
    byte status = CREDENTIALS_FAILED.getId();
    return encodeAuth(status, null, null, serializationService.getVersion(), clientEngine.getPartitionService().getPartitionCount(), clientEngine.getClusterService().getClusterId(), clientFailoverSupported);
}
Also used : Connection(com.hazelcast.internal.nio.Connection) ServerConnection(com.hazelcast.internal.server.ServerConnection)

Example 19 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class AuthenticationBaseMessageTask method authenticate.

private AuthenticationStatus authenticate(SecurityContext securityContext) {
    String nodeClusterName = nodeEngine.getConfig().getClusterName();
    if (!nodeClusterName.equals(clusterName)) {
        return CREDENTIALS_FAILED;
    }
    Connection connection = endpoint.getConnection();
    Boolean passed = Boolean.FALSE;
    try {
        LoginContext lc = securityContext.createClientLoginContext(clusterName, credentials, connection);
        lc.login();
        endpoint.setLoginContext(lc);
        passed = Boolean.TRUE;
        return AUTHENTICATED;
    } catch (LoginException e) {
        logger.warning(e);
        return CREDENTIALS_FAILED;
    } finally {
        nodeEngine.getNode().getNodeExtension().getAuditlogService().eventBuilder(AuditlogTypeIds.AUTHENTICATION_CLIENT).message("Client connection authentication.").addParameter("connection", connection).addParameter("credentials", credentials).addParameter("passed", passed).log();
    }
}
Also used : LoginContext(javax.security.auth.login.LoginContext) Connection(com.hazelcast.internal.nio.Connection) ServerConnection(com.hazelcast.internal.server.ServerConnection) LoginException(javax.security.auth.login.LoginException)

Example 20 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class ClientClusterServiceImpl method detectMembershipEvents.

private List<MembershipEvent> detectMembershipEvents(Collection<Member> prevMembers, Set<Member> currentMembers) {
    List<Member> newMembers = new LinkedList<>();
    Set<Member> deadMembers = new HashSet<>(prevMembers);
    for (Member member : currentMembers) {
        if (!deadMembers.remove(member)) {
            newMembers.add(member);
        }
    }
    List<MembershipEvent> events = new LinkedList<>();
    for (Member member : deadMembers) {
        events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_REMOVED, currentMembers));
        Connection connection = connectionManager.getConnection(member.getUuid());
        if (connection != null) {
            connection.close(null, new TargetDisconnectedException("The client has closed the connection to this member," + " after receiving a member left event from the cluster. " + connection));
        }
    }
    for (Member member : newMembers) {
        events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_ADDED, currentMembers));
    }
    if (events.size() != 0) {
        MemberListSnapshot snapshot = memberListSnapshot.get();
        if (snapshot.members.values().size() != 0) {
            logger.info(membersString(snapshot));
        }
    }
    return events;
}
Also used : InitialMembershipEvent(com.hazelcast.cluster.InitialMembershipEvent) MembershipEvent(com.hazelcast.cluster.MembershipEvent) Connection(com.hazelcast.internal.nio.Connection) TcpClientConnection(com.hazelcast.client.impl.connection.tcp.TcpClientConnection) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Aggregations

Connection (com.hazelcast.internal.nio.Connection)41 Test (org.junit.Test)14 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)8 ServerConnection (com.hazelcast.internal.server.ServerConnection)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)6 Address (com.hazelcast.cluster.Address)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)5 Member (com.hazelcast.cluster.Member)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ConnectionListener (com.hazelcast.internal.nio.ConnectionListener)5 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)4 ILogger (com.hazelcast.logging.ILogger)4 QueryId (com.hazelcast.sql.impl.QueryId)4 Map (java.util.Map)4 UUID (java.util.UUID)4 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)3 TargetDisconnectedException (com.hazelcast.spi.exception.TargetDisconnectedException)3 IOException (java.io.IOException)3