Package io.deephaven.enterprise.resolver
Class ResolverReader
java.lang.Object
io.deephaven.enterprise.resolver.ResolverReader
Resolve a dh-resolver service path
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA listener that clients can use to register for updates to the list of servers for a resolved service. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringfetchServiceConfigJson(@NotNull String logPfx, @NotNull EtcdResolverContext ctx, @NotNull String servicePath, long remainingMillis) Fetch the service config json file associated with the service path.static HostPort[]getServers(String logPfx, EtcdResolverContext ctx, String servicePath) Resolve a service path to an array ofHostPortobjects.static SafeCloseablewatchServers(@NotNull String logPfx, @NotNull EtcdResolverContext ctx, @NotNull String servicePath, @NotNull ResolverReader.HostPortListener listener) Register a listener for updates to the list of registered servers for a service path.
-
Constructor Details
-
ResolverReader
public ResolverReader()
-
-
Method Details
-
getServers
Resolve a service path to an array ofHostPortobjects.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
ctxargument to limit this wait.- Parameters:
logPfx- a prefix for loggingctx- a ResolverContext object for this fetch. Note that ifctx.fetchTimeoutMillis == 0, this call will block waiting on new data.servicePath- the service path to resolve- Returns:
- An array of
HostPortobjects 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 loggingctx- a ResolverContext object with the configuration to use for our etcd callsservicePath- the service path to resolvelistener- 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 loggingctx- a ResolverContext object with the configuration to use for our etcd callsservicePath- the service path to resolveremainingMillis- 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 outExecutionException- if there is an error executing the requestInterruptedException- if the call is interrupted
-