All Implemented Interfaces:
Comparable<SRV>

public class SRVextends RRWithTarget implements Comparable<SRV>
DNS SRV (Service) record payload for service discovery.
Specifies the location of services for a given domain with priority, weight, and port information for load balancing.
  • Field Details

    • priority

      public final int priority
      The priority of this service. Lower values mean higher priority.
    • weight

      public final int weight
      The weight of this service. Services with the same priority should be balanced based on weight.
    • port

      public final int port
      The target port.
  • Constructor Details

    • SRV

      public SRV(int priority, int weight, int port, String target)
      Builds an SRV record from a textual target hostname.
      Parameters:
      priority - lower values are tried first among records of equal weight
      weight - relative likelihood of this record among equals
      port - the TCP or UDP port the service listens on
      target - the hostname the service is reached at
    • SRV

      public SRV(int priority, int weight, int port, DnsName target)
      Builds an SRV record from an already-parsed target hostname.
      Parameters:
      priority - lower values are tried first among records of equal weight
      weight - relative likelihood of this record among equals
      port - the TCP or UDP port the service listens on
      target - the already-parsed hostname the service is reached at
  • Method Details

    • parse

      public static SRV parse(DataInputStream dis, byte[] data) throws IOException
      Reads an SRV record body from the stream.
      Parameters:
      dis - stream positioned at the start of the SRV record fields
      data - the whole message being parsed, used to resolve names
      Returns:
      the decoded SRV record
      Throws:
      IOException - if the stream ends early or the target name cannot be read
    • isServiceAvailable

      public boolean isServiceAvailable()
      Check if the service is available at this domain. This checks f the target points to the root label. As per RFC 2782 the service is decidedly not available if there is only a single SRV answer pointing to the root label. From RFC 2782:
      A Target of "." means that the service is decidedly not available at this domain.
      Returns:
      true if the service is available at this domain.
    • serialize

      public void serialize(DataOutputStream dos) throws IOException
      Writes the priority, weight, port and target name.
      Overrides:
      serialize in class RRWithTarget
      Parameters:
      dos - the output stream to serialize to.
      Throws:
      IOException - if an I/O error occurs.
    • toString

      public String toString()
      Renders the priority, weight, port and target.
      Overrides:
      toString in class RRWithTarget
    • getType

      public Record.TYPE getType()
      Returns the DNS record type of this record.
      Specified by:
      getType in class Data
      Returns:
      The DNS record type of this payload.
    • compareTo

      public int compareTo(SRV other)
      Orders by priority first, then by weight, per RFC 2782.
      Specified by:
      compareTo in interface Comparable<SRV>