Qore ConnectionProvider Module Reference 1.10
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:
35
36
37protected:
39 Mutex m();
40
42 hash<string, hash<PollInfo>> cache;
43
45 int tid;
46
48 bool autostart = True;
49
52
55
57 const IO_ADD = "add";
58
60 const IO_UPDATE = "update";
61
63 const IO_REMOVE = "remove";
64
66 const IO_QUIT = "quit";
67
69 const IO_QUIT_REMOVE_ALL = "quit-remove-all";
70
72 const DefaultPingTimeout = 30s;
73
76
77public:
78
79private:
82
84 ReadOnlyFile sem_read;
85
87 hash<SocketPollInfo> sem_info;
88
90 Counter mcnt();
91
93 Queue cmdq();
94
95public:
96
98 constructor(*LoggerInterface logger) ;
99
100
103
104
107
108
111
112
114
117
118
121
122
125
126
128 bool running();
129
130
132
138 add(AbstractConnection conn, *hash<auto> other);
139
140
142
147 addOrUpdate(AbstractConnection conn, *hash<auto> other);
148
149
151
159 bool removeConnection(string name);
160
161
163
169 removeConnectionEx(string name);
170
171
172protected:
173 startIntern();
174public:
175
176
177protected:
178 int stopIntern();
179public:
180
181
182protected:
183 ioThread();
184public:
185
186
188protected:
189 handlePingSuccess(string name, date delta, *bool oldok);
190public:
191
192
194protected:
195 handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
196public:
197
198
200protected:
201 handlePingTimeout(string name, date delta);
202public:
203
204
206protected:
207 handlePingTimeoutIntern(string name, date delta);
208public:
209
210
212protected:
213 restartPing(string name, *bool force_restart);
214public:
215
216
217protected:
218 *bool processCommands();
219public:
220
221
222protected:
223 sendCmd(string cmd);
224public:
225
226};
227};
228
229// private symbols
230namespace Priv {
231hashdecl PollInfo {
232 // poll start timestamp
233 date start;
234
235 # connection
236 AbstractConnection conn;
237
238 # poll operation
239 AbstractPollOperation spop;
240
241 # other data stored alongside the connection
242 *hash<auto> other;
243}
244};
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:54
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:81
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:63
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:60
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition: PollingConnectionMonitor.qc.dox.h:84
constructor(*LoggerInterface logger)
Creates the object.
const IO_ADD
I/O thread command: add.
Definition: PollingConnectionMonitor.qc.dox.h:57
bool autostart
Autostart monitoring thread with first connection.
Definition: PollingConnectionMonitor.qc.dox.h:48
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:69
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition: PollingConnectionMonitor.qc.dox.h:87
const IO_QUIT
I/O thread command: quit.
Definition: PollingConnectionMonitor.qc.dox.h:66
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:51
const DefaultPingTimeout
Default ping timeout duration.
Definition: PollingConnectionMonitor.qc.dox.h:72
const DefaultPingRepeat
Default ping repeat duration.
Definition: PollingConnectionMonitor.qc.dox.h:75
bool running()
Returns True if the I/O thread is running.
The ConnectionProvider namespace.
Definition: AbstractConnection.qc.dox.h:28