module ManagedClient:sig
..end
Rpc_client
clients with the ability to
reconnect in the case of errors.
Additional features:
connect
system call
said the connection is there. The initial ping fixes this problem:
The null procedure is once called after the TCP connection has
been established. Only when this works the client believes the
connection is really up. It is required that mclient_programs
is configured with at least one program, and this program must
have a procedure number 0 of type void -> void
.
In multi-threaded programs, threads must not share managed clients.
type
mclient
type
mclient_config = {
|
mclient_rcache : |
(* | The rcache | *) |
|
mclient_socket_config : |
(* | The socket configuration | *) |
|
mclient_idle_timeout : |
(* | After how many seconds unused connections are closed. A negative value means never. 0 means immediately. A positive value is a point in time in the future. | *) |
|
mclient_programs : |
(* | The programs to bind | *) |
|
mclient_msg_timeout : |
(* | After how many seconds the reply must have been arrived. A negative value means there is no timeout. 0 means immediately. A positive value is a point in time in the future. | *) |
|
mclient_msg_timeout_is_fatal : |
(* | Whether a message timeout is to be considered as fatal error (the client is shut down, and the error counter for the endpoint is increased) | *) |
|
mclient_exception_handler : |
(* | Whether to call Rpc_client.set_exception_handler | *) |
|
mclient_auth_methods : |
(* | Set these authentication methods in the client | *) |
|
mclient_initial_ping : |
(* | Whether to call procedure 0 of the first program after connection establishment (see comments above) | *) |
|
mclient_max_response_length : |
(* | The maximum response length. See
Rpc_client.set_max_response_length . | *) |
exception Service_unavailable
val create_mclient_config : ?rcache:Rpc_proxy.ReliabilityCache.rcache ->
?socket_config:Rpc_client.socket_config ->
?idle_timeout:float ->
?programs:Rpc_program.t list ->
?msg_timeout:float ->
?msg_timeout_is_fatal:bool ->
?exception_handler:(exn -> unit) ->
?auth_methods:Rpc_client.auth_method list ->
?initial_ping:bool ->
?max_response_length:int -> unit -> mclient_config
rcache
: Use the global reliability cachesocket_config
: Rpc_client.default_socket_config
programs
: The empty list. It is very advisable to fill this!msg_timeout
: (-1), i.e. nonemsg_timeout_is_fatal
: falseexception_handler
: Noneauth_methods
: empty listinitial_ping
: falsemax_response_length
: Noneval create_mclient : mclient_config ->
Rpc_client.connector ->
Unixqueue.event_system -> mclient
Internet
and Unix
connectors are supported.typestate =
[ `Connecting | `Down | `Up of Unix.sockaddr option ]
`Down
: The initial state, and also reached after a socket
error, or after one of the shutdown functions is called.
Although `Down
, there might still some cleanup to do.
When RPC functions are called, the client is automatically
revived.`Connecting
: This state is used while the initial ping is
done. It does not reflect whether the client is really
TCP-connected. Without initial ping, this state cannot occur.`Up s
: The client is (so far known) up and can be used.
s
is the socket address of the local socketval mclient_state : mclient -> state
val pending_calls : mclient -> int
val event_system : mclient -> Unixqueue.event_system
val shut_down : mclient -> unit
val sync_shutdown : mclient -> unit
val trigger_shutdown : mclient -> (unit -> unit) -> unit
Rpc_client.shut_down
, Rpc_client.sync_shutdown
, and
Rpc_client.trigger_shutdown
val record_unavailability : mclient -> unit
rcache_threshold
so that the server endpoint
is disabled for some time. However, this only affects new
connections, not existing ones.
For a stricter interpretation of errors see
enforce_unavailability
.
The error counter is increased anyway when a socket error
happens, or an RPC call times out and msg_timeout_is_fatal
is set. This function can be used to also interpret other
misbehaviors as fatal errors.
val enforce_unavailability : mclient -> unit
Service_unavailable
exception, and that the client is shut down.
The background is this: When the reliability cache discovers an
unavailable port or host, only the new call is stopped with this
exception, but older calls remain unaffected. This function
can be used to change the policy, and to stop even pending calls.
The difference to trigger_shutdown
is that the pending RPC
calls get the exception Service_unavailable
instead of
Rpc_client.Message_lost
, and that it is enforced that the
shutdown is recorded as fatal error in the reliability cache.
val set_batch_call : mclient -> unit
Rpc_client.set_batch_call
val compare : mclient -> mclient -> int
ManagedClient
can be used with Set.Make
and Map.Make
include Rpc_client.USE_CLIENT
USE_CLIENT
interface for calling procedures