Package javax.jmdns.impl
Class ServiceInfoImpl
java.lang.Object
javax.jmdns.ServiceInfo
javax.jmdns.impl.ServiceInfoImpl
- All Implemented Interfaces:
Cloneable
,DNSListener
,DNSStatefulObject
JmDNS service information.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
private static final class
Nested classes/interfaces inherited from class javax.jmdns.ServiceInfo
ServiceInfo.Fields
Nested classes/interfaces inherited from interface javax.jmdns.impl.DNSStatefulObject
DNSStatefulObject.DefaultImplementation, DNSStatefulObject.DNSStatefulObjectSemaphore
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private ServiceInfoImpl.Delegate
private String
private final Set
<Inet4Address> private final Set
<Inet6Address> private String
private String
private boolean
private boolean
private int
private int
private String
private String
private final ServiceInfoImpl.ServiceInfoState
private String
private byte[]
private int
private static org.slf4j.Logger
-
Constructor Summary
ConstructorsConstructorDescriptionServiceInfoImpl
(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, byte[] text) ServiceInfoImpl
(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, String text) ServiceInfoImpl
(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, Map<String, ?> props) ServiceInfoImpl
(Map<ServiceInfo.Fields, String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, byte[] text) ServiceInfoImpl
(Map<ServiceInfo.Fields, String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, String text) ServiceInfoImpl
(Map<ServiceInfo.Fields, String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, Map<String, ?> props) ServiceInfoImpl
(ServiceInfo info) During recovery we need to duplicate service info to reregister them -
Method Summary
Modifier and TypeMethodDescription(package private) void
_setText
(byte[] text) This is used internally by the framework(package private) void
addAddress
(Inet4Address addr) (package private) void
addAddress
(Inet6Address addr) boolean
advanceState
(DNSTask task) Sets the state and notifies all objects that wait on the ServiceInfo.answers
(DNSRecordClass recordClass, boolean unique, int ttl, HostInfo localHost) Create a series of answer that correspond with the give service info.void
associateWithTask
(DNSTask task, DNSState state) Sets the task associated with this Object.boolean
Sets the state and notifies all objects that wait on the ServiceInfo.protected static Map
<ServiceInfo.Fields, String> checkQualifiedNameMap
(Map<ServiceInfo.Fields, String> qualifiedNameMap) clone()
boolean
Sets the state and notifies all objects that wait on the ServiceInfo.(package private) static Map
<ServiceInfo.Fields, String> createQualifiedMap
(String instance, String application, String protocol, String domain, String subtype) boolean
Deprecated.Returns the application of the service info suitable for printing.(package private) ServiceInfoImpl.Delegate
getDns()
Returns the DNS associated with this object.Returns the domain of the service info suitable for printing.Deprecated.String[]
Returns the host IP addresses string in textual presentation.Deprecated.Returns a list of all IPv4 InetAddresses that can be used for this service.Deprecated.Returns a list of all IPv6 InetAddresses that can be used for this service.Deprecated.Returns a list of all InetAddresses that can be used for this service.getKey()
The key is used to retrieve service info in hash tables.
The key is the lower case qualified name.getName()
Unqualified service instance name, such asfoobar
.Returns a description of the service info suitable for printing.int
getPort()
Get the port for the service.int
Get the priority of the service.byte[]
getPropertyBytes
(String name) Get a property of the service.Enumeration of the property names.getPropertyString
(String name) Get a property of the service.Returns the protocol of the service info suitable for printing.Fully qualified service name, such asfoobar._http._tcp.local.
.Returns a dictionary of the fully qualified name component of this service.Get the name of the server.Returns the sub type of the service info suitable for printing.byte[]
Get the text for the service as raw bytes.Deprecated.getType()
Fully qualified service type name, such as_http._tcp.local.
Fully qualified service type name with the subtype if appropriate, such as_printer._sub._http._tcp.local.
getURL()
Deprecated.Deprecated.String[]
getURLs()
Get the list of URL for this service.String[]
Get the list of URL for this service.int
Get the weight of the service.private boolean
handleExpiredRecord
(DNSRecord record) Handles expired records insofar that it removes their content from this service.private boolean
handleUpdateRecord
(DNSCache dnsCache, long now, DNSRecord record) Adds data ofDNSRecord
to the internal service representation.boolean
hasData()
Returns true if the service info is filled with data.int
hashCode()
private final boolean
boolean
hasSameAddresses
(ServiceInfo other) Compare addresses of another ServiceInfoboolean
Returns true if the service info has a serverboolean
Returns true, if this is an announced state.boolean
Returns true, if this is an announcing state.boolean
isAssociatedWithTask
(DNSTask task, DNSState state) Checks if this object is associated with the task and in the same state.boolean
Returns true, if this is a canceled state.boolean
Returns true, if this is a canceling state.boolean
isClosed()
Returns true, if this is a closed state.boolean
Returns true, if this is a closing state.boolean
Returnstrue
if ServiceListener.resolveService will be called whenever new new information is received.boolean
Returns true, if this is a probing state.boolean
boolean
Sets the state and notifies all objects that wait on the ServiceInfo.void
Remove the association of the task with this Object.(package private) static String
removeSeparators
(String name) boolean
Sets the state and notifies all objects that wait on the ServiceInfo.(package private) void
setDelegate
(ServiceInfoImpl.Delegate delegate) void
(package private) void
Sets the service instance name.void
setNeedTextAnnouncing
(boolean needTextAnnouncing) (package private) void
void
setText
(byte[] text) Set the text for the service.void
Set the text for the service.toString()
void
updateRecord
(DNSCache dnsCache, long now, DNSEntry dnsEntry) JmDNS callback to update a DNS record.boolean
waitForAnnounced
(long timeout) Waits for the object to be announced.boolean
waitForCanceled
(long timeout) Waits for the object to be canceled.
-
Field Details
-
logger
private static org.slf4j.Logger logger -
_domain
-
_protocol
-
_application
-
_name
-
_subtype
-
_server
-
_port
private int _port -
_weight
private int _weight -
_priority
private int _priority -
_text
private byte[] _text -
_props
-
_ipv4Addresses
-
_ipv6Addresses
-
_key
-
_persistent
private boolean _persistent -
_needTextAnnouncing
private boolean _needTextAnnouncing -
_state
-
_delegate
-
-
Constructor Details
-
ServiceInfoImpl
public ServiceInfoImpl(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, String text) - Parameters:
type
-name
-subtype
-port
-weight
-priority
-persistent
-text
-- See Also:
-
ServiceInfoImpl
public ServiceInfoImpl(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, Map<String, ?> props) - Parameters:
type
-name
-subtype
-port
-weight
-priority
-persistent
-props
-- See Also:
-
ServiceInfoImpl
public ServiceInfoImpl(String type, String name, String subtype, int port, int weight, int priority, boolean persistent, byte[] text) - Parameters:
type
-name
-subtype
-port
-weight
-priority
-persistent
-text
-- See Also:
-
ServiceInfoImpl
public ServiceInfoImpl(Map<ServiceInfo.Fields, String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, Map<String, ?> props) -
ServiceInfoImpl
ServiceInfoImpl(Map<ServiceInfo.Fields, String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, String text) -
ServiceInfoImpl
ServiceInfoImpl(Map<ServiceInfo.Fields, String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, byte[] text) -
ServiceInfoImpl
ServiceInfoImpl(ServiceInfo info) During recovery we need to duplicate service info to reregister them- Parameters:
info
-
-
-
Method Details
-
createQualifiedMap
-
checkQualifiedNameMap
protected static Map<ServiceInfo.Fields,String> checkQualifiedNameMap(Map<ServiceInfo.Fields, String> qualifiedNameMap) -
removeSeparators
-
getType
Fully qualified service type name, such as_http._tcp.local.
- Specified by:
getType
in classServiceInfo
- Returns:
- service type name
-
getTypeWithSubtype
Fully qualified service type name with the subtype if appropriate, such as_printer._sub._http._tcp.local.
- Specified by:
getTypeWithSubtype
in classServiceInfo
- Returns:
- service type name
-
getName
Unqualified service instance name, such asfoobar
.- Specified by:
getName
in classServiceInfo
- Returns:
- service name
-
getKey
The key is used to retrieve service info in hash tables.
The key is the lower case qualified name.- Specified by:
getKey
in classServiceInfo
- Returns:
- the key
-
setName
Sets the service instance name.- Parameters:
name
- unqualified service instance name, such asfoobar
-
getQualifiedName
Fully qualified service name, such asfoobar._http._tcp.local.
.- Specified by:
getQualifiedName
in classServiceInfo
- Returns:
- qualified service name
-
getServer
Description copied from class:ServiceInfo
Get the name of the server. Note: This will be an empty string if no value has been set- Specified by:
getServer
in classServiceInfo
- Returns:
- server name
- See Also:
-
hasServer
public boolean hasServer()Description copied from class:ServiceInfo
Returns true if the service info has a server- Specified by:
hasServer
in classServiceInfo
- Returns:
true
if the service info has a server specified,false
otherwise.- See Also:
-
setServer
- Parameters:
server
- the server to set
-
getHostAddress
Deprecated.Returns the host IP address string in textual presentation.
Note: This can be either an IPv4 or an IPv6 representation.- Specified by:
getHostAddress
in classServiceInfo
- Returns:
- the host raw IP address in a string format.
- See Also:
-
getHostAddresses
Returns the host IP addresses string in textual presentation.- Specified by:
getHostAddresses
in classServiceInfo
- Returns:
- list of host raw IP address in a string format.
-
addAddress
- Parameters:
addr
- the addr to add
-
addAddress
- Parameters:
addr
- the addr to add
-
getAddress
Deprecated.Get the host address of the service.- Specified by:
getAddress
in classServiceInfo
- Returns:
- host Internet address
- See Also:
-
getInetAddress
Deprecated.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.- Specified by:
getInetAddress
in classServiceInfo
- Returns:
- Internet address
- See Also:
-
getInet4Address
Deprecated.Get the IPv4 InetAddress of the service.
Note: This return null if the service IPv4 address cannot be resolved.- Specified by:
getInet4Address
in classServiceInfo
- Returns:
- Internet address
- See Also:
-
getInet6Address
Deprecated.Get the IPv6 InetAddress of the service.
Note: This return null if the service IPv6 address cannot be resolved.- Specified by:
getInet6Address
in classServiceInfo
- Returns:
- Internet address
- See Also:
-
getInetAddresses
Description copied from class:ServiceInfo
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.
- Specified by:
getInetAddresses
in classServiceInfo
- Returns:
- list of InetAddress objects
-
getInet4Addresses
Description copied from class:ServiceInfo
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.
- Specified by:
getInet4Addresses
in classServiceInfo
- Returns:
- list of InetAddress objects
-
getInet6Addresses
Description copied from class:ServiceInfo
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.
- Specified by:
getInet6Addresses
in classServiceInfo
- Returns:
- list of InetAddress objects
-
getPort
public int getPort()Description copied from class:ServiceInfo
Get the port for the service.- Specified by:
getPort
in classServiceInfo
- Returns:
- service port
- See Also:
-
getPriority
public int getPriority()Description copied from class:ServiceInfo
Get the priority of the service.- Specified by:
getPriority
in classServiceInfo
- Returns:
- service priority
- See Also:
-
getWeight
public int getWeight()Description copied from class:ServiceInfo
Get the weight of the service.- Specified by:
getWeight
in classServiceInfo
- Returns:
- service weight
- See Also:
-
getTextBytes
public byte[] getTextBytes()Description copied from class:ServiceInfo
Get the text for the service as raw bytes.- Specified by:
getTextBytes
in classServiceInfo
- Returns:
- raw service text
- See Also:
-
getTextString
Deprecated.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.- Specified by:
getTextString
in classServiceInfo
- Returns:
- service text
- See Also:
-
getURL
Deprecated.Description copied from class:ServiceInfo
Get the URL for this service. An http URL is created by combining the address, port, and path properties.- Specified by:
getURL
in classServiceInfo
- Returns:
- service URL
- See Also:
-
getURLs
Description copied from class:ServiceInfo
Get the list of URL for this service. An http URL is created by combining the address, port, and path properties.- Specified by:
getURLs
in classServiceInfo
- Returns:
- list of service URL
-
getURL
Deprecated.Description copied from class:ServiceInfo
Get the URL for this service. An URL is created by combining the protocol, address, port, and path properties.- Specified by:
getURL
in classServiceInfo
- Parameters:
protocol
- requested protocol- Returns:
- service URL
- See Also:
-
getURLs
Description copied from class:ServiceInfo
Get the list of URL for this service. An URL is created by combining the protocol, address, port, and path properties.- Specified by:
getURLs
in classServiceInfo
- Parameters:
protocol
- requested protocol- Returns:
- list of service URL
-
getPropertyBytes
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.- Specified by:
getPropertyBytes
in classServiceInfo
- Parameters:
name
- property name- Returns:
- raw property text
-
getPropertyString
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.- Specified by:
getPropertyString
in classServiceInfo
- Parameters:
name
- property name- Returns:
- property text
-
getPropertyNames
Enumeration of the property names.- Specified by:
getPropertyNames
in classServiceInfo
- Returns:
- property name enumeration
-
getApplication
Returns the application of the service info suitable for printing.- Specified by:
getApplication
in classServiceInfo
- Returns:
- service application
-
getDomain
Returns the domain of the service info suitable for printing.- Specified by:
getDomain
in classServiceInfo
- Returns:
- service domain
-
getProtocol
Returns the protocol of the service info suitable for printing.- Specified by:
getProtocol
in classServiceInfo
- Returns:
- service protocol
-
getSubtype
Returns the sub type of the service info suitable for printing.- Specified by:
getSubtype
in classServiceInfo
- Returns:
- service sub type
-
getQualifiedNameMap
Returns a dictionary of the fully qualified name component of this service.- Specified by:
getQualifiedNameMap
in classServiceInfo
- Returns:
- dictionary of the fully qualified name components
-
getProperties
-
updateRecord
JmDNS callback to update a DNS record.- Specified by:
updateRecord
in interfaceDNSListener
- Parameters:
dnsCache
-now
-dnsEntry
-
-
handleExpiredRecord
Handles expired records insofar that it removes their content from this service. Implementation note:
Currently only expired A and AAAA records are handled.- Parameters:
record
- to check for data to be removed- Returns:
true
if data from the expired record could be removed from this service,false
otherwise
-
handleUpdateRecord
Adds data ofDNSRecord
to the internal service representation.- Parameters:
dnsCache
-now
-record
- to get data from- Returns:
true
if service was updated,false
otherwise
-
hasData
public boolean hasData()Returns true if the service info is filled with data.- Specified by:
hasData
in classServiceInfo
- Returns:
true
if the service info has data,false
otherwise.
-
hasInetAddress
private final boolean hasInetAddress() -
advanceState
Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
advanceState
in interfaceDNSStatefulObject
- Parameters:
task
- associated task- Returns:
true
if the state was changed by this thread,false
otherwise.- See Also:
-
revertState
public boolean revertState()Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
revertState
in interfaceDNSStatefulObject
- Returns:
true
if the state was changed by this thread,false
otherwise.- See Also:
-
cancelState
public boolean cancelState()Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
cancelState
in interfaceDNSStatefulObject
- Returns:
true
if the state was changed by this thread,false
otherwise.
-
closeState
public boolean closeState()Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
closeState
in interfaceDNSStatefulObject
- Returns:
true
if the state was changed by this thread,false
otherwise.
-
recoverState
public boolean recoverState()Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
recoverState
in interfaceDNSStatefulObject
- Returns:
true
if the state was changed by this thread,false
otherwise.
-
removeAssociationWithTask
Remove the association of the task with this Object.- Specified by:
removeAssociationWithTask
in interfaceDNSStatefulObject
- Parameters:
task
- associated task
-
associateWithTask
Sets the task associated with this Object.- Specified by:
associateWithTask
in interfaceDNSStatefulObject
- Parameters:
task
- associated taskstate
- state of the task
-
isAssociatedWithTask
Checks if this object is associated with the task and in the same state.- Specified by:
isAssociatedWithTask
in interfaceDNSStatefulObject
- Parameters:
task
- associated taskstate
- state of the task- Returns:
true
is the task is associated with this object,false
otherwise.
-
isProbing
public boolean isProbing()Returns true, if this is a probing state.- Specified by:
isProbing
in interfaceDNSStatefulObject
- Returns:
true
if probing state,false
otherwise
-
isAnnouncing
public boolean isAnnouncing()Returns true, if this is an announcing state.- Specified by:
isAnnouncing
in interfaceDNSStatefulObject
- Returns:
true
if announcing state,false
otherwise
-
isAnnounced
public boolean isAnnounced()Returns true, if this is an announced state.- Specified by:
isAnnounced
in interfaceDNSStatefulObject
- Returns:
true
if announced state,false
otherwise
-
isCanceling
public boolean isCanceling()Returns true, if this is a canceling state.- Specified by:
isCanceling
in interfaceDNSStatefulObject
- Returns:
true
if canceling state,false
otherwise
-
isCanceled
public boolean isCanceled()Returns true, if this is a canceled state.- Specified by:
isCanceled
in interfaceDNSStatefulObject
- Returns:
true
if canceled state,false
otherwise
-
isClosing
public boolean isClosing()Returns true, if this is a closing state.- Specified by:
isClosing
in interfaceDNSStatefulObject
- Returns:
true
if closing state,false
otherwise
-
isClosed
public boolean isClosed()Returns true, if this is a closed state.- Specified by:
isClosed
in interfaceDNSStatefulObject
- Returns:
true
if closed state,false
otherwise
-
waitForAnnounced
public boolean waitForAnnounced(long timeout) Waits for the object to be announced.- Specified by:
waitForAnnounced
in interfaceDNSStatefulObject
- Parameters:
timeout
- the maximum time to wait in milliseconds.- Returns:
true
if the object is announced,false
otherwise
-
waitForCanceled
public boolean waitForCanceled(long timeout) Waits for the object to be canceled.- Specified by:
waitForCanceled
in interfaceDNSStatefulObject
- Parameters:
timeout
- the maximum time to wait in milliseconds.- Returns:
true
if the object is canceled,false
otherwise
-
hashCode
public int hashCode() -
equals
-
getNiceTextString
Returns a description of the service info suitable for printing.- Specified by:
getNiceTextString
in classServiceInfo
- Returns:
- service info description
-
clone
- Overrides:
clone
in classServiceInfo
-
toString
-
answers
public Collection<DNSRecord> answers(DNSRecordClass recordClass, boolean unique, int ttl, HostInfo localHost) Create a series of answer that correspond with the give service info.- Parameters:
recordClass
- record class of the queryunique
-ttl
-localHost
-- Returns:
- collection of answers
-
setText
Set the text for the service. Setting the text will fore a re-announce of the service.- Specified by:
setText
in classServiceInfo
- 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
Set the text for the service. Setting the text will fore a re-announce of the service.- Specified by:
setText
in classServiceInfo
- 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.
-
_setText
void _setText(byte[] text) This is used internally by the framework- Parameters:
text
-
-
setDns
-
getDns
Returns the DNS associated with this object.- Specified by:
getDns
in interfaceDNSStatefulObject
- Returns:
- DNS resolver
-
isPersistent
public boolean isPersistent()Returnstrue
if ServiceListener.resolveService will be called whenever new new information is received.- Specified by:
isPersistent
in classServiceInfo
- Returns:
- the persistent
-
setNeedTextAnnouncing
public void setNeedTextAnnouncing(boolean needTextAnnouncing) - Parameters:
needTextAnnouncing
- the needTextAnnouncing to set
-
needTextAnnouncing
public boolean needTextAnnouncing()- Returns:
- the needTextAnnouncing
-
getDelegate
ServiceInfoImpl.Delegate getDelegate()- Returns:
- the delegate
-
setDelegate
- Parameters:
delegate
- the delegate to set
-
hasSameAddresses
Description copied from class:ServiceInfo
Compare addresses of another ServiceInfo- Specified by:
hasSameAddresses
in classServiceInfo
- Parameters:
other
- ServiceInfo to compare- Returns:
- true if addresses are the same, false if not
-