added ConnectionHandler::onAttached() and ConnectionHandler::onDetached() methods
This commit is contained in:
parent
c0241cac67
commit
c52e8ff0b2
|
|
@ -41,11 +41,43 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ~ConnectionHandler() = default;
|
virtual ~ConnectionHandler() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that is called immediately after a connection has been attached
|
||||||
|
* to the handler. This method is called right after the connection object
|
||||||
|
* was constructed. You can override this method if you want to initialize
|
||||||
|
* your handler for this specific connection. This is especially useful if
|
||||||
|
* you use your handler to deal with multiple connections, and cannot use
|
||||||
|
* the constructor for initialization.
|
||||||
|
*
|
||||||
|
* @param connection The connection object that was just constructed
|
||||||
|
*/
|
||||||
|
virtual void onAttached(Connection *connection)
|
||||||
|
{
|
||||||
|
// make sure compilers dont complain about unused parameters
|
||||||
|
(void) connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that is called right before a connection object is destructed.
|
||||||
|
* This is the counterpart of the onAttached() method.
|
||||||
|
*
|
||||||
|
* Wacht out: the connection object that is passed to this method is in
|
||||||
|
* the process of being destructed, which makes it unsafe to call any
|
||||||
|
* methods on it.
|
||||||
|
*
|
||||||
|
* @param connection The connection that is being destructed
|
||||||
|
*/
|
||||||
|
virtual void onDetached(Connection *connection)
|
||||||
|
{
|
||||||
|
// make sure compilers dont complain about unused parameters
|
||||||
|
(void) connection;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that is called when the heartbeat frequency is negotiated
|
* Method that is called when the heartbeat frequency is negotiated
|
||||||
* between the server and the client. You normally do not have to
|
* between the server and the client durion connection setup. You
|
||||||
* override this method, because in the default implementation the
|
* normally do not have to override this method, because in the default
|
||||||
* suggested heartbeat is simply accepted by the client.
|
* implementation the suggested heartbeat is simply accepted by the client.
|
||||||
*
|
*
|
||||||
* However, if you want to disable heartbeats, or when you want an
|
* However, if you want to disable heartbeats, or when you want an
|
||||||
* alternative heartbeat interval, you can override this method
|
* alternative heartbeat interval, you can override this method
|
||||||
|
|
@ -121,8 +153,8 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that is called when the login attempt succeeded. After this method
|
* Method that is called when the login attempt succeeded. After this method
|
||||||
* is called, the connection is ready to use. This is the first method
|
* is called, the connection is ready to use, and the RabbitMQ server is
|
||||||
* that is normally called after you've constructed the connection object.
|
* ready to receive instructions.
|
||||||
*
|
*
|
||||||
* According to the AMQP protocol, you must wait for the connection to become
|
* According to the AMQP protocol, you must wait for the connection to become
|
||||||
* ready (and this onConnected method to be called) before you can start
|
* ready (and this onConnected method to be called) before you can start
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ namespace AMQP {
|
||||||
ConnectionImpl::ConnectionImpl(Connection *parent, ConnectionHandler *handler, const Login &login, const std::string &vhost) :
|
ConnectionImpl::ConnectionImpl(Connection *parent, ConnectionHandler *handler, const Login &login, const std::string &vhost) :
|
||||||
_parent(parent), _handler(handler), _login(login), _vhost(vhost)
|
_parent(parent), _handler(handler), _login(login), _vhost(vhost)
|
||||||
{
|
{
|
||||||
|
// tell the handler that it is attached to this connection
|
||||||
|
_handler->onAttached(_parent);
|
||||||
|
|
||||||
// we need to send a protocol header
|
// we need to send a protocol header
|
||||||
send(ProtocolHeaderFrame());
|
send(ProtocolHeaderFrame());
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +51,9 @@ ConnectionImpl::~ConnectionImpl()
|
||||||
|
|
||||||
// invalidate all channels, so they will no longer call methods on this channel object
|
// invalidate all channels, so they will no longer call methods on this channel object
|
||||||
for (auto iter = _channels.begin(); iter != _channels.end(); iter++) iter->second->detach();
|
for (auto iter = _channels.begin(); iter != _channels.end(); iter++) iter->second->detach();
|
||||||
|
|
||||||
|
// tell the handler that it is no longer attached to this connection
|
||||||
|
_handler->onDetached(_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue