Search in sources :

Example 1 with GetConnectedClientsOperation

use of com.hazelcast.client.impl.operations.GetConnectedClientsOperation 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 2 with GetConnectedClientsOperation

use of com.hazelcast.client.impl.operations.GetConnectedClientsOperation in project hazelcast by hazelcast.

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    factory.newHazelcastClient();
    factory.newHazelcastClient();
    Node node = getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, String>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, String> clients = future.get();
    assertEquals(2, clients.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with GetConnectedClientsOperation

use of com.hazelcast.client.impl.operations.GetConnectedClientsOperation in project hazelcast by hazelcast.

the class ClientEngineImpl method getClientsInCluster.

Map<UUID, String> getClientsInCluster() {
    OperationService operationService = node.nodeEngine.getOperationService();
    Map<UUID, String> clientsMap = new HashMap<>();
    for (Member member : node.getClusterService().getMembers()) {
        Address target = member.getAddress();
        Operation clientInfoOperation = new GetConnectedClientsOperation();
        Future<Map<UUID, String>> future = operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target);
        try {
            Map<UUID, String> endpoints = future.get();
            if (endpoints == null) {
                continue;
            }
            // Merge connected clients according to their UUID
            clientsMap.putAll(endpoints);
        } catch (Exception e) {
            logger.warning("Cannot get client information from: " + target.toString(), e);
        }
    }
    return clientsMap;
}
Also used : Address(com.hazelcast.cluster.Address) InetSocketAddress(java.net.InetSocketAddress) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) LoginException(javax.security.auth.login.LoginException)

Example 4 with GetConnectedClientsOperation

use of com.hazelcast.client.impl.operations.GetConnectedClientsOperation in project hazelcast by hazelcast.

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    Node node = getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, String>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, String> clients = future.get();
    assertEquals(0, clients.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

GetConnectedClientsOperation (com.hazelcast.client.impl.operations.GetConnectedClientsOperation)4 Map (java.util.Map)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)3 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Node (com.hazelcast.instance.impl.Node)2 Accessors.getNode (com.hazelcast.test.Accessors.getNode)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 LoginException (javax.security.auth.login.LoginException)2 Test (org.junit.Test)2 ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 ClientDisconnectionOperation (com.hazelcast.client.impl.operations.ClientDisconnectionOperation)1 PostJoinClientOperation (com.hazelcast.client.impl.operations.PostJoinClientOperation)1 Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1 ClientType (com.hazelcast.core.ClientType)1 Member (com.hazelcast.core.Member)1