Module Distributed_uwt.Make
Functor to create a module of type Distributed.Process given a message module M of type Distributed.Message_type and a custom logger module L of type CustomerLogger.
Parameters
Signature
exceptionInit_more_than_onceexceptionInvalidNode of Distributed.Node_id.texceptionLocal_only_mode
type message_type= M.tThe abstract type representing the messages that will be sent between processes.
type 'a matcher_listThe abstract type representing a non-empty list of matchers to be used with
receivefunction.
type monitor_refThe abstract type representing a monitor_ref that is returned when a processes is monitored and can be used to unmonitor it.
type monitor_reason=|Normal of Distributed.Process_id.tProcess terminated normally.
|Exception of Distributed.Process_id.t * exnProcess terminated with exception.
|UnkownNodeId of Distributed.Process_id.t * Distributed.Node_id.tAn operation failed because the remote node id is unknown.
|NoProcess of Distributed.Process_id.tAttempted to monitor a process that does not exist.
Reason for process termination.
module Remote_config : sig ... endThe configuration of a node to be run as a remote node i.e., one that can both send an receive messages with other nodes.
module Local_config : sig ... endThe configuration of a node to be run as a local node i.e., one that can not send or receive messages with other nodes.
type node_config=|Local of Local_config.t|Remote of Remote_config.tThe configuration of a node. Can be one of
node_config.Localornode_config.Remote.
val return : 'a -> 'a treturn vcreates a computation returningv.
val (>>=) : 'a t -> ('a -> 'b t) -> 'b tc >>= fis a computation which first waits for the computationcto terminate and then, if the computation succeeds, behaves as the application of functionfto the return value ofc. If the computationcfails,c >>= falso fails, with the same exception.
val fail : exn -> 'a tfail eis a process that fails with the exceptione.
val catch : (unit -> 'a t) -> (exn -> 'a t) -> 'a tcatch p fis a process that behaves as the processp ()if this process succeeds. If the processp ()fails with some exception,catch p fbehaves as the application offto this exception.
val spawn : ?monitor:bool -> Distributed.Node_id.t -> (unit -> unit t) -> (Distributed.Process_id.t * monitor_ref option) tspawn monitor name node_id processwill spawnprocessonnode_idreturning theDistributed.Process_id.tassociated with the newly spawned process. Ifmonitoris true (default value is false) then the spawned process will also be monitored and the associatedmonitor_refwill be returned.If
node_idis an unknown node thenInvalidNodeexception is raised.
val case : (message_type -> (unit -> 'a t) option) -> 'a matcher_listcase match_fnwill create amatcher_listwhich will usematch_fnto match on potential messages.match_fnshould returnNoneto indicate no match orSome handlerwherehandleris the function that should be called to handle the matching message.
val termination_case : (monitor_reason -> 'a t) -> 'a matcher_listtermination_case handlerwill create amatcher_listwhich can use used to match againsttermination_reasonfor a process that is being monitored. If this process is monitoring another process then providing this matcher in the list of matchers toreceivewill allow this process to act on the termination of the monitored process.NOTE : when a remote process (i.e., one running on another node) raises an exception you will not be able to pattern match on the exception . This is a limitation of the Marshal OCaml module : " Values of extensible variant types, for example exceptions (of extensible type exn), returned by the unmarshaller should not be pattern-matched over through
match ... withortry ... with, because unmarshalling does not preserve the information required for matching their constructors. Structural equalities with other extensible variant values does not work either. Most other uses such as Printexc.to_string, will still work as expected. "See http://caml.inria.fr/pub/docs/manual-ocaml/libref/Marshal.html.
val (|.) : 'a matcher_list -> 'a matcher_list -> 'a matcher_lista_matcher |. b_matcheris amatcher_listconsiting of the matchers ina_matcherfollowed by the matchers inb_matcher.
val receive : ?timeout_duration:float -> 'a matcher_list -> 'a option treceive timeout matcherswill wait for a message to be sent to this process which matches one of matchers provided inmatchers. The first matching matcher inmatcherswill used process the matching message returningSome resultwhereresultis result of the matcher processing the matched message. All the other non-matching messages are left in the same order they came in.If a time out is provided and no matching messages has arrived in the time out period then None will be returned.
If the
matchersis empty then anEmpty_matchersexception is raised.
val receive_loop : ?timeout_duration:float -> bool matcher_list -> unit treceive_loop timeout matchersis a convenience function which will loop until a matcher inmatchersreturns false.
val send : Distributed.Process_id.t -> message_type -> unit tsend process_id msgwill send, asynchronously, messagemsgto the process with idprocess_id(possibly running on a remote node).If
process_idis resides on an unknown node thenInvalidNodeexception is raised.If
process_idis an unknown process but the node on which it resides is known then send will still succeed (i.e., will not raise any exceptions).
val (>!) : Distributed.Process_id.t -> message_type -> unit tpid >! msgis equivalent tosend pid msg.>!is an infix alias forsend.
val broadcast : Distributed.Node_id.t -> message_type -> unit tbroadcast node_id msgwill send, asynchronously, messagemsgto all the processes onnode_id.If
node_idis an unknown node thenInvalidNodeexception is raised.
val monitor : Distributed.Process_id.t -> monitor_ref tmonitor pidwill allows the calling process to monitorpid. Whenpidterminates (normally or abnormally) this monitoring process will receive atermination_reasonmessage, which can be matched inreceiveusingtermination_matcher. A single process can be monitored my multiple processes.If
process_idis resides on an unknown node thenInvalidNodeexception is raised.
val unmonitor : monitor_ref -> unit tunmonitor mrefwill cause this process to stop monitoring the process which is referenced bymref. If the current process is not monitoring the process referenced bymrefthenunmonitoris a no-op.If process being unmonitored as indicated by
monitor_refis resides on an unknown node thenInvalidNodeexception is raised.
val get_self_pid : Distributed.Process_id.t tget_self_pid processwill return the process id associated withprocess.
val get_self_node : Distributed.Node_id.t tget_self_node processwill return the node id associated withprocess.
val get_remote_node : string -> Distributed.Node_id.t option tget_remote_node node_namewill return the node id associated withname, if there is no record of a node withnameat this time thenNoneis returned.
val get_remote_nodes : Distributed.Node_id.t list tThe list of all nodes currently active and inactive.
val add_remote_node : string -> int -> string -> Distributed.Node_id.t tadd_remote_node ip port namewill connect to the remote node atip:portwith namenameand add it to the current nodes list of connected remote nodes. The newly added node id is returned as the result. Adding a remote node that already exists is a no-op.If the node is operating in local only mode then
Local_only_modeis raised.
val remove_remote_node : Distributed.Node_id.t -> unit tremove_remote_node node_idwill removenode_idfrom the list of connected remote nodes.If the node is operating in local only mode then
Local_only_modeis raised.
val run_node : ?process:(unit -> unit t) -> node_config -> unit iorun_node process node_monitor_fn node_configperforms the necessary bootstrapping to start this node according tonode_config. If provided, runs the initialprocessreturning the resultingio.If it's called more than once then an exception of
Init_more_than_onceis raised.