Loading...
Searching...
No Matches
PollingConnectionMonitor.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// Qore PollingConnectionMonitor class definition
/* PollingConnectionMonitor.qc Copyright 2016 - 2024 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
namespace ConnectionProvider {
class PollingConnectionMonitor : public LoggerWrapper {
public:
const PollEventMap = ...;
protected:
Mutex m();
hash<string, hash<PollInfo>> cache;
int tid;
bool autostart = True;
date ping_timeout = DefaultPingTimeout;
date ping_repeat = DefaultPingRepeat;
const IO_ADD = "add";
const IO_UPDATE = "update";
const IO_REMOVE = "remove";
const IO_QUIT = "quit";
const DefaultPingTimeout = 30s;
const DefaultPingRepeat = 1m;
public:
private:
File sem_write;
ReadOnlyFile sem_read;
hash<SocketPollInfo> sem_info;
Counter mcnt();
Queue cmdq();
public:
constructor(*LoggerInterface logger) ;
destructor();
hash<auto> getInfo();
setAutostart(bool autostart = True);
bool getAutostart();
start();
stop();
stopClear();
waitStop();
bool running();
add(AbstractConnection conn, *hash<auto> other, *bool start_pending);
addOrUpdate(AbstractConnection conn, *hash<auto> other);
bool removeConnection(string name);
removeConnectionEx(string name);
protected:
startIntern();
public:
protected:
int stopIntern();
public:
protected:
ioThread();
public:
protected:
failedToStartPing(string name, hash<ExceptionInfo> ex);
public:
protected:
handlePingSuccess(string name, date delta, *bool oldok);
public:
protected:
handlePingFailed(string name, date delta, hash<ExceptionInfo> ex);
public:
protected:
handlePingTimeout(string name, date delta);
public:
protected:
handlePingTimeoutIntern(string name, date delta);
public:
protected:
*hash<ExceptionInfo> restartPing(string name, *bool force_restart);
public:
protected:
*bool processCommands();
public:
protected:
sendCmd(string cmd);
public:
};
};
// private symbols
namespace Priv {
hashdecl PollInfo {
// poll start timestamp
date start;
// connection
AbstractConnection conn;
// poll operation
AbstractPollOperation spop;
// other data stored alongside the connection
*hash<auto> other;
}
}
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