Qore ConnectionProvider Module Reference 2.0
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 - 2024 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
38
39protected:
41 Mutex m();
42
44 hash<string, hash<PollInfo>> cache;
45
47 int tid;
48
50 bool autostart = True;
51
54
57
59 const IO_ADD = "add";
60
62 const IO_UPDATE = "update";
63
65 const IO_REMOVE = "remove";
66
68 const IO_QUIT = "quit";
69
71 const DefaultPingTimeout = 30s;
72
75
76public:
77
78private:
81
83 ReadOnlyFile sem_read;
84
86 hash<SocketPollInfo> sem_info;
87
89 Counter mcnt();
90
92 Queue cmdq();
93
94public:
95
97 constructor(*LoggerInterface logger) ;
98
99
102
103
105 hash<auto> getInfo();
106
107
110
111
114
115
117
120
121
124
125
128
129
131 bool running();
132
133
135
141 add(AbstractConnection conn, *hash<auto> other);
142
143
145
150 addOrUpdate(AbstractConnection conn, *hash<auto> other);
151
152
154
162 bool removeConnection(string name);
163
164
166
172 removeConnectionEx(string name);
173
174
175protected:
176 startIntern();
177public:
178
179
180protected:
181 int stopIntern();
182public:
183
184
185protected:
186 ioThread();
187public:
188
189
191protected:
192 failedToStartPing(string name, hash<ExceptionInfo> ex);
193public:
194
195
197protected:
198 handlePingSuccess(string name, date delta, *bool oldok);
199public:
200
201
203protected:
204 handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
205public:
206
207
209protected:
210 handlePingTimeout(string name, date delta);
211public:
212
213
215protected:
216 handlePingTimeoutIntern(string name, date delta);
217public:
218
219
221
223protected:
224 *hash<ExceptionInfo> restartPing(string name, *bool force_restart);
225public:
226
227
228protected:
229 *bool processCommands();
230public:
231
232
233protected:
234 sendCmd(string cmd);
235public:
236
237};
238};
239
240// private symbols
241namespace Priv {
242hashdecl PollInfo {
243 // poll start timestamp
244 date start;
245
246 // connection
247 AbstractConnection conn;
248
249 // poll operation
250 AbstractPollOperation spop;
251
252 // other data stored alongside the connection
253 *hash<auto> other;
254}
255
256class RecursiveAutoLock {
257
258public:
259protected:
260 Mutex m;
261
262public:
263
264 constructor(Mutex m);
265
266
267 destructor();
268
269};
270}
Abstract base class for connections.
Definition AbstractConnection.qc.dox.h:47
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:56
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:80
setAutostart(bool autostart=True)
Set autostart flag.
hash< auto > getInfo()
Returns information about the object.
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.
*hash< ExceptionInfo > 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:65
int tid
I/O thread TID.
Definition PollingConnectionMonitor.qc.dox.h:47
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:62
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition PollingConnectionMonitor.qc.dox.h:83
constructor(*LoggerInterface logger)
Creates the object.
const IO_ADD
I/O thread command: add.
Definition PollingConnectionMonitor.qc.dox.h:59
bool autostart
Autostart monitoring thread with first connection.
Definition PollingConnectionMonitor.qc.dox.h:50
stopClear()
Stops monitoring and clears all connections.
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition PollingConnectionMonitor.qc.dox.h:86
const IO_QUIT
I/O thread command: quit.
Definition PollingConnectionMonitor.qc.dox.h:68
hash< string, hash< PollInfo > > cache
Connection cache; unique name -> connection object wrapper.
Definition PollingConnectionMonitor.qc.dox.h:44
date ping_timeout
ping timeout duration
Definition PollingConnectionMonitor.qc.dox.h:53
const PollEventMap
Polling event map.
Definition PollingConnectionMonitor.qc.dox.h:36
const DefaultPingTimeout
Default ping timeout duration.
Definition PollingConnectionMonitor.qc.dox.h:71
const DefaultPingRepeat
Default ping repeat duration.
Definition PollingConnectionMonitor.qc.dox.h:74
bool running()
Returns True if the I/O thread is running.
failedToStartPing(string name, hash< ExceptionInfo > ex)
Could not start ping.
The ConnectionProvider namespace.
Definition AbstractConnection.qc.dox.h:28