1
(* $Id: lever.ml 1415 2010-02-15 23:58:25Z gerd $ *)
5
(* --- things we need for creating the lever --- *)
8
type s = string (* argument type. Here, the message string *)
9
type r = bool (* result type. Here, whether the lever was successful *)
12
module L = Netplex_cenv.Make_lever(T)
14
module LV = Netplex_cenv.Make_var_type(L)
20
inherit Netplex_kit.empty_processor_hooks ()
21
method post_start_hook cont =
22
(* Just print the message 10 times *)
24
Netlog.logf `Info "Helper1: %s" s;
27
(* There is no real way for disabling a helper again. [shutdown]
28
will shut the process down (and it is not restarting). The
29
service definition will remain active, however.
38
let proc_operation s =
39
(* Start the helper thread using a lever *)
40
let lever = LV.get "sample_lever" in
41
let success = lever s in
44
"Could activate lever"
46
"Error activating lever" in
51
let setup_worker srv _ =
52
Operation_srv.P.V.bind
53
~proc_null:(fun () -> ())
60
inherit Netplex_kit.empty_processor_hooks()
62
val mutable helper1_lever = (fun _ -> assert false)
64
method post_add_hook socksrv ctrl =
65
(* This is run in controller context, right after program startup.
66
Register now the lever function, which starts a helper service.
72
Netplex_kit.add_helper_service
73
ctrl "helper1" (helper_hooks s);
76
Netlog.logf `Err "Cannot start helper service: %s"
77
(Netexn.to_string error);
78
false (* not successful *)
80
(* Remember the created lever until the child forks *)
81
helper1_lever <- lever
83
method post_start_hook cont =
84
(* Make the lever generally available in the child *)
85
LV.set "sample_lever" helper1_lever
89
let worker_factory() =
90
Rpc_netplex.rpc_factory
91
~configure:(fun _ _ -> ())
94
~hooks:(fun _ -> worker_hooks())
101
let (opt_list, cmdline_cfg) = Netplex_main.args() in
103
let use_mt = ref false in
106
[ "-mt", Arg.Set use_mt,
107
" Use multi-threading instead of multi-processing";
109
"-debug", Arg.String (fun s -> Netlog.Debug.enable_module s),
110
"<module> Enable debug messages for <module>";
112
"-debug-all", Arg.Unit (fun () -> Netlog.Debug.enable_all()),
113
" Enable all debug messages";
115
"-debug-list", Arg.Unit (fun () ->
116
List.iter print_endline (Netlog.Debug.names());
118
" Show possible modules for -debug, then exit";
123
(fun s -> raise (Arg.Bad ("Don't know what to do with: " ^ s)))
124
(sprintf "usage: %s [options]" (Filename.basename Sys.argv.(0)));
128
Netplex_mt.mt() (* multi-threading *)
130
Netplex_mp.mp() in (* multi-processing *)
134
Netplex_log.logger_factories (* allow all built-in logging styles *)
135
Netplex_workload.workload_manager_factories (* ... all ways of workload management *)
141
Netsys_signal.init();