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>.- <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."
- <protocol>: This is either "_tcp" or "_udp"
- <app>: This define the application protocol. Typical example are "_http", "_ftp", etc.
- <Instance>: This is the service name
- <sub>: This is the subtype for the application protocol
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ServiceInfo.Fields
Fields for the fully qualified map.
-
Constructor Summary
Constructors Constructor Description ServiceInfo()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ServiceInfo
clone()
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.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.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.static ServiceInfo
create(String type, String name, int port, int weight, int priority, byte[] text)
Construct a service description for registering with JmDNS.static ServiceInfo
create(String type, String name, int port, int weight, int priority, String text)
Construct a service description for registering with JmDNS.static ServiceInfo
create(String type, String name, int port, int weight, int priority, Map<String,?> props)
Construct a service description for registering with JmDNS.static ServiceInfo
create(String type, String name, int port, String text)
Construct a service description for registering with JmDNS.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.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.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.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.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.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.static ServiceInfo
create(String type, String name, String subtype, int port, String text)
Construct a service description for registering with JmDNS.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.abstract InetAddress
getAddress()
Deprecated.since 3.1.8abstract String
getApplication()
Returns the application of the service info suitable for printing.abstract String
getDomain()
Returns the domain of the service info suitable for printing.abstract String
getHostAddress()
Deprecated.since 3.2.3abstract String[]
getHostAddresses()
Returns the host IP addresses string in textual presentation.abstract Inet4Address
getInet4Address()
Deprecated.since 3.2.3abstract Inet4Address[]
getInet4Addresses()
Returns a list of all IPv4 InetAddresses that can be used for this service.abstract Inet6Address
getInet6Address()
Deprecated.since 3.2.3abstract Inet6Address[]
getInet6Addresses()
Returns a list of all IPv6 InetAddresses that can be used for this service.abstract InetAddress
getInetAddress()
Deprecated.since 3.2.3abstract InetAddress[]
getInetAddresses()
Returns a list of all InetAddresses that can be used for this service.abstract String
getKey()
The key is used to retrieve service info in hash tables.
The key is the lower case qualified name.abstract String
getName()
Unqualified service instance name, such asfoobar
.abstract String
getNiceTextString()
Returns a description of the service info suitable for printing.abstract int
getPort()
Get the port for the service.abstract int
getPriority()
Get the priority of the service.abstract byte[]
getPropertyBytes(String name)
Get a property of the service.abstract Enumeration<String>
getPropertyNames()
Enumeration of the property names.abstract String
getPropertyString(String name)
Get a property of the service.abstract String
getProtocol()
Returns the protocol of the service info suitable for printing.abstract String
getQualifiedName()
Fully qualified service name, such asfoobar._http._tcp.local.
.abstract Map<ServiceInfo.Fields,String>
getQualifiedNameMap()
Returns a dictionary of the fully qualified name component of this service.abstract String
getServer()
Get the name of the server.abstract String
getSubtype()
Returns the sub type of the service info suitable for printing.abstract byte[]
getTextBytes()
Get the text for the service as raw bytes.abstract String
getTextString()
Deprecated.since 3.1.7abstract String
getType()
Fully qualified service type name, such as_http._tcp.local.
abstract String
getTypeWithSubtype()
Fully qualified service type name with the subtype if appropriate, such as_printer._sub._http._tcp.local.
abstract String
getURL()
Deprecated.since 3.2.3abstract String
getURL(String protocol)
Deprecated.since 3.2.3abstract String[]
getURLs()
Get the list of URL for this service.abstract String[]
getURLs(String protocol)
Get the list of URL for this service.abstract int
getWeight()
Get the weight of the service.abstract boolean
hasData()
Returns true if the service info is filled with data.abstract boolean
hasSameAddresses(ServiceInfo other)
Compare addresses of another ServiceInfoabstract boolean
isPersistent()
Returnstrue
if ServiceListener.resolveService will be called whenever new new information is received.abstract void
setText(byte[] text)
Set the text for the service.abstract void
setText(Map<String,?> props)
Set the text for the service.
-
-
-
Method Detail
-
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 asfoobar
port
- the local port on which the service runstext
- 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 asfoobar
subtype
- service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumerationport
- the local port on which the service runstext
- 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 asfoobar
port
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicetext
- 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 asfoobar
subtype
- service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumerationport
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicetext
- 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 asfoobar
port
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the serviceprops
- 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 asfoobar
subtype
- service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumerationport
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the serviceprops
- 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 asfoobar
port
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicetext
- 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 asfoobar
subtype
- service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumerationport
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicetext
- 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 asfoobar
port
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicepersistent
- iftrue
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 asfoobar
subtype
- service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumerationport
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicepersistent
- iftrue
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 asfoobar
port
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicepersistent
- iftrue
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 asfoobar
subtype
- service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumerationport
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicepersistent
- iftrue
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 asfoobar
port
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicepersistent
- iftrue
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 asfoobar
subtype
- service subtype see draft-cheshire-dnsext-dns-sd-06.txt chapter 7.1 Selective Instance Enumerationport
- the local port on which the service runsweight
- weight of the servicepriority
- priority of the servicepersistent
- iftrue
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 runsweight
- weight of the servicepriority
- priority of the servicepersistent
- iftrue
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 asfoobar
.- 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 asfoobar._http._tcp.local.
.- Returns:
- qualified service name
-
getServer
public abstract String getServer()
Get the name of the server.- Returns:
- server name
-
getHostAddress
@Deprecated public abstract String getHostAddress()
Deprecated.since 3.2.3Returns 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()
-
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.8Get the host address of the service.- Returns:
- host Internet address
- See Also:
getInetAddresses()
-
getInetAddress
@Deprecated public abstract InetAddress getInetAddress()
Deprecated.since 3.2.3Get 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:
getInetAddresses()
-
getInet4Address
@Deprecated public abstract Inet4Address getInet4Address()
Deprecated.since 3.2.3Get the IPv4 InetAddress of the service.
Note: This return null if the service IPv4 address cannot be resolved.- Returns:
- Internet address
- See Also:
getInet4Addresses()
-
getInet6Address
@Deprecated public abstract Inet6Address getInet6Address()
Deprecated.since 3.2.3Get the IPv6 InetAddress of the service.
Note: This return null if the service IPv6 address cannot be resolved.- Returns:
- Internet address
- See Also:
getInet6Addresses()
-
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.7Get 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:
getPropertyNames()
,getPropertyBytes(String)
,getPropertyString(String)
-
getURL
@Deprecated public abstract String getURL()
Deprecated.since 3.2.3Get the URL for this service. An http URL is created by combining the address, port, and path properties.- Returns:
- service URL
- See Also:
getURLs()
-
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.3Get 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()
-
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()
Returnstrue
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()
-
-