Package javax.jmdns.impl
Class JmmDNSImpl
- java.lang.Object
-
- javax.jmdns.impl.JmmDNSImpl
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,EventListener
,ServiceInfoImpl.Delegate
,JmmDNS
,NetworkTopologyListener
public class JmmDNSImpl extends Object implements JmmDNS, NetworkTopologyListener, ServiceInfoImpl.Delegate
This class enable multihoming mDNS. It will open a mDNS per IP address of the machine.- Author:
- Cédrik Lime, Pierre Frisch
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.jmdns.JmmDNS
JmmDNS.Factory
-
-
Constructor Summary
Constructors Constructor Description JmmDNSImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addNetworkTopologyListener(NetworkTopologyListener listener)
Listen to network changes.void
addServiceListener(String type, ServiceListener listener)
Listen for services of a given type.void
addServiceTypeListener(ServiceTypeListener listener)
Listen for service types.void
close()
JmDNS[]
getDNS()
Return a list of all the registered JmDNS instancesString[]
getHostNames()
Return the list HostName associated with this JmmDNS instance.InetAddress[]
getInetAddresses()
Return the list of addresses of the interface to which this instance of JmmDNS is bound.InetAddress[]
getInterfaces()
Deprecated.String[]
getNames()
Return the names of the JmDNS instances.ServiceInfo[]
getServiceInfos(String type, String name)
Get service information.ServiceInfo[]
getServiceInfos(String type, String name, boolean persistent)
Get service information.ServiceInfo[]
getServiceInfos(String type, String name, boolean persistent, long timeout)
Get service information.ServiceInfo[]
getServiceInfos(String type, String name, long timeout)
Get service information.void
inetAddressAdded(NetworkTopologyEvent event)
A network address has been added.void
inetAddressRemoved(NetworkTopologyEvent event)
A network address has been removed.ServiceInfo[]
list(String type)
Returns a list of service infos of the specified type.ServiceInfo[]
list(String type, long timeout)
Returns a list of service infos of the specified type.Map<String,ServiceInfo[]>
listBySubtype(String type)
Returns a list of service infos of the specified type sorted by subtype.Map<String,ServiceInfo[]>
listBySubtype(String type, long timeout)
Returns a list of service infos of the specified type sorted by subtype.NetworkTopologyListener[]
networkListeners()
Returns list of network change listenersvoid
registerService(ServiceInfo info)
Register a service.void
registerServiceType(String type)
Register a service type.void
removeNetworkTopologyListener(NetworkTopologyListener listener)
Remove listener for network changes.void
removeServiceListener(String type, ServiceListener listener)
Remove listener for services of a given type.void
removeServiceTypeListener(ServiceTypeListener listener)
Remove listener for service types.void
requestServiceInfo(String type, String name)
Request service information.void
requestServiceInfo(String type, String name, boolean persistent)
Request service information.void
requestServiceInfo(String type, String name, boolean persistent, long timeout)
Request service information.void
requestServiceInfo(String type, String name, long timeout)
Request service information.void
textValueUpdated(ServiceInfo target, byte[] value)
void
unregisterAllServices()
Unregister all services.void
unregisterService(ServiceInfo info)
Unregister a service.
-
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getNames
public String[] getNames()
Description copied from interface:JmmDNS
Return the names of the JmDNS instances.- Specified by:
getNames
in interfaceJmmDNS
- Returns:
- list of name of the JmDNS
- See Also:
JmDNS.getName()
-
getHostNames
public String[] getHostNames()
Description copied from interface:JmmDNS
Return the list HostName associated with this JmmDNS instance.- Specified by:
getHostNames
in interfaceJmmDNS
- Returns:
- list of host names
- See Also:
JmDNS.getHostName()
-
getInetAddresses
public InetAddress[] getInetAddresses() throws IOException
Description copied from interface:JmmDNS
Return the list of addresses of the interface to which this instance of JmmDNS is bound.- Specified by:
getInetAddresses
in interfaceJmmDNS
- Returns:
- list of Internet Address
- Throws:
IOException
- See Also:
JmDNS.getInetAddress()
-
getDNS
public JmDNS[] getDNS()
Description copied from interface:JmmDNS
Return a list of all the registered JmDNS instances
-
getInterfaces
@Deprecated public InetAddress[] getInterfaces() throws IOException
Deprecated.Description copied from interface:JmmDNS
Return the list of addresses of the interface to which this instance of JmmDNS is bound.- Specified by:
getInterfaces
in interfaceJmmDNS
- Returns:
- list of Internet Address
- Throws:
IOException
- See Also:
JmDNS.getInterface()
-
getServiceInfos
public ServiceInfo[] getServiceInfos(String type, String name)
Description copied from interface:JmmDNS
Get service information. If the information is not cached, the method will block until updated information is received on all DNS. Usage note: Do not call this method from the AWT event dispatcher thread. You will make the user interface unresponsive.- Specified by:
getServiceInfos
in interfaceJmmDNS
- Parameters:
type
- fully qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.- Returns:
- list of service info. If no service info is found the list is empty.
- See Also:
JmDNS.getServiceInfo(java.lang.String, java.lang.String)
-
getServiceInfos
public ServiceInfo[] getServiceInfos(String type, String name, long timeout)
Description copied from interface:JmmDNS
Get service information. If the information is not cached, the method will block until updated information is received on all DNS. Usage note: If you call this method from the AWT event dispatcher thread, use a small timeout, or you will make the user interface unresponsive.- Specified by:
getServiceInfos
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.timeout
- timeout in milliseconds. Typical timeout should be 5s.- Returns:
- list of service info. If no service info is found the list is empty.
- See Also:
JmDNS.getServiceInfo(java.lang.String, java.lang.String, long)
-
getServiceInfos
public ServiceInfo[] getServiceInfos(String type, String name, boolean persistent)
Description copied from interface:JmmDNS
Get service information. If the information is not cached, the method will block until updated information is received on all DNS. Usage note: If you call this method from the AWT event dispatcher thread, use a small timeout, or you will make the user interface unresponsive.- Specified by:
getServiceInfos
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.persistent
- iftrue
ServiceListener.resolveService will be called whenever new new information is received.- Returns:
- list of service info. If no service info is found the list is empty.
- See Also:
JmDNS.getServiceInfo(java.lang.String, java.lang.String, boolean)
-
getServiceInfos
public ServiceInfo[] getServiceInfos(String type, String name, boolean persistent, long timeout)
Description copied from interface:JmmDNS
Get service information. If the information is not cached, the method will block until updated information is received on all DNS. Usage note: If you call this method from the AWT event dispatcher thread, use a small timeout, or you will make the user interface unresponsive.- Specified by:
getServiceInfos
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.persistent
- iftrue
ServiceListener.resolveService will be called whenever new new information is received.timeout
- timeout in milliseconds. Typical timeout should be 5s.- Returns:
- list of service info. If no service info is found the list is empty.
- See Also:
JmDNS.getServiceInfo(java.lang.String, java.lang.String, boolean, long)
-
requestServiceInfo
public void requestServiceInfo(String type, String name)
Description copied from interface:JmmDNS
Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfo
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.- See Also:
JmDNS.requestServiceInfo(java.lang.String, java.lang.String)
-
requestServiceInfo
public void requestServiceInfo(String type, String name, boolean persistent)
Description copied from interface:JmmDNS
Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfo
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.persistent
- iftrue
ServiceListener.resolveService will be called whenever new new information is received.- See Also:
JmDNS.requestServiceInfo(java.lang.String, java.lang.String, boolean)
-
requestServiceInfo
public void requestServiceInfo(String type, String name, long timeout)
Description copied from interface:JmmDNS
Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfo
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.timeout
- timeout in milliseconds- See Also:
JmDNS.requestServiceInfo(java.lang.String, java.lang.String, long)
-
requestServiceInfo
public void requestServiceInfo(String type, String name, boolean persistent, long timeout)
Description copied from interface:JmmDNS
Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfo
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.name
- unqualified service name, such asfoobar
.persistent
- iftrue
ServiceListener.resolveService will be called whenever new new information is received.timeout
- timeout in milliseconds- See Also:
JmDNS.requestServiceInfo(java.lang.String, java.lang.String, boolean, long)
-
addServiceTypeListener
public void addServiceTypeListener(ServiceTypeListener listener) throws IOException
Description copied from interface:JmmDNS
Listen for service types.- Specified by:
addServiceTypeListener
in interfaceJmmDNS
- Parameters:
listener
- listener for service types- Throws:
IOException
- See Also:
JmDNS.addServiceTypeListener(javax.jmdns.ServiceTypeListener)
-
removeServiceTypeListener
public void removeServiceTypeListener(ServiceTypeListener listener)
Description copied from interface:JmmDNS
Remove listener for service types.- Specified by:
removeServiceTypeListener
in interfaceJmmDNS
- Parameters:
listener
- listener for service types- See Also:
JmDNS.removeServiceTypeListener(javax.jmdns.ServiceTypeListener)
-
addServiceListener
public void addServiceListener(String type, ServiceListener listener)
Description copied from interface:JmmDNS
Listen for services of a given type. The type has to be a fully qualified type name such as_http._tcp.local.
.- Specified by:
addServiceListener
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.listener
- listener for service updates- See Also:
JmDNS.addServiceListener(java.lang.String, javax.jmdns.ServiceListener)
-
removeServiceListener
public void removeServiceListener(String type, ServiceListener listener)
Description copied from interface:JmmDNS
Remove listener for services of a given type.- Specified by:
removeServiceListener
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.listener
- listener for service updates- See Also:
JmDNS.removeServiceListener(java.lang.String, javax.jmdns.ServiceListener)
-
textValueUpdated
public void textValueUpdated(ServiceInfo target, byte[] value)
- Specified by:
textValueUpdated
in interfaceServiceInfoImpl.Delegate
-
registerService
public void registerService(ServiceInfo info) throws IOException
Description copied from interface:JmmDNS
Register a service. The service is registered for access by other jmdns clients. The name of the service may be changed to make it unique.
Note the Service info is cloned for each network interface.- Specified by:
registerService
in interfaceJmmDNS
- Parameters:
info
- service info to register- Throws:
IOException
- See Also:
JmDNS.registerService(javax.jmdns.ServiceInfo)
-
unregisterService
public void unregisterService(ServiceInfo info)
Description copied from interface:JmmDNS
Unregister a service. The service should have been registered.- Specified by:
unregisterService
in interfaceJmmDNS
- Parameters:
info
- service info to remove- See Also:
JmDNS.unregisterService(javax.jmdns.ServiceInfo)
-
unregisterAllServices
public void unregisterAllServices()
Description copied from interface:JmmDNS
Unregister all services.- Specified by:
unregisterAllServices
in interfaceJmmDNS
- See Also:
JmDNS.unregisterAllServices()
-
registerServiceType
public void registerServiceType(String type)
Description copied from interface:JmmDNS
Register a service type. If this service type was not already known, all service listeners will be notified of the new service type. Service types are automatically registered as they are discovered.- Specified by:
registerServiceType
in interfaceJmmDNS
- Parameters:
type
- full qualified service type, such as_http._tcp.local.
.- See Also:
JmDNS.registerServiceType(java.lang.String)
-
list
public ServiceInfo[] list(String type)
Description copied from interface:JmmDNS
Returns a list of service infos of the specified type.- Specified by:
list
in interfaceJmmDNS
- Parameters:
type
- Service type name, such as_http._tcp.local.
.- Returns:
- An array of service instance.
- See Also:
JmDNS.list(java.lang.String)
-
list
public ServiceInfo[] list(String type, long timeout)
Description copied from interface:JmmDNS
Returns a list of service infos of the specified type.- Specified by:
list
in interfaceJmmDNS
- Parameters:
type
- Service type name, such as_http._tcp.local.
.timeout
- timeout in milliseconds. Typical timeout should be 6s.- Returns:
- An array of service instance.
- See Also:
JmDNS.list(java.lang.String, long)
-
listBySubtype
public Map<String,ServiceInfo[]> listBySubtype(String type)
Description copied from interface:JmmDNS
Returns a list of service infos of the specified type sorted by subtype. Any service that do not register a subtype is listed in the empty subtype section.- Specified by:
listBySubtype
in interfaceJmmDNS
- Parameters:
type
- Service type name, such as_http._tcp.local.
.- Returns:
- A dictionary of service info by subtypes.
- See Also:
JmDNS.listBySubtype(java.lang.String)
-
listBySubtype
public Map<String,ServiceInfo[]> listBySubtype(String type, long timeout)
Description copied from interface:JmmDNS
Returns a list of service infos of the specified type sorted by subtype. Any service that do not register a subtype is listed in the empty subtype section.- Specified by:
listBySubtype
in interfaceJmmDNS
- Parameters:
type
- Service type name, such as_http._tcp.local.
.timeout
- timeout in milliseconds. Typical timeout should be 6s.- Returns:
- A dictionary of service info by subtypes.
- See Also:
JmDNS.listBySubtype(java.lang.String, long)
-
addNetworkTopologyListener
public void addNetworkTopologyListener(NetworkTopologyListener listener)
Description copied from interface:JmmDNS
Listen to network changes.- Specified by:
addNetworkTopologyListener
in interfaceJmmDNS
- Parameters:
listener
- listener for network changes
-
removeNetworkTopologyListener
public void removeNetworkTopologyListener(NetworkTopologyListener listener)
Description copied from interface:JmmDNS
Remove listener for network changes.- Specified by:
removeNetworkTopologyListener
in interfaceJmmDNS
- Parameters:
listener
- listener for network changes
-
networkListeners
public NetworkTopologyListener[] networkListeners()
Description copied from interface:JmmDNS
Returns list of network change listeners- Specified by:
networkListeners
in interfaceJmmDNS
- Returns:
- list of network change listeners
-
inetAddressAdded
public void inetAddressAdded(NetworkTopologyEvent event)
Description copied from interface:NetworkTopologyListener
A network address has been added.- Specified by:
inetAddressAdded
in interfaceNetworkTopologyListener
- Parameters:
event
- The NetworkTopologyEvent providing the name and fully qualified type of the service.
-
inetAddressRemoved
public void inetAddressRemoved(NetworkTopologyEvent event)
Description copied from interface:NetworkTopologyListener
A network address has been removed.- Specified by:
inetAddressRemoved
in interfaceNetworkTopologyListener
- Parameters:
event
- The NetworkTopologyEvent providing the name and fully qualified type of the service.
-
-