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;
}
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());
}
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;
}
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());
}
Aggregations