Search in sources :

Example 51 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class ClientMemberAttributeTest method testChangeAttributes.

@Test(timeout = 120000)
public void testChangeAttributes() throws Exception {
    Config c = new Config();
    JoinConfig join = c.getNetworkConfig().getJoin();
    join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
    join.getMulticastConfig().setEnabled(false);
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
    Member m1 = h1.getCluster().getLocalMember();
    m1.setIntAttribute("Test", 123);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
    assertEquals(2, h2.getCluster().getMembers().size());
    Member member = null;
    for (Member m : h2.getCluster().getMembers()) {
        if (m == h2.getCluster().getLocalMember()) {
            continue;
        }
        member = m;
    }
    assertNotNull(member);
    assertEquals(m1, member);
    assertNotNull(member.getIntAttribute("Test"));
    assertEquals(123, (int) member.getIntAttribute("Test"));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final CountDownLatch latch = new CountDownLatch(3);
    final MembershipListener listener = new LatchMembershipListener(latch);
    h2.getCluster().addMembershipListener(listener);
    h1.getCluster().addMembershipListener(listener);
    client.getCluster().addMembershipListener(listener);
    m1.setIntAttribute("Test", 321);
    // Force sleep to distribute value
    assertOpenEventually(latch);
    assertNotNull(member.getIntAttribute("Test"));
    assertEquals(321, (int) member.getIntAttribute("Test"));
    boolean found = false;
    Collection<Member> members = client.getCluster().getMembers();
    for (Member m : members) {
        if (m.equals(m1)) {
            assertEquals(321, (int) m.getIntAttribute("Test"));
            found = true;
        }
    }
    assertTrue(found);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) JoinConfig(com.hazelcast.config.JoinConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.core.MembershipListener) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 52 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class ClientEngineImpl method getConnectedClientStats.

@Override
public Map<ClientType, Integer> getConnectedClientStats() {
    int numberOfCppClients = 0;
    int numberOfDotNetClients = 0;
    int numberOfJavaClients = 0;
    int numberOfNodeJSClients = 0;
    int numberOfPythonClients = 0;
    int numberOfOtherClients = 0;
    OperationService operationService = node.nodeEngine.getOperationService();
    Map<ClientType, Integer> resultMap = new HashMap<ClientType, Integer>();
    Map<String, ClientType> clientsMap = new HashMap<String, ClientType>();
    for (Member member : node.getClusterService().getMembers()) {
        Address target = member.getAddress();
        Operation clientInfoOperation = new GetConnectedClientsOperation();
        Future<Map<String, ClientType>> future = operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target);
        try {
            Map<String, ClientType> endpoints = future.get();
            if (endpoints == null) {
                continue;
            }
            //Merge connected clients according to their uuid.
            for (Map.Entry<String, ClientType> entry : endpoints.entrySet()) {
                clientsMap.put(entry.getKey(), entry.getValue());
            }
        } catch (Exception e) {
            logger.warning("Cannot get client information from: " + target.toString(), e);
        }
    }
    //Now we are regrouping according to the client type
    for (ClientType clientType : clientsMap.values()) {
        switch(clientType) {
            case JAVA:
                numberOfJavaClients++;
                break;
            case CSHARP:
                numberOfDotNetClients++;
                break;
            case CPP:
                numberOfCppClients++;
                break;
            case NODEJS:
                numberOfNodeJSClients++;
                break;
            case PYTHON:
                numberOfPythonClients++;
                break;
            default:
                numberOfOtherClients++;
        }
    }
    resultMap.put(ClientType.CPP, numberOfCppClients);
    resultMap.put(ClientType.CSHARP, numberOfDotNetClients);
    resultMap.put(ClientType.JAVA, numberOfJavaClients);
    resultMap.put(ClientType.NODEJS, numberOfNodeJSClients);
    resultMap.put(ClientType.PYTHON, numberOfPythonClients);
    resultMap.put(ClientType.OTHER, numberOfOtherClients);
    return resultMap;
}
Also used : ClientType(com.hazelcast.core.ClientType) Address(com.hazelcast.nio.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) ClientDisconnectionOperation(com.hazelcast.client.impl.operations.ClientDisconnectionOperation) Operation(com.hazelcast.spi.Operation) PostJoinClientOperation(com.hazelcast.client.impl.operations.PostJoinClientOperation) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) ClientEndpoint(com.hazelcast.client.ClientEndpoint) LoginException(javax.security.auth.login.LoginException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) OperationService(com.hazelcast.spi.OperationService) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) Member(com.hazelcast.core.Member) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 53 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class SerializationTest method testMemberLeftException_usingSimpleMember.

@Test
public void testMemberLeftException_usingSimpleMember() throws Exception {
    String uuid = UuidUtil.newUnsecureUuidString();
    String host = "127.0.0.1";
    int port = 5000;
    Member member = new SimpleMemberImpl(MemberVersion.of("3.8.0"), uuid, new InetSocketAddress(host, port));
    testMemberLeftException(uuid, host, port, member);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Member(com.hazelcast.core.Member) SimpleMemberImpl(com.hazelcast.instance.SimpleMemberImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 54 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class SerializationTest method testMemberLeftException_withLiteMemberImpl.

@Test
public void testMemberLeftException_withLiteMemberImpl() throws Exception {
    String uuid = UuidUtil.newUnsecureUuidString();
    String host = "127.0.0.1";
    int port = 5000;
    Member member = new MemberImpl(new Address(host, port), MemberVersion.of("3.8.0"), false, uuid, null, null, true);
    testMemberLeftException(uuid, host, port, member);
}
Also used : Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) SimpleMemberImpl(com.hazelcast.instance.SimpleMemberImpl) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 55 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class SerializationTest method testMemberLeftException_withLiteSimpleMemberImpl.

@Test
public void testMemberLeftException_withLiteSimpleMemberImpl() throws Exception {
    String uuid = UuidUtil.newUnsecureUuidString();
    String host = "127.0.0.1";
    int port = 5000;
    Member member = new SimpleMemberImpl(MemberVersion.of("3.8.0"), uuid, new InetSocketAddress(host, port), true);
    testMemberLeftException(uuid, host, port, member);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Member(com.hazelcast.core.Member) SimpleMemberImpl(com.hazelcast.instance.SimpleMemberImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Member (com.hazelcast.core.Member)167 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)37 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Config (com.hazelcast.config.Config)18 HashSet (java.util.HashSet)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 Future (java.util.concurrent.Future)17 Data (com.hazelcast.nio.serialization.Data)13 Operation (com.hazelcast.spi.Operation)13 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 CacheEventData (com.hazelcast.cache.impl.CacheEventData)12 HeapData (com.hazelcast.internal.serialization.impl.HeapData)12 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)12 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 OperationService (com.hazelcast.spi.OperationService)12