Class ServerName

java.lang.Object
org.apache.hadoop.hbase.ServerName
All Implemented Interfaces:
Serializable, Comparable<ServerName>
Direct Known Subclasses:
StartcodeAgnosticServerName

@Public public class ServerName extends Object implements Comparable<ServerName>, Serializable
Name of a particular incarnation of an HBase Server. A ServerName is used uniquely identifying a server instance in a cluster and is made of the combination of hostname, port, and startcode. The startcode distinguishes 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[]).

Use getAddress() to obtain the Server hostname + port (Endpoint/Socket Address).

Immutable.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getHostNameMinusDomain

      private static String getHostNameMinusDomain(String hostname)
      Parameters:
      hostname - the hostname string to get the actual hostname from
      Returns:
      hostname minus the domain, if there is one (will do pass-through on ip addresses)
    • 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.
    • valueOf

      public static ServerName valueOf(Address address, long startCode)
      Retrieve an instance of ServerName. Callers should use the equals(Object) method to compare returned instances, though we may return a shared immutable object as an internal optimization.
      Parameters:
      address - the Address to use for getting the ServerName
      startCode - the startcode to use for getting the ServerName
      Returns:
      the constructed ServerName
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toShortString

      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()
      Return getServerName() as bytes with a short-sized prefix with the VERSION of this class.
    • getServerName

    • getHostname

      public String getHostname()
    • getHostnameLowerCase

    • getPort

      public int getPort()
    • getStartcode

      @Deprecated public long getStartcode()
      Deprecated.
      Since 2.5.0, will be removed in 4.0.0. Use getStartCode() instead.
      Return the start code.
    • getStartCode

      public long getStartCode()
      Return the start code.
    • getServerName

      private static String getServerName(String hostName, int port, long startCode)
      For internal use only.
      Parameters:
      hostName - the name of the host to use
      port - the port on the host to use
      startCode - the startcode to use for formatting
      Returns:
      Server name made of the concatenation of hostname, port and startcode formatted as <hostname> ',' <port> ',' <startcode>
    • getAddress

      public Address getAddress()
    • 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
    • isSameAddress

      public static boolean isSameAddress(ServerName left, ServerName right)
      Compare two addresses
      Parameters:
      left - the first server address to compare
      right - the second server address to compare
      Returns:
      true if left and right have the 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:
    • parseServerName

      public static ServerName parseServerName(String str)
      Parse a ServerName from a string
      Parameters:
      str - Either an instance of toString() or a "'<hostname>' ':' '<port>'".
      Returns:
      A ServerName instance.
    • isFullServerName

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