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 classChecks 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 AtomicBooleanprivate final AtomicBooleanprivate final ExecutorServiceprivate final ConcurrentMap<InetAddress, JmDNS> Every JmDNS created.private final ExecutorServiceprivate 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 Timerprivate final Set<ServiceTypeListener> Holds instances of ServiceTypeListener's.private static org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidListen to network changes.voidaddServiceListener(String type, ServiceListener listener) Listen for services of a given type.voidaddServiceTypeListener(ServiceTypeListener listener) Listen for service types.voidclose()protected JmDNScreateJmDnsInstance(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.voidA network address has been added.voidA 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 listenersvoidregisterService(ServiceInfo info) Register a service.voidregisterServiceType(String type) Register a service type.voidRemove listener for network changes.voidremoveServiceListener(String type, ServiceListener listener) Remove listener for services of a given type.voidremoveServiceTypeListener(ServiceTypeListener listener) Remove listener for service types.voidrequestServiceInfo(String type, String name) Request service information.voidrequestServiceInfo(String type, String name, boolean persistent) Request service information.voidrequestServiceInfo(String type, String name, boolean persistent, long timeout) Request service information.voidrequestServiceInfo(String type, String name, long timeout) Request service information.voidtextValueUpdated(ServiceInfo target, byte[] value) voidUnregister all services.voidunregisterService(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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getNames
Description copied from interface:JmmDNSReturn the names of the JmDNS instances. -
getHostNames
Description copied from interface:JmmDNSReturn the list HostName associated with this JmmDNS instance.- Specified by:
getHostNamesin interfaceJmmDNS- Returns:
- list of host names
- See Also:
-
getInetAddresses
Description copied from interface:JmmDNSReturn the list of addresses of the interface to which this instance of JmmDNS is bound.- Specified by:
getInetAddressesin interfaceJmmDNS- Returns:
- list of Internet Address
- Throws:
IOException- See Also:
-
getDNS
Description copied from interface:JmmDNSReturn a list of all the registered JmDNS instances -
getInterfaces
Deprecated.Description copied from interface:JmmDNSReturn the list of addresses of the interface to which this instance of JmmDNS is bound.- Specified by:
getInterfacesin interfaceJmmDNS- Returns:
- list of Internet Address
- Throws:
IOException- See Also:
-
getServiceInfos
Description copied from interface:JmmDNSGet 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:
getServiceInfosin 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:JmmDNSGet 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:
getServiceInfosin 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:JmmDNSGet 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:
getServiceInfosin interfaceJmmDNS- Parameters:
type- full qualified service type, such as_http._tcp.local..name- unqualified service name, such asfoobar.persistent- iftrueServiceListener.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:JmmDNSGet 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:
getServiceInfosin interfaceJmmDNS- Parameters:
type- full qualified service type, such as_http._tcp.local..name- unqualified service name, such asfoobar.persistent- iftrueServiceListener.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:JmmDNSRequest service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfoin 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:JmmDNSRequest service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfoin interfaceJmmDNS- Parameters:
type- full qualified service type, such as_http._tcp.local..name- unqualified service name, such asfoobar.persistent- iftrueServiceListener.resolveService will be called whenever new new information is received.- See Also:
-
requestServiceInfo
Description copied from interface:JmmDNSRequest service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfoin 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:JmmDNSRequest service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.- Specified by:
requestServiceInfoin interfaceJmmDNS- Parameters:
type- full qualified service type, such as_http._tcp.local..name- unqualified service name, such asfoobar.persistent- iftrueServiceListener.resolveService will be called whenever new new information is received.timeout- timeout in milliseconds- See Also:
-
addServiceTypeListener
Description copied from interface:JmmDNSListen for service types.- Specified by:
addServiceTypeListenerin interfaceJmmDNS- Parameters:
listener- listener for service types- Throws:
IOException- See Also:
-
removeServiceTypeListener
Description copied from interface:JmmDNSRemove listener for service types.- Specified by:
removeServiceTypeListenerin interfaceJmmDNS- Parameters:
listener- listener for service types- See Also:
-
addServiceListener
Description copied from interface:JmmDNSListen for services of a given type. The type has to be a fully qualified type name such as_http._tcp.local..- Specified by:
addServiceListenerin interfaceJmmDNS- Parameters:
type- full qualified service type, such as_http._tcp.local..listener- listener for service updates- See Also:
-
removeServiceListener
Description copied from interface:JmmDNSRemove listener for services of a given type.- Specified by:
removeServiceListenerin interfaceJmmDNS- Parameters:
type- full qualified service type, such as_http._tcp.local..listener- listener for service updates- See Also:
-
textValueUpdated
- Specified by:
textValueUpdatedin interfaceServiceInfoImpl.Delegate
-
registerService
Description copied from interface:JmmDNSRegister 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:
registerServicein interfaceJmmDNS- Parameters:
info- service info to register- Throws:
IOException- See Also:
-
unregisterService
Description copied from interface:JmmDNSUnregister a service. The service should have been registered.- Specified by:
unregisterServicein interfaceJmmDNS- Parameters:
info- service info to remove- See Also:
-
unregisterAllServices
public void unregisterAllServices()Description copied from interface:JmmDNSUnregister all services.- Specified by:
unregisterAllServicesin interfaceJmmDNS- See Also:
-
registerServiceType
Description copied from interface:JmmDNSRegister 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:
registerServiceTypein interfaceJmmDNS- Parameters:
type- full qualified service type, such as_http._tcp.local..- See Also:
-
list
Description copied from interface:JmmDNSReturns a list of service infos of the specified type. -
list
Description copied from interface:JmmDNSReturns a list of service infos of the specified type. -
listBySubtype
Description copied from interface:JmmDNSReturns 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:
listBySubtypein 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:JmmDNSReturns 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:
listBySubtypein 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:JmmDNSListen to network changes.- Specified by:
addNetworkTopologyListenerin interfaceJmmDNS- Parameters:
listener- listener for network changes
-
removeNetworkTopologyListener
Description copied from interface:JmmDNSRemove listener for network changes.- Specified by:
removeNetworkTopologyListenerin interfaceJmmDNS- Parameters:
listener- listener for network changes
-
networkListeners
Description copied from interface:JmmDNSReturns list of network change listeners- Specified by:
networkListenersin interfaceJmmDNS- Returns:
- list of network change listeners
-
inetAddressAdded
Description copied from interface:NetworkTopologyListenerA network address has been added.- Specified by:
inetAddressAddedin interfaceNetworkTopologyListener- Parameters:
event- The NetworkTopologyEvent providing the name and fully qualified type of the service.
-
inetAddressRemoved
Description copied from interface:NetworkTopologyListenerA network address has been removed.- Specified by:
inetAddressRemovedin interfaceNetworkTopologyListener- Parameters:
event- The NetworkTopologyEvent providing the name and fully qualified type of the service.
-
createJmDnsInstance
- Throws:
IOException
-