Qore ConnectionProvider Module Reference 1.11
Loading...
Searching...
No Matches
PollingConnectionMonitor.qc.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
2// Qore PollingConnectionMonitor class definition
3
4/* PollingConnectionMonitor.qc Copyright 2016 - 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
26
28namespace ConnectionProvider {
30
32class PollingConnectionMonitor : public LoggerWrapper {
33
34public:
36 const PollEventMap = {
37 SOCK_POLLIN: "read",
38 SOCK_POLLOUT: "write",
39 SOCK_POLLIN | SOCK_POLLOUT: "read and write",
40 };
41
42protected:
44 Mutex m();
45
47 hash<string, hash<PollInfo>> cache;
48
50 int tid;
51
53 bool autostart = True;
54
57
60
62 const IO_ADD = "add";
63
65 const IO_UPDATE = "update";
66
68 const IO_REMOVE = "remove";
69
71 const IO_QUIT = "quit";
72
74 const IO_QUIT_REMOVE_ALL = "quit-remove-all";
75
77 const DefaultPingTimeout = 30s;
78
81
82public:
83
84private:
87
89 ReadOnlyFile sem_read;
90
92 hash<SocketPollInfo> sem_info;
93
95 Counter mcnt();
96
98 Queue cmdq();
99
100public:
101
103 constructor(*LoggerInterface logger) ;
104
105
108
109
112
113
116
117
119
122
123
126
127
130
131
133 bool running();
134
135
137
143 add(AbstractConnection conn, *hash<auto> other);
144
145
147
152 addOrUpdate(AbstractConnection conn, *hash<auto> other);
153
154
156
164 bool removeConnection(string name);
165
166
168
174 removeConnectionEx(string name);
175
176
177protected:
178 startIntern();
179public:
180
181
182protected:
183 int stopIntern();
184public:
185
186
187protected:
188 ioThread();
189public:
190
191
193protected:
194 handlePingSuccess(string name, date delta, *bool oldok);
195public:
196
197
199protected:
200 handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
201public:
202
203
205protected:
206 handlePingTimeout(string name, date delta);
207public:
208
209
211protected:
212 handlePingTimeoutIntern(string name, date delta);
213public:
214
215
217protected:
218 restartPing(string name, *bool force_restart);
219public:
220
221
222protected:
223 *bool processCommands();
224public:
225
226
227protected:
228 sendCmd(string cmd);
229public:
230
231};
232};
233
234// private symbols
235namespace Priv {
236hashdecl PollInfo {
237 // poll start timestamp
238 date start;
239
240 # connection
241 AbstractConnection conn;
242
243 # poll operation
244 AbstractPollOperation spop;
245
246 # other data stored alongside the connection
247 *hash<auto> other;
248}
249
250class RecursiveAutoLock {
251
252public:
253protected:
254 Mutex m;
255
256public:
257
258 constructor(Mutex m);
259
260
261 destructor();
262
263};
264};
abstract base class for connections
Definition: AbstractConnection.qc.dox.h:34
Class for monitoring connection supporting the polling API.
Definition: PollingConnectionMonitor.qc.dox.h:32
bool removeConnection(string name)
Removes the given connection.
date ping_repeat
ping repeat duration
Definition: PollingConnectionMonitor.qc.dox.h:59
handlePingTimeout(string name, date delta)
Handles a poll timeout.
handlePingSuccess(string name, date delta, *bool oldok)
Handles a successful ping.
File sem_write
File to signal the I/O thread.
Definition: PollingConnectionMonitor.qc.dox.h:86
setAutostart(bool autostart=True)
Set autostart flag.
Mutex m()
Lock for atomic actions.
Queue cmdq()
I/O thread command queue.
handlePingFailed(string name, date delta, hash< ExceptionInfo > ex)
Handles a failed ping.
restartPing(string name, *bool force_restart)
Restarts a ping operation.
handlePingTimeoutIntern(string name, date delta)
Handles a ping timeout.
removeConnectionEx(string name)
Removes the given connection.
add(AbstractConnection conn, *hash< auto > other)
Adds a connection to be monitored.
const IO_REMOVE
I/O thread command: remove.
Definition: PollingConnectionMonitor.qc.dox.h:68
int tid
I/O thread TID.
Definition: PollingConnectionMonitor.qc.dox.h:50
addOrUpdate(AbstractConnection conn, *hash< auto > other)
Adds or updates an existing connection that is already being monitored.
destructor()
Stops the monitoring thread and destroys the object.
const IO_UPDATE
I/O thread command: update.
Definition: PollingConnectionMonitor.qc.dox.h:65
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition: PollingConnectionMonitor.qc.dox.h:89
constructor(*LoggerInterface logger)
Creates the object.
const IO_ADD
I/O thread command: add.
Definition: PollingConnectionMonitor.qc.dox.h:62
bool autostart
Autostart monitoring thread with first connection.
Definition: PollingConnectionMonitor.qc.dox.h:53
stopClear()
Stops monitoring and clears all connections.
const IO_QUIT_REMOVE_ALL
I/O thread command: quit and remove all connection.
Definition: PollingConnectionMonitor.qc.dox.h:74
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition: PollingConnectionMonitor.qc.dox.h:92
const IO_QUIT
I/O thread command: quit.
Definition: PollingConnectionMonitor.qc.dox.h:71
hash< string, hash< PollInfo > > cache
Connection cache; unique name -> connection object wrapper.
Definition: PollingConnectionMonitor.qc.dox.h:47
date ping_timeout
ping timeout duration
Definition: PollingConnectionMonitor.qc.dox.h:56
const PollEventMap
Polling event map.
Definition: PollingConnectionMonitor.qc.dox.h:36
const DefaultPingTimeout
Default ping timeout duration.
Definition: PollingConnectionMonitor.qc.dox.h:77
const DefaultPingRepeat
Default ping repeat duration.
Definition: PollingConnectionMonitor.qc.dox.h:80
bool running()
Returns True if the I/O thread is running.
The ConnectionProvider namespace.
Definition: AbstractConnection.qc.dox.h:28