module Netplex_cenv:Container environmentsig
..end
Some helper functions to explore the environment from a container.
Most of the following functions must be called from a container context,
i.e. from a process or thread that acts as container, otherwise
the exception Not_in_container_thread
is raised. There are also some
functions that can be called from controller context for convenience.
exception Not_in_container_thread
val log : Netplex_types.level -> string -> unit
val logf : Netplex_types.level -> ('a, unit, string, unit) Pervasives.format4 -> 'a
printf
val report_connection_string : Unix.file_descr -> string -> string
netplex.connections
admin message.
The string is the detail to report.type
timer
val create_timer : (timer -> bool) -> float -> timer
create_timer f tmo
: Creates a timer with timeout value tmo
:
In tmo
seconds f
is called, and if this function returns true
,
the timer remains active, and another round of timing is arranged.
If the functions returns false
or raises an exception, the timer
is stopped.
Timers are also stopped on container shutdown.
Timers are attached to the container event system, and run only
if this event system runs.
val cancel_timer : timer -> unit
val cancel_all_timers : unit -> unit
val timer_id : timer -> int
var
and set_var
methods of the container class.
The following functions are often more convenient, however.
These functions can only be invoked from container contexts.
More documentation: Container variables
exception Container_variable_not_found of string
exception Container_variable_type_mismatch of string
val int_var : string -> int
val string_var : string -> string
val float_var : string -> float
val bool_var : string -> bool
Container_variable_not_found
or Container_variable_type_mismatch
val set_int_var : string -> int -> unit
val set_string_var : string -> string -> unit
val set_float_var : string -> float -> unit
val set_bool_var : string -> bool -> unit
val make_var_type : ('a -> Netplex_types.encap) ->
(Netplex_types.encap -> 'a) -> (string -> 'a) * (string -> 'a -> unit)
foo
, do
module E = Netplex_encap.Make_encap(struct type t = foo end)
let (get, set) =
make_var_type E.wrap E.unwrap
Read on for using functors to create get
and set
.
module type TYPE =sig
..end
t
module type VAR_TYPE =sig
..end
t
with two functions get
and set
accessing the container variables
module Make_var_type:
get
and set
like make_var_type
.
val system_shutdown : unit -> unit
shutdown
method of the
controller)val system_restart : unit -> unit
restart
method of the
controller)send_message
.val send_message : string -> string -> string array -> unit
send_message service_pattern msg_name msg_arguments
: Sends
a message to all services and message receivers matching
service_pattern
. The pattern may include the wildcard *
.
See the Netplex_types.controller.send_message
method for
the notification guarantees.
This function can be invoked from both container and controller
contexts.
val lookup : string -> string -> string option
lookup service_name protocol_name
tries to find a Unix domain
socket for the service and returns it.
On Win32, the returned path refers to a file describing the
IPC mechanism. Use Netplex_sockserv.any_file_client_connector
to convert the path into an RPC connector.
val lookup_container_sockets : string -> string -> string array
lookup_container_sockets service_name protocol_name
: returns
the Unix Domain paths of all container sockets for this service and
protocol. These are the sockets declared with address type
"container" in the config file.
On Win32, the returned paths refer to files describing the
IPC mechanism. Use Netplex_sockserv.any_file_client_connector
to convert the paths into RPC connectors.
Container sockets are explained here:
Sending messages to individual containers
val self_cont : unit -> Netplex_types.container
Not_in_container_thread
if called from outside a
container context.val self_obj : unit ->
[ `Container of Netplex_types.container
| `Controller of Netplex_types.controller ]
Not_in_container_thread
(sic!) if called from
neither a container not a controller thread.val current_sys_id : unit -> [ `Process of int | `Thread of int ]
val admin_connector : unit -> Rpc_client.mode2
let conn = Netplex_cenv.admin_connector() in
let client = Netplex_ctrl_clnt.Admin.V2.create_client2 conn in
Netplex_ctrl_clnt.Admin.V2.system_shutdown client ();
Rpc_client.shut_down client
Note that the admin interface is going to evolve, and it is advisable to avoid admin calls whenever possible.
This function must be called from container context.
val run_in_controller_context : Netplex_types.controller -> (unit -> unit) -> unit
run_in_controller_context ctrl f
: Arranges that f()
is executed
in the context of the controller. This is only possible for
multi-threading but not for multi-processing style! For
programs using multi-processing, see Netplex_cenv.Make_lever
for a workaround.
This function can be called from any thread. The function f
is
executed by pushing it onto the event queue, and calling it when
the pushed event is reached. This is usually a safe point for
many kinds of operations, but if controller methods are invoked
the details are left unspecified.
For example, this allows it to start helper threads via
Netplex_kit.add_helper_service
at any time.
An example can be found here: Levers - calling controller functions from containers
val run_in_container_context : Netplex_types.container -> (unit -> unit) -> unit
run_in_container_context cont f
: Arranges that f()
is executed
in the context of the container cont
. This is only possible for
multi-threading but not for multi-processing style!
This function can be called from any thread. The function f
is
executed by pushing it onto the event queue, and calling it when
the pushed event is reached. This is usually a safe point for
many kinds of operations, but if container method are invoked
the details are left unspecified.
There is no guarantee that f
is called anytime soon - if the
container is busy with something else than with the event queue
the execution will be blocked until these other activities are
over.
More documentation: Levers - calling controller functions from containers
module type FUN_TYPE =sig
..end
s->t
module type LEVER =sig
..end
module Make_lever:
LEVER
module from a function type as specified in
FUN_TYPE
module Debug:sig
..end