Search in sources :

Example 1 with Connection

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;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) SplitBrainMergeValidationOperation(com.hazelcast.internal.cluster.impl.operations.SplitBrainMergeValidationOperation) Connection(com.hazelcast.nio.Connection) Future(java.util.concurrent.Future) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with Connection

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;
}
Also used : FinalizeJoinOperation(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation) Address(com.hazelcast.nio.Address) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MemberImpl(com.hazelcast.instance.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) Connection(com.hazelcast.nio.Connection) PostJoinOperation(com.hazelcast.internal.cluster.impl.operations.PostJoinOperation) FinalizeJoinOperation(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation) MemberInfoUpdateOperation(com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation) ConfigMismatchOperation(com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOperation) Operation(com.hazelcast.spi.Operation) BeforeJoinCheckFailureOperation(com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOperation) SetMasterOperation(com.hazelcast.internal.cluster.impl.operations.SetMasterOperation) GroupMismatchOperation(com.hazelcast.internal.cluster.impl.operations.GroupMismatchOperation) PostJoinOperation(com.hazelcast.internal.cluster.impl.operations.PostJoinOperation) MasterDiscoveryOperation(com.hazelcast.internal.cluster.impl.operations.MasterDiscoveryOperation) JoinRequestOperation(com.hazelcast.internal.cluster.impl.operations.JoinRequestOperation) AuthenticationFailureOperation(com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOperation)

Example 3 with Connection

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();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Connection(com.hazelcast.nio.Connection)

Example 4 with Connection

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);
    }
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 5 with Connection

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);
    }
}
Also used : Connection(com.hazelcast.nio.Connection)

Aggregations

Connection (com.hazelcast.nio.Connection)59 Address (com.hazelcast.nio.Address)15 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)10 Test (org.junit.Test)9 QuickTest (com.hazelcast.test.annotation.QuickTest)7 IOException (java.io.IOException)7 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)6 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)6 AssertTask (com.hazelcast.test.AssertTask)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)5 Packet (com.hazelcast.nio.Packet)5 ClientClusterService (com.hazelcast.client.spi.ClientClusterService)4 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)4 Member (com.hazelcast.core.Member)4 Node (com.hazelcast.instance.Node)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 EventHandler (com.hazelcast.client.spi.EventHandler)2 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)2