Class ServiceDiscovery

java.lang.Object
org.ka2ddo.yaac.util.ServiceDiscovery
All Implemented Interfaces:
Closeable, AutoCloseable

public abstract class ServiceDiscovery extends Object implements Closeable
This class handles requests for Service Discovery lookups via RFC 6763, using any of several means:
  1. if on a system with an avahi daemon, use the daemon as a proxy for the request.
  2. 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.
  3. fail if neither scheme can be used.
Author:
Andrew Pavlin, KA2DDO
  • Method Details

    • browse

      public abstract void browse(String serviceType, ServiceDiscovery.SDCallback callback)
      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

      public abstract void lookup(String serviceType, ServiceDiscovery.SDCallback callback)
      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

      public abstract void close() throws IOException
      Close down an open ServiceDiscovery handler and release any resources it is holding.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if close failed for some reason
    • browseService

      public static void browseService(String service, ServiceDiscovery.SDListener listener)
      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

      public static ServiceDiscovery.SDAnswer[] browseService(String service)
      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

      public static void lookupService(String service, ServiceDiscovery.SDListener listener)
      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

      public static ServiceDiscovery.SDAnswer[] lookupService(String service)
      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

      public static ServiceDiscovery getSDClient() throws UnknownServiceException
      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