Qore ConnectionProvider Module Reference 2.0.1
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
132
133
135 bool running();
136
137
139
146 add(AbstractConnection conn, *hash<auto> other, *bool start_pending);
147
148
150
155 addOrUpdate(AbstractConnection conn, *hash<auto> other);
156
157
159
167 bool removeConnection(string name);
168
169
171
177 removeConnectionEx(string name);
178
179
180protected:
181 startIntern();
182public:
183
184
185protected:
186 int stopIntern();
187public:
188
189
190protected:
191 ioThread();
192public:
193
194
196protected:
197 failedToStartPing(string name, hash<ExceptionInfo> ex);
198public:
199
200
202protected:
203 handlePingSuccess(string name, date delta, *bool oldok);
204public:
205
206
208protected:
209 handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
210public:
211
212
214protected:
215 handlePingTimeout(string name, date delta);
216public:
217
218
220protected:
221 handlePingTimeoutIntern(string name, date delta);
222public:
223
224
226
228protected:
229 *hash<ExceptionInfo> restartPing(string name, *bool force_restart);
230public:
231
232
233protected:
234 *bool processCommands();
235public:
236
237
238protected:
239 sendCmd(string cmd);
240public:
241
242};
243};
244
245// private symbols
246namespace Priv {
247hashdecl PollInfo {
248 // poll start timestamp
249 date start;
250
251 // connection
252 AbstractConnection conn;
253
254 // poll operation
255 AbstractPollOperation spop;
256
257 // other data stored alongside the connection
258 *hash<auto> other;
259}
260}
Abstract base class for connections.
Definition AbstractConnection.qc.dox.h:69
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.
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
add(AbstractConnection conn, *hash< auto > other, *bool start_pending)
Adds a connection to be monitored.
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
waitStop()
Waits for the monitoring thread to stop if it's running.
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