-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudi.mli
224 lines (173 loc) · 7.57 KB
/
cloudi.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
(*-*-Mode:ocaml;coding:utf-8;tab-width:2;c-basic-offset:2;indent-tabs-mode:()-*-
ex: set ft=ocaml fenc=utf-8 sts=2 ts=2 sw=2 et nomod: *)
(*
MIT License
Copyright (c) 2017-2023 Michael Truog <mjtruog at protonmail dot com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*)
(** OCaml {{:https://cloudi.org/api.html#1_Intro}CloudI API}.
Example usage is available in the
{{:https://cloudi.org/tutorials.html#cloudi_examples}integration tests}.
*)
(** provided when handling a service request *)
type request_type =
ASYNC
| SYNC
(** the Erlang pid that is the source of the service request *)
type source = Erlang.Pid.t
(** service request callback function return type *)
type response =
Response of string
| ResponseInfo of string * string
| Forward of string * string * string
| Forward_ of string * string * string * int * int
| Null
| NullError of string
(** an instance of the CloudI API *)
module Instance :
sig
type 's t
end
(** a function to handle a service request *)
type 's callback =
request_type ->
string -> string ->
string -> string ->
int -> int -> string -> source ->
's -> 's Instance.t ->
response
(** a null trans_id is used to check for a timeout or
to get the oldest response with recv_async *)
val trans_id_null : string
val invalid_input_error : string
val message_decoding_error : string
val terminate_error : string
exception ReturnSync
exception ReturnAsync
exception ForwardSync
exception ForwardAsync
exception Terminate
exception FatalError
(** creates an instance of the CloudI API *)
val api :
?terminate_return_value:bool ->
int -> 's -> ('s Instance.t, string) result
(** returns the thread count from the service configuration *)
val thread_count : unit -> (int, string) result
(** subscribes to a service name pattern with a callback *)
val subscribe : 's Instance.t -> string -> 's callback -> (unit, string) result
(** returns the number of subscriptions for a single service name pattern *)
val subscribe_count : 's Instance.t -> string -> (int, string) result
(** unsubscribes from a service name pattern once *)
val unsubscribe : 's Instance.t -> string -> (unit, string) result
(** sends an asynchronous service request *)
val send_async :
?timeout:int -> ?request_info:string -> ?priority:int ->
's Instance.t -> string -> string -> (string, string) result
(** sends a synchronous service request *)
val send_sync :
?timeout:int -> ?request_info:string -> ?priority:int ->
's Instance.t -> string -> string -> (string * string * string, string) result
(** sends asynchronous service requests to all subscribers
of the matching service name pattern *)
val mcast_async :
?timeout:int -> ?request_info:string -> ?priority:int ->
's Instance.t -> string -> string -> (string array, string) result
(** forwards an asynchronous service request to a different service name *)
val forward_async :
's Instance.t ->
string -> string -> string ->
int -> int -> string -> source -> (unit, string) result
(** forwards a synchronous service request to a different service name *)
val forward_sync :
's Instance.t ->
string -> string -> string ->
int -> int -> string -> source -> (unit, string) result
(** forwards a service request to a different service name *)
val forward_ :
's Instance.t -> request_type ->
string -> string -> string ->
int -> int -> string -> source -> (unit, string) result
(** provides a response to an asynchronous service request *)
val return_async :
's Instance.t ->
string -> string -> string -> string ->
int -> string -> source -> (unit, string) result
(** provides a response to a synchronous service request *)
val return_sync :
's Instance.t ->
string -> string -> string -> string ->
int -> string -> source -> (unit, string) result
(** provides a response to a service request *)
val return_ :
's Instance.t -> request_type ->
string -> string -> string -> string ->
int -> string -> source -> (unit, string) result
(** blocks to receive an asynchronous service request response *)
val recv_async :
?timeout:int -> ?trans_id:string -> ?consume:bool ->
's Instance.t -> (string * string * string, string) result
(** returns the 0-based index of this process in the service instance *)
val process_index : 's Instance.t -> int
(** returns the 0-based index of this process in the service instance *)
val process_index_ : unit -> (int, string) result
(** returns the current process count based on the service configuration *)
val process_count : 's Instance.t -> int
(** returns the count_process_dynamic maximum count
based on the service configuration *)
val process_count_max : 's Instance.t -> int
(** returns the count_process_dynamic maximum count
based on the service configuration *)
val process_count_max_ : unit -> (int, string) result
(** returns the count_process_dynamic minimum count
based on the service configuration *)
val process_count_min : 's Instance.t -> int
(** returns the count_process_dynamic minimum count
based on the service configuration *)
val process_count_min_ : unit -> (int, string) result
(** returns the service name pattern prefix from the service configuration *)
val prefix : 's Instance.t -> string
(** returns the service initialization timeout
from the service configuration *)
val timeout_initialize : 's Instance.t -> int
(** returns the service initialization timeout
from the service configuration *)
val timeout_initialize_ : unit -> (int, string) result
(** returns the default asynchronous service request send timeout
from the service configuration *)
val timeout_async : 's Instance.t -> int
(** returns the default synchronous service request send timeout
from the service configuration *)
val timeout_sync : 's Instance.t -> int
(** returns the service termination timeout
based on the service configuration *)
val timeout_terminate : 's Instance.t -> int
(** returns the service termination timeout
based on the service configuration *)
val timeout_terminate_ : unit -> (int, string) result
(** returns the default service request send priority
from the service configuration *)
val priority_default : 's Instance.t -> int
(** blocks to process incoming CloudI service requests *)
val poll : 's Instance.t -> int -> (bool, string) result
(** shutdown the service successfully *)
val shutdown : ?reason:string -> 's Instance.t -> (unit, string) result
(** decode service request info key/value data *)
val info_key_value_parse : string -> (string, string list) Hashtbl.t
(** encode service response info key/value data *)
val info_key_value_new :
?response:bool -> (string, string list) Hashtbl.t -> string