Qore ConnectionProvider Module Reference 1.9.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 - 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
33
34public:
35
36
37protected:
39 Mutex m();
40
42 hash<string, hash<PollInfo>> cache;
43
45 int tid;
46
48 *Logger logger;
49
51 bool autostart = True;
52
55
58
60 const IO_ADD = "add";
61
63 const IO_UPDATE = "update";
64
66 const IO_REMOVE = "remove";
67
69 const IO_QUIT = "quit";
70
72 const IO_QUIT_REMOVE_ALL = "quit-remove-all";
73
75 const DefaultPingTimeout = 30s;
76
79
80public:
81
82private:
85
87 ReadOnlyFile sem_read;
88
90 hash<SocketPollInfo> sem_info;
91
93 Counter mcnt();
94
96 Queue cmdq();
97
98public:
99
102
103
106
107
110
111
114
115
118
119
121
124
125
128
129
132
133
135 bool running();
136
137
139
145 add(AbstractConnection conn, *hash<auto> other);
146
147
149
154 addOrUpdate(AbstractConnection conn, *hash<auto> other);
155
156
158
166 bool removeConnection(string name);
167
168
170
176 removeConnectionEx(string name);
177
178
179 logArgs(int lvl, string msg, auto args);
180
181
182 log(int lvl, string msg);
183
184
185protected:
186 startIntern();
187public:
188
189
190protected:
191 int stopIntern();
192public:
193
194
195protected:
196 ioThread();
197public:
198
199
201protected:
202 handlePingSuccess(string name, date delta, *bool oldok);
203public:
204
205
207protected:
208 handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
209public:
210
211
213protected:
214 handlePingTimeout(string name, date delta);
215public:
216
217
219protected:
220 handlePingTimeoutIntern(string name, date delta);
221public:
222
223
225protected:
226 restartPing(string name, *bool force_restart);
227public:
228
229
230protected:
231 *bool processCommands();
232public:
233
234
235protected:
236 sendCmd(string cmd);
237public:
238
239};
240};
241
242// private symbols
243namespace Priv {
244hashdecl PollInfo {
245 // poll start timestamp
246 date start;
247
248 # connection
249 AbstractConnection conn;
250
251 # poll operation
252 AbstractPollOperation spop;
253
254 # other data stored alongside the connection
255 *hash<auto> other;
256}
257};
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:57
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:84
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:66
int tid
I/O thread TID.
Definition: PollingConnectionMonitor.qc.dox.h:45
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:63
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition: PollingConnectionMonitor.qc.dox.h:87
*Logger logger
Logger.
Definition: PollingConnectionMonitor.qc.dox.h:48
const IO_ADD
I/O thread command: add.
Definition: PollingConnectionMonitor.qc.dox.h:60
bool autostart
Autostart monitoring thread with first connection.
Definition: PollingConnectionMonitor.qc.dox.h:51
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:72
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition: PollingConnectionMonitor.qc.dox.h:90
const IO_QUIT
I/O thread command: quit.
Definition: PollingConnectionMonitor.qc.dox.h:69
setLogger(Logger logger)
Sets the logger.
hash< string, hash< PollInfo > > cache
Connection cache; unique name -> connection object wrapper.
Definition: PollingConnectionMonitor.qc.dox.h:42
date ping_timeout
ping timeout duration
Definition: PollingConnectionMonitor.qc.dox.h:54
constructor(*Logger logger)
Creates the object.
const DefaultPingTimeout
Default ping timeout duration.
Definition: PollingConnectionMonitor.qc.dox.h:75
const DefaultPingRepeat
Default ping repeat duration.
Definition: PollingConnectionMonitor.qc.dox.h:78
bool running()
Returns True if the I/O thread is running.
The ConnectionProvider namespace.
Definition: AbstractConnection.qc.dox.h:28