Class ResolverReader

java.lang.Object
io.deephaven.enterprise.resolver.ResolverReader

public class ResolverReader extends Object
Resolve a dh-resolver service path
  • Constructor Details

    • ResolverReader

      public ResolverReader()
  • Method Details

    • getServers

      public static HostPort[] getServers(String logPfx, EtcdResolverContext ctx, String servicePath)
      Resolve a service path to an array of HostPort objects.

      If at the time of the call there are no servers registered, this call will block and will wait for at least one server to be registered before returning. The caller can use the fetch timeout parameter in the ctx argument to limit this wait.

      Parameters:
      logPfx - a prefix for logging
      ctx - a ResolverContext object for this fetch. Note that if ctx.fetchTimeoutMillis == 0, this call will block waiting on new data.
      servicePath - the service path to resolve
      Returns:
      An array of HostPort objects or null if a timeout was provided and it expired before any servers registered
      Throws:
      ResolverException - if running into an error while fetching
    • watchServers

      public static SafeCloseable watchServers(@NotNull @NotNull String logPfx, @NotNull @NotNull EtcdResolverContext ctx, @NotNull @NotNull String servicePath, @NotNull @NotNull ResolverReader.HostPortListener listener)
      Register a listener for updates to the list of registered servers for a service path. A first GET call is made to etcd synchronously to this call, to get the initial list of servers, which is delivered as an initial update before this call returns. An etcd watcher is registered to deliver subsequent updates after return.

      Note if the etcd watcher completes with or without error (e.g. by etcd leader failover), the watcher is automatically restarted.

      Update from the etcd watcher are delivered to the listener asynchronously after this call returns. When no more updates are required, the caller can invoke close() on the returned object.

      Parameters:
      logPfx - a prefix for logging
      ctx - a ResolverContext object with the configuration to use for our etcd calls
      servicePath - the service path to resolve
      listener - a listener object that will get called on time initially with the current list of servers, and subsequently one time every time there is change in the list, with the contents of the new list. Note if there are servers already registered by the time of this call, the first update will be dispatched immediately and the listener's update method will be called from inside this call, before it returns.
      Returns:
      An object that can be used to close the listener subscription; after close is called on this object no further updates will occur to the listener.
    • fetchServiceConfigJson

      public static String fetchServiceConfigJson(@NotNull @NotNull String logPfx, @NotNull @NotNull EtcdResolverContext ctx, @NotNull @NotNull String servicePath, long remainingMillis) throws TimeoutException, ExecutionException, InterruptedException
      Fetch the service config json file associated with the service path.
      Parameters:
      logPfx - a prefix for logging
      ctx - a ResolverContext object with the configuration to use for our etcd calls
      servicePath - the service path to resolve
      remainingMillis - milliseconds to time out this call
      Returns:
      A string with the JSON contents for the service config associated with the service path provided
      Throws:
      TimeoutException - if this call times out
      ExecutionException - if there is an error executing the request
      InterruptedException - if the call is interrupted