Up

module Persistent_rpc_client

: sig

An actively maintained rpc connection that eagerly and repeatedly attempts to reconnect whenever the connection is lost, until a new connection is established.

#
type t
#
module Event : sig
#
type t =
# | Attempting_to_connect
# | Obtained_address of Core.Std.Host_and_port.t
# | Failed_to_connect of Core.Std.Error.t
# | Connected
# | Disconnected
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
val create : server_name:string -> ?log:Log.t -> ?on_event:(Event.t -> unit) -> ?implementations:_ Rpc.Connection.Client_implementations.t -> ?max_message_size:int -> ?handshake_timeout:Core.Std.Time.Span.t -> (unit -> Core.Std.Host_and_port.t Core.Std.Or_error.t Import.Deferred.t) -> t

create ~server_name ~log get_address returns a persistent rpc connection to a server whose host and port are obtained via get_address every time we try to connect. For example, get_address might look up a server's host and port in catalog at a particular path to which multiple redundant copies of a service are publishing their location. If one copy dies, we get the address of the another one when looking up the address afterwards.

All connection events (see the type above) are passed to the on_event callback, if given. If a ~log is supplied then these events will be written there as well, with a "persistent-connection-to" tag value of server_name, which should be the name of the server we are connecting to.

`Failed_to_connect error and `Obtained_address addr events are only reported if they are distinct from the most recent event of the same type that has taken place since the most recent `Attempting_to_connect event.

The implementations, max_message_size, and handshake_timeout arguments are just as for Rpc.Connection.create.

#
val connected : t -> Rpc.Connection.t Import.Deferred.t

connected returns the first available rpc connection from the time it is called. When currently connected, the returned deferred is already determined. If closed has been called, then the returned deferred is never determined.

#
val current_connection : t -> Rpc.Connection.t option

The current rpc connection, if any.

#
val close : t -> unit Import.Deferred.t

close t closes the current connection and stops it from trying to reconnect. After the deferred it returns becomes determined, the last connection has been closed and no others will be attempted.

close_finished t becomes determined at the same time as the result of the first call to close. close_finished differs from close in that it does not have the side effect of initiating a close.

#
val close_finished : t -> unit Import.Deferred.t
end