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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Checks the network state.
If the network change, this class will reconfigure the list of DNS do adapt to the new configuration.Nested classes/interfaces inherited from interface javax.jmdns.JmmDNS
JmmDNS.Factory
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBoolean
private final AtomicBoolean
private final ExecutorService
private final ConcurrentMap
<InetAddress, JmDNS> Every JmDNS created.private final ExecutorService
private final Set
<NetworkTopologyListener> private final ConcurrentMap
<String, List<ServiceListener>> Holds instances of ServiceListener's.private final ConcurrentMap
<String, ServiceInfo> This enable the service info text update.List of registered servicesprivate final Timer
private final Set
<ServiceTypeListener> Holds instances of ServiceTypeListener's.private static org.slf4j.Logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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()
protected JmDNS
createJmDnsInstance
(InetAddress address) JmDNS[]
getDNS()
Return a list of all the registered JmDNS instancesString[]
Return the list HostName associated with this JmmDNS instance.Return the list of addresses of the interface to which this instance of JmmDNS is bound.Deprecated.String[]
getNames()
Return the names of the JmDNS instances.getServiceInfos
(String type, String name) Get service information.getServiceInfos
(String type, String name, boolean persistent) Get service information.getServiceInfos
(String type, String name, boolean persistent, long timeout) Get service information.getServiceInfos
(String type, String name, long timeout) Get service information.void
A network address has been added.void
A network address has been removed.Returns a list of service infos of the specified type.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.Returns list of network change listenersvoid
registerService
(ServiceInfo info) Register a service.void
registerServiceType
(String type) Register a service type.void
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
Unregister all services.void
unregisterService
(ServiceInfo info) Unregister a service.
-
Field Details
-
logger
private static org.slf4j.Logger logger -
_networkListeners
-
_knownMDNS
Every JmDNS created. -
_services
This enable the service info text update. -
_serviceTypes
List of registered services -
_serviceListeners
Holds instances of ServiceListener's. Keys are Strings holding a fully qualified service type. Values are LinkedList's of ServiceListener's. -
_typeListeners
Holds instances of ServiceTypeListener's. -
_listenerExecutor
-
_jmDNSExecutor
-
_timer
-
_isClosing
-
_closed
-
-
Constructor Details
-
JmmDNSImpl
public JmmDNSImpl()
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getNames
Description copied from interface:JmmDNS
Return the names of the JmDNS instances. -
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:
-
getInetAddresses
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:
-
getDNS
Description copied from interface:JmmDNS
Return a list of all the registered JmDNS instances -
getInterfaces
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:
-
getServiceInfos
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:
-
getServiceInfos
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:
-
getServiceInfos
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:
-
getServiceInfos
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:
-
requestServiceInfo
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:
-
requestServiceInfo
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:
-
requestServiceInfo
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:
-
requestServiceInfo
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:
-
addServiceTypeListener
Description copied from interface:JmmDNS
Listen for service types.- Specified by:
addServiceTypeListener
in interfaceJmmDNS
- Parameters:
listener
- listener for service types- Throws:
IOException
- See Also:
-
removeServiceTypeListener
Description copied from interface:JmmDNS
Remove listener for service types.- Specified by:
removeServiceTypeListener
in interfaceJmmDNS
- Parameters:
listener
- listener for service types- See Also:
-
addServiceListener
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:
-
removeServiceListener
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:
-
textValueUpdated
- Specified by:
textValueUpdated
in interfaceServiceInfoImpl.Delegate
-
registerService
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:
-
unregisterService
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:
-
unregisterAllServices
public void unregisterAllServices()Description copied from interface:JmmDNS
Unregister all services.- Specified by:
unregisterAllServices
in interfaceJmmDNS
- See Also:
-
registerServiceType
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:
-
list
Description copied from interface:JmmDNS
Returns a list of service infos of the specified type. -
list
Description copied from interface:JmmDNS
Returns a list of service infos of the specified type. -
listBySubtype
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:
-
listBySubtype
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:
-
addNetworkTopologyListener
Description copied from interface:JmmDNS
Listen to network changes.- Specified by:
addNetworkTopologyListener
in interfaceJmmDNS
- Parameters:
listener
- listener for network changes
-
removeNetworkTopologyListener
Description copied from interface:JmmDNS
Remove listener for network changes.- Specified by:
removeNetworkTopologyListener
in interfaceJmmDNS
- Parameters:
listener
- listener for network changes
-
networkListeners
Description copied from interface:JmmDNS
Returns list of network change listeners- Specified by:
networkListeners
in interfaceJmmDNS
- Returns:
- list of network change listeners
-
inetAddressAdded
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
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.
-
createJmDnsInstance
- Throws:
IOException
-