@Override public Map<ClientType, Integer> getConnectedClientStats() { int numberOfCppClients = 0; int numberOfDotNetClients = 0; int numberOfJavaClients = 0; int numberOfOtherClients = 0; Operation clientInfoOperation = new GetConnectedClientsOperation(); 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(); 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; default: numberOfOtherClients++; } } resultMap.put(ClientType.CPP, numberOfCppClients); resultMap.put(ClientType.CSHARP, numberOfDotNetClients); resultMap.put(ClientType.JAVA, numberOfJavaClients); resultMap.put(ClientType.OTHER, numberOfOtherClients); return resultMap; }
private String getThisNodesAddress() { final NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); final Address thisAddress = nodeEngine.getThisAddress(); return thisAddress.toString(); }