Qore ConnectionProvider Module Reference  1.7
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 
33 
34 public:
35 
36 
37 protected:
39  Mutex m();
40 
42  hash<string, hash<PollInfo>> cache;
43 
45  Counter cnt();
46 
48  int tid;
49 
51  Queue cmdq();
52 
54  *Logger logger;
55 
58 
61 
63  const IO_ADD = "add";
64 
66  const IO_UPDATE = "update";
67 
69  const IO_REMOVE = "remove";
70 
72  const IO_QUIT = "quit";
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 
92 public:
93 
95  constructor(*Logger logger);
96 
97 
100 
101 
103  setLogger(Logger logger);
104 
105 
107 
109  start();
110 
111 
113  stop();
114 
115 
117  bool running();
118 
119 
121 
127 
128 
130 
135 
136 
138 
144  bool removeConnection(string name);
145 
146 
148 
154  removeConnectionEx(string name);
155 
156 
157 protected:
158  ioThread();
159 public:
160 
161 
163 protected:
164  handlePingSuccess(string name);
165 public:
166 
167 
169 protected:
170  handlePingFailed(string name, hash<ExceptionInfo> ex);
171 public:
172 
173 
175 protected:
176  handlePingTimeout(string name);
177 public:
178 
179 
181 protected:
182  restartPing(string name, *bool force_restart);
183 public:
184 
185 
186 protected:
187  *bool processCommands();
188 public:
189 
190 
191 protected:
192  sendCmd(string cmd);
193 public:
194 
195 };
196 };
197 
198 // private symbols
199 namespace Priv {
200 hashdecl PollInfo {
201  // poll start timestamp
202  date start;
203 
204  # connection
205  AbstractConnection conn;
206 
207  # poll operation
208  AbstractPollOperation spop;
209 }
210 };
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:60
File sem_write
File to signal the I/O thread.
Definition: PollingConnectionMonitor.qc.dox.h:84
Mutex m()
Lock for atomic actions.
Queue cmdq()
I/O thread command queue.
restartPing(string name, *bool force_restart)
Restarts a ping operation.
handlePingFailed(string name, hash< ExceptionInfo > ex)
Handles a failed ping.
removeConnectionEx(string name)
Removes the given connection.
addOrUpdate(AbstractConnection conn)
Adds or updates an existing connection that is already being monitored.
const IO_REMOVE
I/O thread command: remove.
Definition: PollingConnectionMonitor.qc.dox.h:69
int tid
I/O thread TID.
Definition: PollingConnectionMonitor.qc.dox.h:48
add(AbstractConnection conn)
Adds a connection to be monitored.
destructor()
Stops the monitoring thread and destroys the object.
const IO_UPDATE
I/O thread command: update.
Definition: PollingConnectionMonitor.qc.dox.h:66
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:54
const IO_ADD
I/O thread command: add.
Definition: PollingConnectionMonitor.qc.dox.h:63
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:72
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:57
constructor(*Logger logger)
Creates the object.
const DefaultPingTimeout
Default ping timeout duration.
Definition: PollingConnectionMonitor.qc.dox.h:75
handlePingTimeout(string name)
Handles a poll timeout.
const DefaultPingRepeat
Default ping repeat duration.
Definition: PollingConnectionMonitor.qc.dox.h:78
bool running()
Returns True if the I/O thread is running.
handlePingSuccess(string name)
Handles a successful ping.
date date(date dt)
The ConnectionProvider namespace.
Definition: AbstractConnection.qc.dox.h:28