com.alachisoft.ncache.client.internal.communication.NodeInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.alachisoft.ncache.client.internal.communication;
import java.net.InetAddress;
public class NodeInfo {
private InetAddress _ip;
private int _port;
//private IPAddress _ip;
public NodeInfo(InetAddress ip, int port) {
_ip = ip;
_port = port;
}
/**
* IPAddress of the node joining / leaving the cluster.
*/
public final InetAddress getIpAddress() {
return _ip;
}
/**
* Port, the member uses for the cluster-wide communication.
*/
public final int getPort() {
return _port;
}
/**
* provides the string representation of NodeInfo.
*
* @return
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (_ip == null) {
sb.append("");
} else {
String host_name = _ip.toString();
appendShortName(host_name, sb);
}
sb.append(":" + _port);
return sb.toString();
}
/**
* Input: "daddy.nms.fnc.fujitsu.com", output: "daddy". Appends result to
* string buffer 'sb'.
*
* @param hostname The hostname in long form. Guaranteed not to be null
* @param sb The string buffer to which the result is to be appended
*/
private void appendShortName(String hostname, StringBuilder sb) {
if (hostname != null) {
int index = hostname.indexOf((char) '.');
if (index > 0 && !Character.isDigit(hostname.charAt(0))) {
sb.append(hostname.substring(0, (index) - (0)));
} else {
sb.append(hostname);
}
}
}
}