Package javax.jmdns.impl
Class ServiceInfoImpl
- java.lang.Object
-
- javax.jmdns.ServiceInfo
-
- javax.jmdns.impl.ServiceInfoImpl
-
- All Implemented Interfaces:
Cloneable,DNSStatefulObject
public class ServiceInfoImpl extends ServiceInfo implements DNSStatefulObject
JmDNS service information.- Author:
- Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Victor Toni
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceServiceInfoImpl.Delegate-
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
-
-
Constructor Summary
Constructors Constructor Description ServiceInfoImpl(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, Map<String,?> props)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanadvanceState(DNSTask task)Sets the state and notifies all objects that wait on the ServiceInfo.Collection<DNSRecord>answers(DNSRecordClass recordClass, boolean unique, int ttl, HostInfo localHost)Create a series of answer that correspond with the give service info.voidassociateWithTask(DNSTask task, DNSState state)Sets the task associated with this Object.booleancancelState()Sets the state and notifies all objects that wait on the ServiceInfo.protected static Map<ServiceInfo.Fields,String>checkQualifiedNameMap(Map<ServiceInfo.Fields,String> qualifiedNameMap)ServiceInfoImplclone()booleancloseState()Sets the state and notifies all objects that wait on the ServiceInfo.static Map<ServiceInfo.Fields,String>decodeQualifiedNameMap(String type, String name, String subtype)static Map<ServiceInfo.Fields,String>decodeQualifiedNameMapForType(String type)booleanequals(Object obj)InetAddressgetAddress()Deprecated.StringgetApplication()Returns the application of the service info suitable for printing.JmDNSImplgetDns()Returns the DNS associated with this object.StringgetDomain()Returns the domain of the service info suitable for printing.StringgetHostAddress()Deprecated.String[]getHostAddresses()Returns the host IP addresses string in textual presentation.Inet4AddressgetInet4Address()Deprecated.Inet4Address[]getInet4Addresses()Returns a list of all IPv4 InetAddresses that can be used for this service.Inet6AddressgetInet6Address()Deprecated.Inet6Address[]getInet6Addresses()Returns a list of all IPv6 InetAddresses that can be used for this service.InetAddressgetInetAddress()Deprecated.InetAddress[]getInetAddresses()Returns a list of all InetAddresses that can be used for this service.StringgetKey()The key is used to retrieve service info in hash tables.
The key is the lower case qualified name.StringgetName()Unqualified service instance name, such asfoobar.StringgetNiceTextString()Returns a description of the service info suitable for printing.intgetPort()Get the port for the service.intgetPriority()Get the priority of the service.byte[]getPropertyBytes(String name)Get a property of the service.Enumeration<String>getPropertyNames()Enumeration of the property names.StringgetPropertyString(String name)Get a property of the service.StringgetProtocol()Returns the protocol of the service info suitable for printing.StringgetQualifiedName()Fully qualified service name, such asfoobar._http._tcp.local..Map<ServiceInfo.Fields,String>getQualifiedNameMap()Returns a dictionary of the fully qualified name component of this service.StringgetServer()Get the name of the server.StringgetSubtype()Returns the sub type of the service info suitable for printing.byte[]getTextBytes()Get the text for the service as raw bytes.StringgetTextString()Deprecated.StringgetType()Fully qualified service type name, such as_http._tcp.local.StringgetTypeWithSubtype()Fully qualified service type name with the subtype if appropriate, such as_printer._sub._http._tcp.local.StringgetURL()Deprecated.StringgetURL(String protocol)Deprecated.String[]getURLs()Get the list of URL for this service.String[]getURLs(String protocol)Get the list of URL for this service.intgetWeight()Get the weight of the service.booleanhasData()Returns true if the service info is filled with data.inthashCode()booleanhasSameAddresses(ServiceInfo other)Compare addresses of another ServiceInfobooleanisAnnounced()Returns true, if this is an announced state.booleanisAnnouncing()Returns true, if this is an announcing state.booleanisAssociatedWithTask(DNSTask task, DNSState state)Checks if this object is associated with the task and in the same state.booleanisCanceled()Returns true, if this is a canceled state.booleanisCanceling()Returns true, if this is a canceling state.booleanisClosed()Returns true, if this is a closed state.booleanisClosing()Returns true, if this is a closing state.booleanisPersistent()Returnstrueif ServiceListener.resolveService will be called whenever new new information is received.booleanisProbing()Returns true, if this is a probing state.booleanneedTextAnnouncing()booleanrecoverState()Sets the state and notifies all objects that wait on the ServiceInfo.voidremoveAssociationWithTask(DNSTask task)Remove the association of the task with this Object.booleanrevertState()Sets the state and notifies all objects that wait on the ServiceInfo.voidsetDns(JmDNSImpl dns)voidsetNeedTextAnnouncing(boolean needTextAnnouncing)voidsetText(byte[] text)Set the text for the service.voidsetText(Map<String,?> props)Set the text for the service.StringtoString()voidupdateRecord(DNSCache dnsCache, long now, DNSEntry dnsEntry)JmDNS callback to update a DNS record.booleanwaitForAnnounced(long timeout)Waits for the object to be announced.booleanwaitForCanceled(long timeout)Waits for the object to be canceled.
-
-
-
Constructor Detail
-
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:
ServiceInfo.create(String, String, int, int, int, String)
-
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:
ServiceInfo.create(String, String, int, int, int, Map)
-
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:
ServiceInfo.create(String, String, int, int, int, byte[])
-
ServiceInfoImpl
public ServiceInfoImpl(Map<ServiceInfo.Fields,String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, Map<String,?> props)
-
-
Method Detail
-
decodeQualifiedNameMap
public static Map<ServiceInfo.Fields,String> decodeQualifiedNameMap(String type, String name, String subtype)
-
decodeQualifiedNameMapForType
public static Map<ServiceInfo.Fields,String> decodeQualifiedNameMapForType(String type)
-
checkQualifiedNameMap
protected static Map<ServiceInfo.Fields,String> checkQualifiedNameMap(Map<ServiceInfo.Fields,String> qualifiedNameMap)
-
getType
public String getType()
Fully qualified service type name, such as_http._tcp.local.- Specified by:
getTypein classServiceInfo- Returns:
- service type name
-
getTypeWithSubtype
public String getTypeWithSubtype()
Fully qualified service type name with the subtype if appropriate, such as_printer._sub._http._tcp.local.- Specified by:
getTypeWithSubtypein classServiceInfo- Returns:
- service type name
-
getName
public String getName()
Unqualified service instance name, such asfoobar.- Specified by:
getNamein classServiceInfo- Returns:
- service name
-
getKey
public String getKey()
The key is used to retrieve service info in hash tables.
The key is the lower case qualified name.- Specified by:
getKeyin classServiceInfo- Returns:
- the key
-
getQualifiedName
public String getQualifiedName()
Fully qualified service name, such asfoobar._http._tcp.local..- Specified by:
getQualifiedNamein classServiceInfo- Returns:
- qualified service name
-
getServer
public String getServer()
Description copied from class:ServiceInfoGet the name of the server.- Specified by:
getServerin classServiceInfo- Returns:
- server name
- See Also:
ServiceInfo.getServer()
-
getHostAddress
@Deprecated public String getHostAddress()
Deprecated.Returns the host IP address string in textual presentation.
Note: This can be either an IPv4 or an IPv6 representation.- Specified by:
getHostAddressin classServiceInfo- Returns:
- the host raw IP address in a string format.
- See Also:
ServiceInfo.getHostAddresses()
-
getHostAddresses
public String[] getHostAddresses()
Returns the host IP addresses string in textual presentation.- Specified by:
getHostAddressesin classServiceInfo- Returns:
- list of host raw IP address in a string format.
-
getAddress
@Deprecated public InetAddress getAddress()
Deprecated.Get the host address of the service.- Specified by:
getAddressin classServiceInfo- Returns:
- host Internet address
- See Also:
ServiceInfo.getInetAddresses()
-
getInetAddress
@Deprecated public InetAddress 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:
getInetAddressin classServiceInfo- Returns:
- Internet address
- See Also:
ServiceInfo.getInetAddresses()
-
getInet4Address
@Deprecated public Inet4Address getInet4Address()
Deprecated.Get the IPv4 InetAddress of the service.
Note: This return null if the service IPv4 address cannot be resolved.- Specified by:
getInet4Addressin classServiceInfo- Returns:
- Internet address
- See Also:
ServiceInfo.getInet4Addresses()
-
getInet6Address
@Deprecated public Inet6Address getInet6Address()
Deprecated.Get the IPv6 InetAddress of the service.
Note: This return null if the service IPv6 address cannot be resolved.- Specified by:
getInet6Addressin classServiceInfo- Returns:
- Internet address
- See Also:
ServiceInfo.getInet6Addresses()
-
getInetAddresses
public InetAddress[] getInetAddresses()
Description copied from class:ServiceInfoReturns 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:
getInetAddressesin classServiceInfo- Returns:
- list of InetAddress objects
-
getInet4Addresses
public Inet4Address[] getInet4Addresses()
Description copied from class:ServiceInfoReturns 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:
getInet4Addressesin classServiceInfo- Returns:
- list of InetAddress objects
-
getInet6Addresses
public Inet6Address[] getInet6Addresses()
Description copied from class:ServiceInfoReturns 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:
getInet6Addressesin classServiceInfo- Returns:
- list of InetAddress objects
-
getPort
public int getPort()
Description copied from class:ServiceInfoGet the port for the service.- Specified by:
getPortin classServiceInfo- Returns:
- service port
- See Also:
ServiceInfo.getPort()
-
getPriority
public int getPriority()
Description copied from class:ServiceInfoGet the priority of the service.- Specified by:
getPriorityin classServiceInfo- Returns:
- service priority
- See Also:
ServiceInfo.getPriority()
-
getWeight
public int getWeight()
Description copied from class:ServiceInfoGet the weight of the service.- Specified by:
getWeightin classServiceInfo- Returns:
- service weight
- See Also:
ServiceInfo.getWeight()
-
getTextBytes
public byte[] getTextBytes()
Description copied from class:ServiceInfoGet the text for the service as raw bytes.- Specified by:
getTextBytesin classServiceInfo- Returns:
- raw service text
- See Also:
ServiceInfo.getTextBytes()
-
getTextString
@Deprecated public String 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:
getTextStringin classServiceInfo- Returns:
- service text
- See Also:
ServiceInfo.getPropertyNames(),ServiceInfo.getPropertyBytes(String),ServiceInfo.getPropertyString(String)
-
getURL
@Deprecated public String getURL()
Deprecated.Description copied from class:ServiceInfoGet the URL for this service. An http URL is created by combining the address, port, and path properties.- Specified by:
getURLin classServiceInfo- Returns:
- service URL
- See Also:
ServiceInfo.getURLs()
-
getURLs
public String[] getURLs()
Description copied from class:ServiceInfoGet the list of URL for this service. An http URL is created by combining the address, port, and path properties.- Specified by:
getURLsin classServiceInfo- Returns:
- list of service URL
-
getURL
@Deprecated public String getURL(String protocol)
Deprecated.Description copied from class:ServiceInfoGet the URL for this service. An URL is created by combining the protocol, address, port, and path properties.- Specified by:
getURLin classServiceInfo- Parameters:
protocol- requested protocol- Returns:
- service URL
- See Also:
ServiceInfo.getURLs()
-
getURLs
public String[] getURLs(String protocol)
Description copied from class:ServiceInfoGet the list of URL for this service. An URL is created by combining the protocol, address, port, and path properties.- Specified by:
getURLsin classServiceInfo- Parameters:
protocol- requested protocol- Returns:
- list of service URL
-
getPropertyBytes
public 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.- Specified by:
getPropertyBytesin classServiceInfo- Parameters:
name- property name- Returns:
- raw property text
-
getPropertyString
public 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.- Specified by:
getPropertyStringin classServiceInfo- Parameters:
name- property name- Returns:
- property text
-
getPropertyNames
public Enumeration<String> getPropertyNames()
Enumeration of the property names.- Specified by:
getPropertyNamesin classServiceInfo- Returns:
- property name enumeration
-
getApplication
public String getApplication()
Returns the application of the service info suitable for printing.- Specified by:
getApplicationin classServiceInfo- Returns:
- service application
-
getDomain
public String getDomain()
Returns the domain of the service info suitable for printing.- Specified by:
getDomainin classServiceInfo- Returns:
- service domain
-
getProtocol
public String getProtocol()
Returns the protocol of the service info suitable for printing.- Specified by:
getProtocolin classServiceInfo- Returns:
- service protocol
-
getSubtype
public String getSubtype()
Returns the sub type of the service info suitable for printing.- Specified by:
getSubtypein classServiceInfo- Returns:
- service sub type
-
getQualifiedNameMap
public Map<ServiceInfo.Fields,String> getQualifiedNameMap()
Returns a dictionary of the fully qualified name component of this service.- Specified by:
getQualifiedNameMapin classServiceInfo- Returns:
- dictionary of the fully qualified name components
-
updateRecord
public void updateRecord(DNSCache dnsCache, long now, DNSEntry dnsEntry)
JmDNS callback to update a DNS record.- Parameters:
dnsCache-now-dnsEntry-
-
hasData
public boolean hasData()
Returns true if the service info is filled with data.- Specified by:
hasDatain classServiceInfo- Returns:
trueif the service info has data,falseotherwise.
-
advanceState
public boolean advanceState(DNSTask task)
Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
advanceStatein interfaceDNSStatefulObject- Parameters:
task- associated task- Returns:
truefalse otherwise.- See Also:
DNSState.advance()
-
revertState
public boolean revertState()
Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
revertStatein interfaceDNSStatefulObject- Returns:
truefalse otherwise.- See Also:
DNSState.revert()
-
cancelState
public boolean cancelState()
Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
cancelStatein interfaceDNSStatefulObject- Returns:
truefalse otherwise.
-
closeState
public boolean closeState()
Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
closeStatein interfaceDNSStatefulObject- Returns:
truefalse otherwise.
-
recoverState
public boolean recoverState()
Sets the state and notifies all objects that wait on the ServiceInfo.- Specified by:
recoverStatein interfaceDNSStatefulObject- Returns:
truefalse otherwise.
-
removeAssociationWithTask
public void removeAssociationWithTask(DNSTask task)
Remove the association of the task with this Object.- Specified by:
removeAssociationWithTaskin interfaceDNSStatefulObject- Parameters:
task- associated task
-
associateWithTask
public void associateWithTask(DNSTask task, DNSState state)
Sets the task associated with this Object.- Specified by:
associateWithTaskin interfaceDNSStatefulObject- Parameters:
task- associated taskstate- state of the task
-
isAssociatedWithTask
public boolean isAssociatedWithTask(DNSTask task, DNSState state)
Checks if this object is associated with the task and in the same state.- Specified by:
isAssociatedWithTaskin interfaceDNSStatefulObject- Parameters:
task- associated taskstate- state of the task- Returns:
trueis the task is associated with this object,falseotherwise.
-
isProbing
public boolean isProbing()
Returns true, if this is a probing state.- Specified by:
isProbingin interfaceDNSStatefulObject- Returns:
trueif probing state,falseotherwise
-
isAnnouncing
public boolean isAnnouncing()
Returns true, if this is an announcing state.- Specified by:
isAnnouncingin interfaceDNSStatefulObject- Returns:
trueif announcing state,falseotherwise
-
isAnnounced
public boolean isAnnounced()
Returns true, if this is an announced state.- Specified by:
isAnnouncedin interfaceDNSStatefulObject- Returns:
trueif announced state,falseotherwise
-
isCanceling
public boolean isCanceling()
Returns true, if this is a canceling state.- Specified by:
isCancelingin interfaceDNSStatefulObject- Returns:
trueif canceling state,falseotherwise
-
isCanceled
public boolean isCanceled()
Returns true, if this is a canceled state.- Specified by:
isCanceledin interfaceDNSStatefulObject- Returns:
trueif canceled state,falseotherwise
-
isClosing
public boolean isClosing()
Returns true, if this is a closing state.- Specified by:
isClosingin interfaceDNSStatefulObject- Returns:
trueif closing state,falseotherwise
-
isClosed
public boolean isClosed()
Returns true, if this is a closed state.- Specified by:
isClosedin interfaceDNSStatefulObject- Returns:
trueif closed state,falseotherwise
-
waitForAnnounced
public boolean waitForAnnounced(long timeout)
Waits for the object to be announced.- Specified by:
waitForAnnouncedin interfaceDNSStatefulObject- Parameters:
timeout- the maximum time to wait in milliseconds.- Returns:
trueif the object is announced,falseotherwise
-
waitForCanceled
public boolean waitForCanceled(long timeout)
Waits for the object to be canceled.- Specified by:
waitForCanceledin interfaceDNSStatefulObject- Parameters:
timeout- the maximum time to wait in milliseconds.- Returns:
trueif the object is canceled,falseotherwise
-
getNiceTextString
public String getNiceTextString()
Returns a description of the service info suitable for printing.- Specified by:
getNiceTextStringin classServiceInfo- Returns:
- service info description
-
clone
public ServiceInfoImpl clone()
- Overrides:
clonein classServiceInfo
-
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
public void setText(byte[] text) throws IllegalStateExceptionSet the text for the service. Setting the text will fore a re-announce of the service.- Specified by:
setTextin 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
public void setText(Map<String,?> props) throws IllegalStateException
Set the text for the service. Setting the text will fore a re-announce of the service.- Specified by:
setTextin 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.
-
setDns
public void setDns(JmDNSImpl dns)
-
getDns
public JmDNSImpl getDns()
Returns the DNS associated with this object.- Specified by:
getDnsin interfaceDNSStatefulObject- Returns:
- DNS resolver
-
isPersistent
public boolean isPersistent()
Returnstrueif ServiceListener.resolveService will be called whenever new new information is received.- Specified by:
isPersistentin classServiceInfo- Returns:
- the persistent
-
setNeedTextAnnouncing
public void setNeedTextAnnouncing(boolean needTextAnnouncing)
- Parameters:
needTextAnnouncing- the needTextAnnouncing to set
-
needTextAnnouncing
public boolean needTextAnnouncing()
- Returns:
- the needTextAnnouncing
-
hasSameAddresses
public boolean hasSameAddresses(ServiceInfo other)
Description copied from class:ServiceInfoCompare addresses of another ServiceInfo- Specified by:
hasSameAddressesin classServiceInfo- Parameters:
other- ServiceInfo to compare- Returns:
- true if addresses are the same, false if not
-
-