org.apache.hadoop.hbase
Class ServerName

java.lang.Object
  extended by org.apache.hadoop.hbase.ServerName
All Implemented Interfaces:
Serializable, Comparable<ServerName>

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class ServerName
extends Object
implements Comparable<ServerName>, Serializable

Instance of an HBase ServerName. A server name is used uniquely identifying a server instance in a cluster and is made of the combination of hostname, port, and startcode. The startcode distingushes restarted servers on same hostname and port (startcode is usually timestamp of server startup). The toString() format of ServerName is safe to use in the filesystem and as znode name up in ZooKeeper. Its format is: <hostname> 'SERVERNAME_SEPARATOR' <port> 'SERVERNAME_SEPARATOR' <startcode>. For example, if hostname is www.example.org, port is 1234, and the startcode for the regionserver is 1212121212, then the toString() would be www.example.org,1234,1212121212.

You can obtain a versioned serialized form of this class by calling getVersionedBytes(). To deserialize, call parseVersionedServerName(byte[])

Immutable.

See Also:
Serialized Form

Field Summary
static List<ServerName> EMPTY_SERVER_LIST
           
static int NON_STARTCODE
          What to use if no startcode supplied.
static Pattern SERVERNAME_PATTERN
           
static String SERVERNAME_SEPARATOR
          This character is used as separator between server hostname, port and startcode.
static String UNKNOWN_SERVERNAME
          What to use if server name is unknown.
 
Method Summary
 int compareTo(ServerName other)
           
 boolean equals(Object o)
           
 String getHostAndPort()
           
 String getHostname()
           
 int getPort()
           
 String getServerName()
           
static String getServerName(String hostAndPort, long startcode)
           
static String getServerNameLessStartCode(String inServerName)
          Utility method to excise the start code from a server name
static long getServerStartcodeFromServerName(String serverName)
           
 long getStartcode()
           
 byte[] getVersionedBytes()
           
 int hashCode()
           
static boolean isFullServerName(String str)
           
static boolean isSameHostnameAndPort(ServerName left, ServerName right)
           
static ServerName parseFrom(byte[] data)
          Get a ServerName from the passed in data bytes.
static String parseHostname(String serverName)
           
static int parsePort(String serverName)
           
static ServerName parseServerName(String str)
           
static long parseStartcode(String serverName)
           
static ServerName parseVersionedServerName(byte[] versionedBytes)
          Use this method instantiating a ServerName from bytes gotten from a call to getVersionedBytes().
 String toShortString()
           
 String toString()
           
static ServerName valueOf(String serverName)
          Retrieve an instance of ServerName.
static ServerName valueOf(String hostname, int port, long startcode)
          Retrieve an instance of ServerName.
static ServerName valueOf(String hostAndPort, long startCode)
          Retrieve an instance of ServerName.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NON_STARTCODE

public static final int NON_STARTCODE
What to use if no startcode supplied.

See Also:
Constant Field Values

SERVERNAME_SEPARATOR

public static final String SERVERNAME_SEPARATOR
This character is used as separator between server hostname, port and startcode.

See Also:
Constant Field Values

SERVERNAME_PATTERN

public static final Pattern SERVERNAME_PATTERN

UNKNOWN_SERVERNAME

public static final String UNKNOWN_SERVERNAME
What to use if server name is unknown.

See Also:
Constant Field Values

EMPTY_SERVER_LIST

public static final List<ServerName> EMPTY_SERVER_LIST
Method Detail

parseHostname

public static String parseHostname(String serverName)

parsePort

public static int parsePort(String serverName)

parseStartcode

public static long parseStartcode(String serverName)

valueOf

public static ServerName valueOf(String hostname,
                                 int port,
                                 long startcode)
Retrieve an instance of ServerName. Callers should use the equals method to compare returned instances, though we may return a shared immutable object as an internal optimization.


valueOf

public static ServerName valueOf(String serverName)
Retrieve an instance of ServerName. Callers should use the equals method to compare returned instances, though we may return a shared immutable object as an internal optimization.


valueOf

public static ServerName valueOf(String hostAndPort,
                                 long startCode)
Retrieve an instance of ServerName. Callers should use the equals method to compare returned instances, though we may return a shared immutable object as an internal optimization.


toString

public String toString()
Overrides:
toString in class Object

toShortString

public String toShortString()
Returns:
Return a SHORT version of toString(), one that has the host only, minus the domain, and the port only -- no start code; the String is for us internally mostly tying threads to their server. Not for external use. It is lossy and will not work in in compares, etc.

getVersionedBytes

public byte[] getVersionedBytes()
Returns:
getServerName() as bytes with a short-sized prefix with the ServerName#VERSION of this class.

getServerName

public String getServerName()

getHostname

public String getHostname()

getPort

public int getPort()

getStartcode

public long getStartcode()

getServerName

public static String getServerName(String hostAndPort,
                                   long startcode)
Parameters:
hostAndPort - String in form of <hostname> ':' <port>
startcode -
Returns:
Server name made of the concatenation of hostname, port and startcode formatted as <hostname> ',' <port> ',' <startcode>

getHostAndPort

public String getHostAndPort()
Returns:
Hostname and port formatted as described at Addressing.createHostAndPortStr(String, int)

getServerStartcodeFromServerName

public static long getServerStartcodeFromServerName(String serverName)
Parameters:
serverName - ServerName in form specified by getServerName()
Returns:
The server start code parsed from servername

getServerNameLessStartCode

public static String getServerNameLessStartCode(String inServerName)
Utility method to excise the start code from a server name

Parameters:
inServerName - full server name
Returns:
server name less its start code

compareTo

public int compareTo(ServerName other)
Specified by:
compareTo in interface Comparable<ServerName>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

isSameHostnameAndPort

public static boolean isSameHostnameAndPort(ServerName left,
                                            ServerName right)
Parameters:
left -
right -
Returns:
True if other has same hostname and port.

parseVersionedServerName

public static ServerName parseVersionedServerName(byte[] versionedBytes)
Use this method instantiating a ServerName from bytes gotten from a call to getVersionedBytes(). Will take care of the case where bytes were written by an earlier version of hbase.

Parameters:
versionedBytes - Pass bytes gotten from a call to getVersionedBytes()
Returns:
A ServerName instance.
See Also:
getVersionedBytes()

parseServerName

public static ServerName parseServerName(String str)
Parameters:
str - Either an instance of toString() or a "'' ':' ''".
Returns:
A ServerName instance.

isFullServerName

public static boolean isFullServerName(String str)
Returns:
true if the String follows the pattern of toString(), false otherwise.

parseFrom

public static ServerName parseFrom(byte[] data)
                            throws DeserializationException
Get a ServerName from the passed in data bytes.

Parameters:
data - Data with a serialize server name in it; can handle the old style servername where servername was host and port. Works too with data that begins w/ the pb 'PBUF' magic and that is then followed by a protobuf that has a serialized ServerName in it.
Returns:
Returns null if data is null else converts passed data to a ServerName instance.
Throws:
DeserializationException


Copyright © 2015 The Apache Software Foundation. All Rights Reserved.