Package org.ka2ddo.yaac.util
Class ServiceDiscovery
java.lang.Object
org.ka2ddo.yaac.util.ServiceDiscovery
- All Implemented Interfaces:
Closeable
,AutoCloseable
This class handles requests for Service Discovery lookups via RFC 6763, using any of several
means:
- if on a system with an avahi daemon, use the daemon as a proxy for the request.
- if avahi can't be found, try to open a dnsjava Resolver socket on the Multicast DNS (RFC 6762) port and do the query directly.
- fail if neither scheme can be used.
- Author:
- Andrew Pavlin, KA2DDO
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Protocol being reported for a particular service.static class
Structure containing one (of possibly several) successful answers for looking up a service by Service Discovery.static interface
Interface for incrementally receiving the results of a service lookup request.static interface
Interface for receiving possibly asynchronous complete answer for a service lookup request. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
browse
(String serviceType, ServiceDiscovery.SDCallback callback) Request a service lookup for the desired service category.static ServiceDiscovery.SDAnswer[]
browseService
(String service) Do a Service Discovery browse and synchronously report the results.static void
browseService
(String service, ServiceDiscovery.SDListener listener) Do a Service Discovery browse and potentially asynchronously report the results.abstract void
close()
Close down an open ServiceDiscovery handler and release any resources it is holding.static ServiceDiscovery
Get an instance of a ServiceDiscovery client that will work on the local system, for possible multiple lookups.abstract void
lookup
(String serviceType, ServiceDiscovery.SDCallback callback) Request a service lookup for the desired single service instance.static ServiceDiscovery.SDAnswer[]
lookupService
(String service) Do a Service Discovery lookup and synchronously report the results.static void
lookupService
(String service, ServiceDiscovery.SDListener listener) Do a Service Discovery lookup and potentially asynchronously report the results.
-
Method Details
-
browse
Request a service lookup for the desired service category.- Parameters:
serviceType
- String name of service, such as "_http._tcp"callback
- SDCallback to receive the information as it is received
-
lookup
Request a service lookup for the desired single service instance.- Parameters:
serviceType
- String name of service instance, such as "fred._http._tcp"callback
- SDCallback to receive the information as it is received
-
close
Close down an open ServiceDiscovery handler and release any resources it is holding.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if close failed for some reason
-
browseService
Do a Service Discovery browse and potentially asynchronously report the results. This method may or may not return before one of the methods on SDListener is called to report the results.- Parameters:
service
- String name of service to look up, such as "_http._tcp"listener
- SDListener that will receive the results
-
browseService
Do a Service Discovery browse and synchronously report the results.- Parameters:
service
- String name of service to look up, such as "_http._tcp"- Returns:
- array of SDAnswer structures with the found service instances, or null if the browse failed with some sort of error
-
lookupService
Do a Service Discovery lookup and potentially asynchronously report the results. This method may or may not return before one of the methods on SDListener is called to report the results.- Parameters:
service
- String name of service to look up, such as "_http._tcp"listener
- SDListener that will receive the results
-
lookupService
Do a Service Discovery lookup and synchronously report the results.- Parameters:
service
- String name of service to look up, such as "_http._tcp"- Returns:
- array of SDAnswer structures with the found service instances, or null if the lookup failed with some sort of error
-
getSDClient
Get an instance of a ServiceDiscovery client that will work on the local system, for possible multiple lookups.- Returns:
- instance of ServiceDiscovery that can make queries on the local operating system
- Throws:
UnknownServiceException
- if there is no known way to make ServiceDiscovery queries from Java code on this system
-