implement tcp handler and pass reason to callback

This commit is contained in:
Timo Sluis 2023-07-03 13:05:09 +02:00
parent 4fb968f7a4
commit 89ba9138c0
5 changed files with 63 additions and 7 deletions

View File

@ -204,9 +204,10 @@ public:
* disk space, another notification will not be sent.
*
* @param connection The connection that was blocked
* @param reason Why was the connection blocked
*/
virtual void onBlocked(Connection *connection)
{
virtual void onBlocked(Connection *connection, const char *reason)
{
// make sure compilers dont complain about unused parameters
(void) connection;
}

View File

@ -430,11 +430,12 @@ public:
/**
* Report that the connection is blocked
* @param reason
*/
void reportBlocked()
void reportBlocked(const char *reason)
{
// inform the handler
_handler->onBlocked(_parent);
_handler->onBlocked(_parent, reason);
}
/**

View File

@ -116,7 +116,28 @@ private:
* @param connection The connection that was closed and that is now unusable
*/
virtual void onClosed(Connection *connection) override;
/**
* Method that is called when the AMQP connection was blocked.
* @param connection The connection that was blocked
* @param reason Why was the connection blocked
*/
virtual void onBlocked(Connection *connection, const char *reason) override
{
// pass to user space
if (_handler) _handler->onBlocked(this, reason);
}
/**
* Method that is called when the AMQP connection is no longer blocked.
* @param connection The connection that is no longer blocked
*/
virtual void onUnblocked(Connection *connection)
{
// pass to user space
if (_handler) _handler->onUnblocked(this);
}
/**
* Method that is called when the tcp connection has been established
* @param state

View File

@ -190,7 +190,40 @@ public:
// make sure compilers dont complain about unused parameters
(void) connection;
}
/**
* Method that is called when the AMQP connection was blocked.
*
* This method is called, when the server connection gets blocked for the first
* time due to the broker running low on a resource (memory or disk). For
* example, when a RabbitMQ node detects that it is low on RAM, it sends a
* notification to all connected publishing clients supporting this feature.
* If before the connections are unblocked the node also starts running low on
* disk space, another notification will not be sent.
*
* @param connection The connection that was blocked
* @param reason Why was the connection blocked
*/
virtual void onBlocked(TcpConnection *connection, const char *reason)
{
// make sure compilers dont complain about unused parameters
(void) connection;
}
/**
* Method that is called when the AMQP connection is no longer blocked.
*
* This method is called when all resource alarms have cleared and the
* connection is fully unblocked.
*
* @param connection The connection that is no longer blocked
*/
virtual void onUnblocked(TcpConnection *connection)
{
// make sure compilers dont complain about unused parameters
(void) connection;
}
/**
* Method that is called when the TCP connection is lost or closed. This
* is always called if you have also received a call to onConnected().

View File

@ -94,7 +94,7 @@ public:
virtual bool process(ConnectionImpl *connection) override
{
// report that it is blocked
connection->reportBlocked();
connection->reportBlocked(this->reason().c_str());
// done
return true;