| Qore ConnectionProvider Module Reference 1.7.1

PollingConnectionMonitor.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // Qore PollingConnectionMonitor class definition
3
4 /* PollingConnectionMonitor.qc Copyright 2016 - 2022 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
28 namespace ConnectionProvider {
30
32 class PollingConnectionMonitor {
33
34 public:
35
36
37 protected:
39 Mutex m();
40
42 hash<string, hash<PollInfo>> cache;
43
45 int tid;
46
48 *Logger logger;
49
51 bool autostart = True;
52
54 date ping_timeout = DefaultPingTimeout;
55
57 date ping_repeat = DefaultPingRepeat;
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
78 const DefaultPingRepeat = 1m;
79
80 public:
81
82 private:
84 File sem_write;
85
87 ReadOnlyFile sem_read;
88
90 hash<SocketPollInfo> sem_info;
91
93 Counter mcnt();
94
96 Queue cmdq();
97
98 public:
99
101 constructor(*Logger logger);
102
103
105 destructor();
106
107
109 setLogger(Logger logger);
110
111
113 setAutostart(bool autostart = True);
114
115
117 bool getAutostart();
118
119
121
123 start();
124
125
127 stop();
128
129
131 stopClear();
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
185 protected:
186 startIntern();
187 public:
188
189
190 protected:
191 int stopIntern();
192 public:
193
194
195 protected:
196 ioThread();
197 public:
198
199
201 protected:
202 handlePingSuccess(string name, date delta, *bool oldok);
203 public:
204
205
207 protected:
208 handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
209 public:
210
211
213 protected:
214 handlePingTimeout(string name, date delta);
215 public:
216
217
219 protected:
220 handlePingTimeoutIntern(string name, date delta);
221 public:
222
223
225 protected:
226 restartPing(string name, *bool force_restart);
227 public:
228
229
230 protected:
231 *bool processCommands();
232 public:
233
234
235 protected:
236 sendCmd(string cmd);
237 public:
238
239 };
240 };
241
242 // private symbols
243 namespace Priv {
244 hashdecl 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 };
ConnectionProvider::AbstractConnection
abstract base class for connections
Definition: AbstractConnection.qc.dox.h:34
ConnectionProvider::PollingConnectionMonitor
Class for monitoring connection supporting the polling API.
Definition: PollingConnectionMonitor.qc.dox.h:32
ConnectionProvider::PollingConnectionMonitor::removeConnection
bool removeConnection(string name)
Removes the given connection.
ConnectionProvider::PollingConnectionMonitor::ping_repeat
date ping_repeat
ping repeat duration
Definition: PollingConnectionMonitor.qc.dox.h:57
ConnectionProvider::PollingConnectionMonitor::handlePingTimeout
handlePingTimeout(string name, date delta)
Handles a poll timeout.
ConnectionProvider::PollingConnectionMonitor::handlePingSuccess
handlePingSuccess(string name, date delta, *bool oldok)
Handles a successful ping.
ConnectionProvider::PollingConnectionMonitor::sem_write
File sem_write
File to signal the I/O thread.
Definition: PollingConnectionMonitor.qc.dox.h:84
ConnectionProvider::PollingConnectionMonitor::setAutostart
setAutostart(bool autostart=True)
Set autostart flag.
ConnectionProvider::PollingConnectionMonitor::start
start()
Starts monitoring.
ConnectionProvider::PollingConnectionMonitor::m
Mutex m()
Lock for atomic actions.
ConnectionProvider::PollingConnectionMonitor::cmdq
Queue cmdq()
I/O thread command queue.
ConnectionProvider::PollingConnectionMonitor::handlePingFailed
handlePingFailed(string name, date delta, hash< ExceptionInfo > ex)
Handles a failed ping.
ConnectionProvider::PollingConnectionMonitor::restartPing
restartPing(string name, *bool force_restart)
Restarts a ping operation.
ConnectionProvider::PollingConnectionMonitor::handlePingTimeoutIntern
handlePingTimeoutIntern(string name, date delta)
Handles a ping timeout.
ConnectionProvider::PollingConnectionMonitor::removeConnectionEx
removeConnectionEx(string name)
Removes the given connection.
ConnectionProvider::PollingConnectionMonitor::add
add(AbstractConnection conn, *hash< auto > other)
Adds a connection to be monitored.
ConnectionProvider::PollingConnectionMonitor::IO_REMOVE
const IO_REMOVE
I/O thread command: remove.
Definition: PollingConnectionMonitor.qc.dox.h:66
ConnectionProvider::PollingConnectionMonitor::mcnt
Counter mcnt()
I/O thread counter.
ConnectionProvider::PollingConnectionMonitor::tid
int tid
I/O thread TID.
Definition: PollingConnectionMonitor.qc.dox.h:45
ConnectionProvider::PollingConnectionMonitor::addOrUpdate
addOrUpdate(AbstractConnection conn, *hash< auto > other)
Adds or updates an existing connection that is already being monitored.
ConnectionProvider::PollingConnectionMonitor::destructor
destructor()
Stops the monitoring thread and destroys the object.
ConnectionProvider::PollingConnectionMonitor::IO_UPDATE
const IO_UPDATE
I/O thread command: update.
Definition: PollingConnectionMonitor.qc.dox.h:63
ConnectionProvider::PollingConnectionMonitor::sem_read
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition: PollingConnectionMonitor.qc.dox.h:87
ConnectionProvider::PollingConnectionMonitor::logger
*Logger logger
Logger.
Definition: PollingConnectionMonitor.qc.dox.h:48
ConnectionProvider::PollingConnectionMonitor::IO_ADD
const IO_ADD
I/O thread command: add.
Definition: PollingConnectionMonitor.qc.dox.h:60
ConnectionProvider::PollingConnectionMonitor::autostart
bool autostart
Autostart monitoring thread with first connection.
Definition: PollingConnectionMonitor.qc.dox.h:51
ConnectionProvider::PollingConnectionMonitor::stopClear
stopClear()
Stops monitoring and clears all connections.
ConnectionProvider::PollingConnectionMonitor::IO_QUIT_REMOVE_ALL
const IO_QUIT_REMOVE_ALL
I/O thread command: quit and remove all connection.
Definition: PollingConnectionMonitor.qc.dox.h:72
ConnectionProvider::PollingConnectionMonitor::sem_info
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition: PollingConnectionMonitor.qc.dox.h:90
ConnectionProvider::PollingConnectionMonitor::IO_QUIT
const IO_QUIT
I/O thread command: quit.
Definition: PollingConnectionMonitor.qc.dox.h:69
ConnectionProvider::PollingConnectionMonitor::setLogger
setLogger(Logger logger)
Sets the logger.
ConnectionProvider::PollingConnectionMonitor::stop
stop()
Stops monitoring.
ConnectionProvider::PollingConnectionMonitor::getAutostart
bool getAutostart()
Get autostart flag.
ConnectionProvider::PollingConnectionMonitor::cache
hash< string, hash< PollInfo > > cache
Connection cache; unique name -> connection object wrapper.
Definition: PollingConnectionMonitor.qc.dox.h:42
ConnectionProvider::PollingConnectionMonitor::ping_timeout
date ping_timeout
ping timeout duration
Definition: PollingConnectionMonitor.qc.dox.h:54
ConnectionProvider::PollingConnectionMonitor::constructor
constructor(*Logger logger)
Creates the object.
ConnectionProvider::PollingConnectionMonitor::DefaultPingTimeout
const DefaultPingTimeout
Default ping timeout duration.
Definition: PollingConnectionMonitor.qc.dox.h:75
ConnectionProvider::PollingConnectionMonitor::DefaultPingRepeat
const DefaultPingRepeat
Default ping repeat duration.
Definition: PollingConnectionMonitor.qc.dox.h:78
ConnectionProvider::PollingConnectionMonitor::running
bool running()
Returns True if the I/O thread is running.
True
const True
date
date date(date dt)
ConnectionProvider
The ConnectionProvider namespace.
Definition: AbstractConnection.qc.dox.h:28