Package javax.jmdns

Class ServiceInfo

java.lang.Object
javax.jmdns.ServiceInfo
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ServiceInfoImpl

public abstract class ServiceInfo extends Object implements Cloneable

The fully qualified service name is build using up to 5 components with the following structure:

            <app>.<protocol>.<servicedomain>.<parentdomain>.
<Instance>.<app>.<protocol>.<servicedomain>.<parentdomain>.
<sub>._sub.<app>.<protocol>.<servicedomain>.<parentdomain>.
  1. <servicedomain>.<parentdomain>: This is the domain scope of the service typically "local.", but this can also be something similar to "in-addr.arpa." or "ip6.arpa."
  2. <protocol>: This is either "_tcp" or "_udp"
  3. <app>: This define the application protocol. Typical example are "_http", "_ftp", etc.
  4. <Instance>: This is the service name
  5. <sub>: This is the subtype for the application protocol

  • Constructor Details

    • ServiceInfo

      public ServiceInfo()
  • Method Details

    • create

      public static ServiceInfo create(String type, String name, int port, String text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      port - the local port on which the service runs
      text - string describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, String subtype, int port, String text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      subtype - service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumeration
      port - the local port on which the service runs
      text - string describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, int port, int weight, int priority, String text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      text - string describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, String subtype, int port, int weight, int priority, String text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      subtype - service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumeration
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      text - string describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, int port, int weight, int priority, Map<String,?> props)
      Construct a service description for registering with JmDNS. The properties hashtable must map property names to either Strings or byte arrays describing the property values.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      props - properties describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, String subtype, int port, int weight, int priority, Map<String,?> props)
      Construct a service description for registering with JmDNS. The properties hashtable must map property names to either Strings or byte arrays describing the property values.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      subtype - service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumeration
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      props - properties describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, int port, int weight, int priority, byte[] text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      text - bytes describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, String subtype, int port, int weight, int priority, byte[] text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      subtype - service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumeration
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      text - bytes describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, int port, int weight, int priority, boolean persistent, String text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      persistent - if true ServiceListener.resolveService will be called whenever new new information is received.
      text - string describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, String text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      subtype - service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumeration
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      persistent - if true ServiceListener.resolveService will be called whenever new new information is received.
      text - string describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, int port, int weight, int priority, boolean persistent, Map<String,?> props)
      Construct a service description for registering with JmDNS. The properties hashtable must map property names to either Strings or byte arrays describing the property values.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      persistent - if true ServiceListener.resolveService will be called whenever new new information is received.
      props - properties describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, Map<String,?> props)
      Construct a service description for registering with JmDNS. The properties hashtable must map property names to either Strings or byte arrays describing the property values.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      subtype - service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumeration
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      persistent - if true ServiceListener.resolveService will be called whenever new new information is received.
      props - properties describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, int port, int weight, int priority, boolean persistent, byte[] text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      persistent - if true ServiceListener.resolveService will be called whenever new new information is received.
      text - bytes describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, byte[] text)
      Construct a service description for registering with JmDNS.
      Parameters:
      type - fully qualified service type name, such as _http._tcp.local..
      name - unqualified service instance name, such as foobar
      subtype - service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumeration
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      persistent - if true ServiceListener.resolveService will be called whenever new new information is received.
      text - bytes describing the service
      Returns:
      new service info
    • create

      public static ServiceInfo create(Map<ServiceInfo.Fields,String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, Map<String,?> props)
      Construct a service description for registering with JmDNS. The properties hashtable must map property names to either Strings or byte arrays describing the property values.
      Parameters:
      qualifiedNameMap - dictionary of values to build the fully qualified service name. Mandatory keys are Application and Instance. The Domain default is local, the Protocol default is tcp and the subtype default is none.
      port - the local port on which the service runs
      weight - weight of the service
      priority - priority of the service
      persistent - if true ServiceListener.resolveService will be called whenever new new information is received.
      props - properties describing the service
      Returns:
      new service info
    • hasData

      public abstract boolean hasData()
      Returns true if the service info is filled with data.
      Returns:
      true if the service info has data, false otherwise.
    • getType

      public abstract String getType()
      Fully qualified service type name, such as _http._tcp.local.
      Returns:
      service type name
    • getTypeWithSubtype

      public abstract String getTypeWithSubtype()
      Fully qualified service type name with the subtype if appropriate, such as _printer._sub._http._tcp.local.
      Returns:
      service type name
    • getName

      public abstract String getName()
      Unqualified service instance name, such as foobar .
      Returns:
      service name
    • getKey

      public abstract String getKey()
      The key is used to retrieve service info in hash tables.
      The key is the lower case qualified name.
      Returns:
      the key
    • getQualifiedName

      public abstract String getQualifiedName()
      Fully qualified service name, such as foobar._http._tcp.local. .
      Returns:
      qualified service name
    • getServer

      public abstract String getServer()
      Get the name of the server. Note: This will be an empty string if no value has been set
      Returns:
      server name
    • hasServer

      public abstract boolean hasServer()
      Returns true if the service info has a server
      Returns:
      true if the service info has a server specified, false otherwise.
    • getHostAddress

      @Deprecated public abstract String getHostAddress()
      Deprecated.
      since 3.2.3
      Returns the host IP address string in textual presentation.
      Note: This can be either an IPv4 or an IPv6 representation.
      Returns:
      the host raw IP address in a string format.
      See Also:
    • getHostAddresses

      public abstract String[] getHostAddresses()
      Returns the host IP addresses string in textual presentation.
      Returns:
      list of host raw IP address in a string format.
    • getAddress

      @Deprecated public abstract InetAddress getAddress()
      Deprecated.
      since 3.1.8
      Get the host address of the service.
      Returns:
      host Internet address
      See Also:
    • getInetAddress

      @Deprecated public abstract InetAddress getInetAddress()
      Deprecated.
      since 3.2.3
      Get the InetAddress of the service. This will return the IPv4 if it exist, otherwise it return the IPv6 if set.
      Note: This return null if the service IP address cannot be resolved.
      Returns:
      Internet address
      See Also:
    • getInet4Address

      @Deprecated public abstract Inet4Address getInet4Address()
      Deprecated.
      since 3.2.3
      Get the IPv4 InetAddress of the service.
      Note: This return null if the service IPv4 address cannot be resolved.
      Returns:
      Internet address
      See Also:
    • getInet6Address

      @Deprecated public abstract Inet6Address getInet6Address()
      Deprecated.
      since 3.2.3
      Get the IPv6 InetAddress of the service.
      Note: This return null if the service IPv6 address cannot be resolved.
      Returns:
      Internet address
      See Also:
    • getInetAddresses

      public abstract InetAddress[] getInetAddresses()
      Returns a list of all InetAddresses that can be used for this service.

      In a multi-homed environment service info can be associated with more than one address.

      Returns:
      list of InetAddress objects
    • getInet4Addresses

      public abstract Inet4Address[] getInet4Addresses()
      Returns a list of all IPv4 InetAddresses that can be used for this service.

      In a multi-homed environment service info can be associated with more than one address.

      Returns:
      list of InetAddress objects
    • getInet6Addresses

      public abstract Inet6Address[] getInet6Addresses()
      Returns a list of all IPv6 InetAddresses that can be used for this service.

      In a multi-homed environment service info can be associated with more than one address.

      Returns:
      list of InetAddress objects
    • getPort

      public abstract int getPort()
      Get the port for the service.
      Returns:
      service port
    • getPriority

      public abstract int getPriority()
      Get the priority of the service.
      Returns:
      service priority
    • getWeight

      public abstract int getWeight()
      Get the weight of the service.
      Returns:
      service weight
    • getTextBytes

      public abstract byte[] getTextBytes()
      Get the text for the service as raw bytes.
      Returns:
      raw service text
    • getTextString

      @Deprecated public abstract String getTextString()
      Deprecated.
      since 3.1.7
      Get the text for the service. This will interpret the text bytes as a UTF8 encoded string. Will return null if the bytes are not a valid UTF8 encoded string.
      Note: Do not use. This method make the assumption that the TXT record is one string. This is false. The TXT record is a series of key value pairs.
      Returns:
      service text
      See Also:
    • getURL

      @Deprecated public abstract String getURL()
      Deprecated.
      since 3.2.3
      Get the URL for this service. An http URL is created by combining the address, port, and path properties.
      Returns:
      service URL
      See Also:
    • getURLs

      public abstract String[] getURLs()
      Get the list of URL for this service. An http URL is created by combining the address, port, and path properties.
      Returns:
      list of service URL
    • getURL

      @Deprecated public abstract String getURL(String protocol)
      Deprecated.
      since 3.2.3
      Get the URL for this service. An URL is created by combining the protocol, address, port, and path properties.
      Parameters:
      protocol - requested protocol
      Returns:
      service URL
      See Also:
    • getURLs

      public abstract String[] getURLs(String protocol)
      Get the list of URL for this service. An URL is created by combining the protocol, address, port, and path properties.
      Parameters:
      protocol - requested protocol
      Returns:
      list of service URL
    • getPropertyBytes

      public abstract byte[] getPropertyBytes(String name)
      Get a property of the service. This involves decoding the text bytes into a property list. Returns null if the property is not found or the text data could not be decoded correctly.
      Parameters:
      name - property name
      Returns:
      raw property text
    • getPropertyString

      public abstract String getPropertyString(String name)
      Get a property of the service. This involves decoding the text bytes into a property list. Returns null if the property is not found, the text data could not be decoded correctly, or the resulting bytes are not a valid UTF8 string.
      Parameters:
      name - property name
      Returns:
      property text
    • getPropertyNames

      public abstract Enumeration<String> getPropertyNames()
      Enumeration of the property names.
      Returns:
      property name enumeration
    • getNiceTextString

      public abstract String getNiceTextString()
      Returns a description of the service info suitable for printing.
      Returns:
      service info description
    • setText

      public abstract void setText(byte[] text) throws IllegalStateException
      Set the text for the service. Setting the text will fore a re-announce of the service.
      Parameters:
      text - the raw byte representation of the text field.
      Throws:
      IllegalStateException - if attempting to set the text for a non persistent service info.
    • setText

      public abstract void setText(Map<String,?> props) throws IllegalStateException
      Set the text for the service. Setting the text will fore a re-announce of the service.
      Parameters:
      props - a key=value map that will be encoded into raw bytes.
      Throws:
      IllegalStateException - if attempting to set the text for a non persistent service info.
    • isPersistent

      public abstract boolean isPersistent()
      Returns true if ServiceListener.resolveService will be called whenever new new information is received.
      Returns:
      the persistent
    • getDomain

      public abstract String getDomain()
      Returns the domain of the service info suitable for printing.
      Returns:
      service domain
    • getProtocol

      public abstract String getProtocol()
      Returns the protocol of the service info suitable for printing.
      Returns:
      service protocol
    • getApplication

      public abstract String getApplication()
      Returns the application of the service info suitable for printing.
      Returns:
      service application
    • getSubtype

      public abstract String getSubtype()
      Returns the sub type of the service info suitable for printing.
      Returns:
      service sub type
    • getQualifiedNameMap

      public abstract Map<ServiceInfo.Fields,String> getQualifiedNameMap()
      Returns a dictionary of the fully qualified name component of this service.
      Returns:
      dictionary of the fully qualified name components
    • hasSameAddresses

      public abstract boolean hasSameAddresses(ServiceInfo other)
      Compare addresses of another ServiceInfo
      Parameters:
      other - ServiceInfo to compare
      Returns:
      true if addresses are the same, false if not
    • clone

      public ServiceInfo clone()
      Overrides:
      clone in class Object