Loading...
Searching...
No Matches
PollingConnectionMonitor.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// Qore PollingConnectionMonitor class definition
/* PollingConnectionMonitor.qc Copyright 2016 - 2022 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:
protected:
Mutex m();
hash<string, hash<PollInfo>> cache;
int tid;
*Logger logger;
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 IO_QUIT_REMOVE_ALL = "quit-remove-all";
const DefaultPingTimeout = 30s;
const DefaultPingRepeat = 1m;
public:
private:
File sem_write;
ReadOnlyFile sem_read;
hash<SocketPollInfo> sem_info;
Counter mcnt();
Queue cmdq();
public:
constructor(*Logger logger);
destructor();
setLogger(Logger logger);
setAutostart(bool autostart = True);
bool getAutostart();
start();
stop();
stopClear();
bool running();
add(AbstractConnection conn, *hash<auto> other);
addOrUpdate(AbstractConnection conn, *hash<auto> other);
bool removeConnection(string name);
removeConnectionEx(string name);
logArgs(int lvl, string msg, auto args);
log(int lvl, string msg);
protected:
startIntern();
public:
protected:
int stopIntern();
public:
protected:
ioThread();
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:
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: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.
ConnectionProvider
The ConnectionProvider namespace.
Definition: AbstractConnection.qc.dox.h:28