Search in sources :

Example 1 with ClientType

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

the class PhoneHome method phoneHome.

public Map<String, String> phoneHome(Node hazelcastNode, String version, boolean isEnterprise) {
    String downloadId = "source";
    InputStream is = null;
    try {
        is = getClass().getClassLoader().getResourceAsStream("hazelcast-download.properties");
        if (is != null) {
            final Properties properties = new Properties();
            properties.load(is);
            downloadId = properties.getProperty("hazelcastDownloadId");
        }
    } catch (IOException ignored) {
        EmptyStatement.ignore(ignored);
    } finally {
        IOUtil.closeResource(is);
    }
    //Calculate native memory usage from native memory config
    NativeMemoryConfig memoryConfig = hazelcastNode.getConfig().getNativeMemoryConfig();
    final ClusterServiceImpl clusterService = hazelcastNode.getClusterService();
    long totalNativeMemorySize = clusterService.getSize(DATA_MEMBER_SELECTOR) * memoryConfig.getSize().bytes();
    String nativeMemoryParameter = (isEnterprise) ? Long.toString(MemoryUnit.BYTES.toGigaBytes(totalNativeMemorySize)) : "0";
    //Calculate connected clients to the cluster.
    Map<ClientType, Integer> clusterClientStats = hazelcastNode.clientEngine.getConnectedClientStats();
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
    Long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();
    PhoneHomeParameterCreator parameterCreator = new PhoneHomeParameterCreator();
    parameterCreator.addParam("version", version);
    parameterCreator.addParam("m", hazelcastNode.getThisUuid());
    parameterCreator.addParam("e", Boolean.toString(isEnterprise));
    parameterCreator.addParam("l", MD5Util.toMD5String(hazelcastNode.getConfig().getLicenseKey()));
    parameterCreator.addParam("p", downloadId);
    parameterCreator.addParam("c", clusterService.getClusterId());
    parameterCreator.addParam("crsz", convertToLetter(clusterService.getMembers().size()));
    parameterCreator.addParam("cssz", convertToLetter(hazelcastNode.clientEngine.getClientEndpointCount()));
    parameterCreator.addParam("hdgb", nativeMemoryParameter);
    parameterCreator.addParam("ccpp", Integer.toString(clusterClientStats.get(ClientType.CPP)));
    parameterCreator.addParam("cdn", Integer.toString(clusterClientStats.get(ClientType.CSHARP)));
    parameterCreator.addParam("cjv", Integer.toString(clusterClientStats.get(ClientType.JAVA)));
    parameterCreator.addParam("cnjs", Integer.toString(clusterClientStats.get(ClientType.NODEJS)));
    parameterCreator.addParam("cpy", Integer.toString(clusterClientStats.get(ClientType.PYTHON)));
    parameterCreator.addParam("cuptm", Long.toString(clusterUpTime));
    parameterCreator.addParam("nuptm", Long.toString(runtimeMxBean.getUptime()));
    parameterCreator.addParam("jvmn", runtimeMxBean.getVmName());
    parameterCreator.addParam("jvmv", System.getProperty("java.version"));
    JetBuildInfo jetBuildInfo = hazelcastNode.getBuildInfo().getJetBuildInfo();
    parameterCreator.addParam("jetv", jetBuildInfo == null ? "" : jetBuildInfo.getVersion());
    try {
        parameterCreator.addParam("osn", osMxBean.getName());
        parameterCreator.addParam("osa", osMxBean.getArch());
        parameterCreator.addParam("osv", osMxBean.getVersion());
    } catch (SecurityException e) {
        parameterCreator.addParam("osn", "N/A");
        parameterCreator.addParam("osa", "N/A");
        parameterCreator.addParam("osv", "N/A");
    }
    String urlStr = BASE_PHONE_HOME_URL + parameterCreator.build();
    fetchWebService(urlStr);
    return parameterCreator.getParameters();
}
Also used : ClientType(com.hazelcast.core.ClientType) JetBuildInfo(com.hazelcast.instance.JetBuildInfo) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) IOException(java.io.IOException) RuntimeMXBean(java.lang.management.RuntimeMXBean) Properties(java.util.Properties) NativeMemoryConfig(com.hazelcast.config.NativeMemoryConfig) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 2 with ClientType

use of com.hazelcast.core.ClientType 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)

Aggregations

ClientType (com.hazelcast.core.ClientType)2 ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 ClientDisconnectionOperation (com.hazelcast.client.impl.operations.ClientDisconnectionOperation)1 GetConnectedClientsOperation (com.hazelcast.client.impl.operations.GetConnectedClientsOperation)1 PostJoinClientOperation (com.hazelcast.client.impl.operations.PostJoinClientOperation)1 NativeMemoryConfig (com.hazelcast.config.NativeMemoryConfig)1 Member (com.hazelcast.core.Member)1 JetBuildInfo (com.hazelcast.instance.JetBuildInfo)1 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)1 Address (com.hazelcast.nio.Address)1 Operation (com.hazelcast.spi.Operation)1 OperationService (com.hazelcast.spi.OperationService)1 UrgentSystemOperation (com.hazelcast.spi.UrgentSystemOperation)1 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 HashMap (java.util.HashMap)1