Search in sources :

Example 1 with Handler

use of org.apache.qpid.proton.engine.Handler in project azure-service-bus-java by Azure.

the class MessagingFactory method closeConnection.

// One of the parameters must be null
private void closeConnection(ErrorCondition error, Exception cause) {
    // Important to copy the reference of the connection as a call to getConnection might create a new connection while we are still in this method
    Connection currentConnection = this.connection;
    if (currentConnection != null) {
        Link[] links = this.registeredLinks.toArray(new Link[0]);
        this.registeredLinks.clear();
        TRACE_LOGGER.debug("Closing all links on the connection. Number of links '{}'", links.length);
        for (Link link : links) {
            link.close();
        }
        TRACE_LOGGER.debug("Closed all links on the connection. Number of links '{}'", links.length);
        if (currentConnection.getLocalState() != EndpointState.CLOSED) {
            TRACE_LOGGER.info("Closing connection to host");
            currentConnection.close();
        }
        for (Link link : links) {
            Handler handler = BaseHandler.getHandler(link);
            if (handler != null && handler instanceof BaseLinkHandler) {
                BaseLinkHandler linkHandler = (BaseLinkHandler) handler;
                if (error != null) {
                    linkHandler.processOnClose(link, error);
                } else {
                    linkHandler.processOnClose(link, cause);
                }
            }
        }
    }
}
Also used : Connection(org.apache.qpid.proton.engine.Connection) BaseHandler(org.apache.qpid.proton.engine.BaseHandler) Handler(org.apache.qpid.proton.engine.Handler) Link(org.apache.qpid.proton.engine.Link)

Aggregations

BaseHandler (org.apache.qpid.proton.engine.BaseHandler)1 Connection (org.apache.qpid.proton.engine.Connection)1 Handler (org.apache.qpid.proton.engine.Handler)1 Link (org.apache.qpid.proton.engine.Link)1