All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.client.ClientInfo Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
package com.alachisoft.ncache.client;

import java.net.InetAddress;

import com.alachisoft.ncache.client.ConnectivityStatus;
import com.alachisoft.ncache.client.internal.util.HelperUtil;

/**
 * This class provides detailed information about cache client.
 */
public class ClientInfo implements Cloneable {
    /**
     * Application's name.
     */
    private String appName = "JavaApp";

    /**
     * ClientID is a unique id.
     */
    private String clientID;

    /**
     * IPAddress of the cache client.
     */
    private InetAddress iPAddress;

    /**
     * Mac Address of cache client
     */
    private String macAddress;

    /**
     * Available cores of Cache Client
     */
    private int cores = 0;

    /**
     * Process ID of the cache client.
     */
    private int processID;

    /**
     * Name of the machine the client is running on.
     */
    private String machineName;

    /**
     *
     */
    private ConnectivityStatus status;

    /**
     * Version of NCache client.
     */
    private int clientVersion;

    /**
     * GetLegacyClientId returns the client id in string.
     *
     * @param info
     * @return Client id of the client
     */
    public static String getLegacyClientID(ClientInfo info) {
        return ((info.clientID != null ? info.clientID : "") + ":" + (info.machineName != null ? info.machineName : "") + ":" + info.processID);
    }

    /**
     * TryParseLegacyClientId parse the Client id and get information about the client id in the form of ClientInfo
     *
     * @param clientId Client id of the client
     * @return
     */
    public static ClientInfo tryParseLegacyClientID(String clientId) {
        String[] parameters = clientId.split("[:]", -1);
        if (parameters.length < 3) {
            return null;
        }
        ClientInfo info = new ClientInfo();
        info.clientID = parameters[0];
        info.machineName = parameters[1];
        info.processID = Integer.getInteger(parameters[2]);
        return info;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getAppName() {
        return appName;
    }

    public String getClientID() {
        return clientID;
    }

    public void setClientID(String clientID) {
        this.clientID = clientID;
    }

    public InetAddress getiPAddress() {
        return iPAddress;
    }

    public void setiPAddress(InetAddress iPAddress) {
        this.iPAddress = iPAddress;
    }


    public void setMacAddress(String macAddress) {
        this.macAddress = macAddress;
    }

    public int getCores() {
        return cores;
    }

    public void setCores(int cores) {
        this.cores = cores;
    }

    public int getProcessID() {
        return processID;
    }

    public void setProcessID(int processID) {
        this.processID = processID;
    }

    public String getMachineName() {
        return machineName;
    }

    public void setMachineName(String machineName) {
        this.machineName = machineName;
    }

    public String getMacAddress() {
        return macAddress;
    }

    public ConnectivityStatus getStatus() {
        return status;
    }

    public void setStatus(ConnectivityStatus status) {
        this.status = status;
    }

    public int getClientVersion() {
        return clientVersion;
    }

    public void setClientVersion(int clientVersion) {
        this.clientVersion = clientVersion;
    }

    /**
     * Converts Client Info to string , contains client id , Application name ,Process id , machine name and address.
     *
     * @return ClientInfo in string form
     */
    @Override
    public String toString() {
        return "Client ID: " + clientID + System.lineSeparator() +
                "Application Name: " + appName + System.lineSeparator() +
                "Process ID: " + processID + System.lineSeparator() +
                "Machine Name: " + machineName + System.lineSeparator() +
                "Status: " + status + System.lineSeparator() +
                "Address: " + iPAddress + System.lineSeparator() +
                "Client Version: " + clientVersion;
    }

    /**
     * Clones the object and returns the newly created clone of the object.
     *
     * @return The newly cloned ClientInfo object
     */
    public final Object clone() {
        ClientInfo info = new ClientInfo();
        info.setiPAddress(iPAddress);
        info.setAppName(appName);
        info.setClientID(clientID);
        info.setMachineName(machineName);
        info.setProcessID(processID);
        info.setStatus(status);
        info.setClientVersion(clientVersion);
        return info;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy