| 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
28 namespace ConnectionProvider {
30
32 class PollingConnectionMonitor : public LoggerWrapper {
33
34 public:
36 const PollEventMap = ...;
37
38
39 protected:
41 Mutex m();
42
44 hash<string, hash<PollInfo>> cache;
45
47 int tid;
48
50 bool autostart = True;
51
53 date ping_timeout = DefaultPingTimeout;
54
56 date ping_repeat = DefaultPingRepeat;
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
74 const DefaultPingRepeat = 1m;
75
76 public:
77
78 private:
80 File sem_write;
81
83 ReadOnlyFile sem_read;
84
86 hash<SocketPollInfo> sem_info;
87
89 Counter mcnt();
90
92 Queue cmdq();
93
94 public:
95
97 constructor(*LoggerInterface logger) ;
98
99
101 destructor();
102
103
105 hash<auto> getInfo();
106
107
109 setAutostart(bool autostart = True);
110
111
113 bool getAutostart();
114
115
117
119 start();
120
121
123 stop();
124
125
127 stopClear();
128
129
131 waitStop();
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
180 protected:
181 startIntern();
182 public:
183
184
185 protected:
186 int stopIntern();
187 public:
188
189
190 protected:
191 ioThread();
192 public:
193
194
196 protected:
197 failedToStartPing(string name, hash<ExceptionInfo> ex);
198 public:
199
200
202 protected:
203 handlePingSuccess(string name, date delta, *bool oldok);
204 public:
205
206
208 protected:
209 handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
210 public:
211
212
214 protected:
215 handlePingTimeout(string name, date delta);
216 public:
217
218
220 protected:
221 handlePingTimeoutIntern(string name, date delta);
222 public:
223
224
226
228 protected:
229 *hash<ExceptionInfo> restartPing(string name, *bool force_restart);
230 public:
231
232
233 protected:
234 *bool processCommands();
235 public:
236
237
238 protected:
239 sendCmd(string cmd);
240 public:
241
242};
243};
244
245// private symbols
246 namespace 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}
ConnectionProvider::AbstractConnection
Abstract base class for connections.
Definition AbstractConnection.qc.dox.h:69
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:56
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:80
ConnectionProvider::PollingConnectionMonitor::setAutostart
setAutostart(bool autostart=True)
Set autostart flag.
ConnectionProvider::PollingConnectionMonitor::start
start()
Starts monitoring.
ConnectionProvider::PollingConnectionMonitor::getInfo
hash< auto > getInfo()
Returns information about the object.
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
*hash< ExceptionInfo > 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::IO_REMOVE
const IO_REMOVE
I/O thread command: remove.
Definition PollingConnectionMonitor.qc.dox.h:65
ConnectionProvider::PollingConnectionMonitor::mcnt
Counter mcnt()
I/O thread counter.
ConnectionProvider::PollingConnectionMonitor::tid
int tid
I/O thread TID.
Definition PollingConnectionMonitor.qc.dox.h:47
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:62
ConnectionProvider::PollingConnectionMonitor::sem_read
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition PollingConnectionMonitor.qc.dox.h:83
ConnectionProvider::PollingConnectionMonitor::constructor
constructor(*LoggerInterface logger)
Creates the object.
ConnectionProvider::PollingConnectionMonitor::IO_ADD
const IO_ADD
I/O thread command: add.
Definition PollingConnectionMonitor.qc.dox.h:59
ConnectionProvider::PollingConnectionMonitor::autostart
bool autostart
Autostart monitoring thread with first connection.
Definition PollingConnectionMonitor.qc.dox.h:50
ConnectionProvider::PollingConnectionMonitor::stopClear
stopClear()
Stops monitoring and clears all connections.
ConnectionProvider::PollingConnectionMonitor::sem_info
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition PollingConnectionMonitor.qc.dox.h:86
ConnectionProvider::PollingConnectionMonitor::IO_QUIT
const IO_QUIT
I/O thread command: quit.
Definition PollingConnectionMonitor.qc.dox.h:68
ConnectionProvider::PollingConnectionMonitor::add
add(AbstractConnection conn, *hash< auto > other, *bool start_pending)
Adds a connection to be monitored.
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:44
ConnectionProvider::PollingConnectionMonitor::ping_timeout
date ping_timeout
ping timeout duration
Definition PollingConnectionMonitor.qc.dox.h:53
ConnectionProvider::PollingConnectionMonitor::waitStop
waitStop()
Waits for the monitoring thread to stop if it's running.
ConnectionProvider::PollingConnectionMonitor::PollEventMap
const PollEventMap
Polling event map.
Definition PollingConnectionMonitor.qc.dox.h:36
ConnectionProvider::PollingConnectionMonitor::DefaultPingTimeout
const DefaultPingTimeout
Default ping timeout duration.
Definition PollingConnectionMonitor.qc.dox.h:71
ConnectionProvider::PollingConnectionMonitor::DefaultPingRepeat
const DefaultPingRepeat
Default ping repeat duration.
Definition PollingConnectionMonitor.qc.dox.h:74
ConnectionProvider::PollingConnectionMonitor::running
bool running()
Returns True if the I/O thread is running.
ConnectionProvider::PollingConnectionMonitor::failedToStartPing
failedToStartPing(string name, hash< ExceptionInfo > ex)
Could not start ping.
ConnectionProvider
The ConnectionProvider namespace.
Definition AbstractConnection.qc.dox.h:28