Search in sources :

Example 36 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class FinalizeJoinOperation method sendPostJoinOperations.

private void sendPostJoinOperations() {
    final ClusterServiceImpl clusterService = getService();
    final NodeEngineImpl nodeEngine = clusterService.getNodeEngine();
    // Post join operations must be lock free; means no locks at all;
    // no partition locks, no key-based locks, no service level locks!
    final Operation[] postJoinOperations = nodeEngine.getPostJoinOperations();
    final OperationService operationService = nodeEngine.getOperationService();
    if (postJoinOperations != null && postJoinOperations.length > 0) {
        final Collection<Member> members = clusterService.getMembers();
        for (Member member : members) {
            if (!member.localMember()) {
                PostJoinOperation operation = new PostJoinOperation(postJoinOperations);
                operationService.createInvocationBuilder(ClusterServiceImpl.SERVICE_NAME, operation, member.getAddress()).setTryCount(POST_JOIN_TRY_COUNT).invoke();
            }
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Operation(com.hazelcast.spi.Operation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Example 37 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class ClusterInfoTest method all_nodes_should_have_the_same_cluster_start_time_and_cluster_id.

@Test
public void all_nodes_should_have_the_same_cluster_start_time_and_cluster_id() throws Exception {
    HazelcastInstance h1 = factory.newHazelcastInstance();
    HazelcastInstance h2 = factory.newHazelcastInstance();
    HazelcastInstance h3 = factory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    Node node1 = TestUtil.getNode(h1);
    Node node2 = TestUtil.getNode(h2);
    Node node3 = TestUtil.getNode(h3);
    //All nodes should have same startTime
    final ClusterServiceImpl clusterService = node1.getClusterService();
    long node1ClusterStartTime = clusterService.getClusterClock().getClusterStartTime();
    long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();
    String node1ClusterId = clusterService.getClusterId();
    assertTrue(clusterUpTime > 0);
    assertNotEquals(node1ClusterStartTime, Long.MIN_VALUE);
    assertEquals(node1ClusterStartTime, node2.getClusterService().getClusterClock().getClusterStartTime());
    assertEquals(node1ClusterStartTime, node3.getClusterService().getClusterClock().getClusterStartTime());
    //All nodes should have same clusterId
    assertNotNull(node1ClusterId);
    assertEquals(node1ClusterId, node2.getClusterService().getClusterId());
    assertEquals(node1ClusterId, node3.getClusterService().getClusterId());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 38 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class ClusterInfoTest method all_nodes_should_have_the_same_cluster_start_time_and_id_after_master_shutdown_and_new_node_join.

@Test
public void all_nodes_should_have_the_same_cluster_start_time_and_id_after_master_shutdown_and_new_node_join() {
    HazelcastInstance h1 = factory.newHazelcastInstance();
    HazelcastInstance h2 = factory.newHazelcastInstance();
    HazelcastInstance h3 = factory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    Node node1 = TestUtil.getNode(h1);
    final ClusterServiceImpl clusterService = node1.getClusterService();
    long node1ClusterStartTime = clusterService.getClusterClock().getClusterStartTime();
    long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();
    String node1ClusterId = clusterService.getClusterId();
    assertTrue(clusterUpTime > 0);
    assertTrue(node1.isMaster());
    h1.shutdown();
    assertClusterSizeEventually(2, h2);
    HazelcastInstance h4 = factory.newHazelcastInstance();
    Node node2 = TestUtil.getNode(h2);
    Node node3 = TestUtil.getNode(h3);
    Node node4 = TestUtil.getNode(h4);
    //All nodes should have the same cluster start time
    assertNotEquals(node1ClusterStartTime, Long.MIN_VALUE);
    assertEquals(node1ClusterStartTime, node2.getClusterService().getClusterClock().getClusterStartTime());
    assertEquals(node1ClusterStartTime, node3.getClusterService().getClusterClock().getClusterStartTime());
    assertEquals(node1ClusterStartTime, node4.getClusterService().getClusterClock().getClusterStartTime());
    //All nodes should have the same clusterId
    assertEquals(node1ClusterId, node2.getClusterService().getClusterId());
    assertEquals(node1ClusterId, node3.getClusterService().getClusterId());
    assertEquals(node1ClusterId, node4.getClusterService().getClusterId());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 39 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class LiteMemberJoinTest method reconnect.

private void reconnect(final HazelcastInstance instance1, final HazelcastInstance instance2) {
    final Node node1 = getNode(instance1);
    final Node node2 = getNode(instance2);
    final ClusterServiceImpl clusterService = node1.getClusterService();
    clusterService.merge(node2.address);
}
Also used : Node(com.hazelcast.instance.Node) HazelcastTestSupport.getNode(com.hazelcast.test.HazelcastTestSupport.getNode) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl)

Example 40 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class MockConnectionManager method stop.

@Override
public void stop() {
    logger.fine("Stopping connection manager");
    live = false;
    final Member localMember = node.getLocalMember();
    final Address thisAddress = localMember.getAddress();
    for (Address address : registry.getAddresses()) {
        if (address.equals(thisAddress)) {
            continue;
        }
        Node otherNode = registry.getNode(address);
        if (otherNode != null && otherNode.getState() != NodeState.SHUT_DOWN) {
            logger.fine(otherNode.getThisAddress() + " is instructed to remove us.");
            ILogger otherLogger = otherNode.getLogger(MockConnectionManager.class);
            otherLogger.fine(localMember + " will be removed from the cluster if present, " + "because it has requested to leave.");
            try {
                ClusterServiceImpl clusterService = otherNode.getClusterService();
                clusterService.removeAddress(localMember.getAddress(), localMember.getUuid(), "Connection manager is stopped on " + localMember);
            } catch (Throwable e) {
                otherLogger.warning("While removing " + thisAddress, e);
            }
        }
    }
    for (Connection connection : mapConnections.values()) {
        connection.close(null, null);
    }
}
Also used : Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Connection(com.hazelcast.nio.Connection) ILogger(com.hazelcast.logging.ILogger) Member(com.hazelcast.core.Member)

Aggregations

ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)41 Node (com.hazelcast.instance.Node)13 Address (com.hazelcast.nio.Address)13 ILogger (com.hazelcast.logging.ILogger)9 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 ClusterState (com.hazelcast.cluster.ClusterState)6 MemberImpl (com.hazelcast.instance.MemberImpl)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 OperationService (com.hazelcast.spi.OperationService)4 Member (com.hazelcast.core.Member)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 ClusterStateManager (com.hazelcast.internal.cluster.impl.ClusterStateManager)3 Config (com.hazelcast.config.Config)2 InternalPartition (com.hazelcast.internal.partition.InternalPartition)2 Connection (com.hazelcast.nio.Connection)2 Operation (com.hazelcast.spi.Operation)2 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2