Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enrich ConnectionPoolListener interface to listen to more connection events #4649

Open
Lincong opened this issue Feb 3, 2023 · 1 comment · May be fixed by #5580
Open

Enrich ConnectionPoolListener interface to listen to more connection events #4649

Lincong opened this issue Feb 3, 2023 · 1 comment · May be fixed by #5580
Labels
new feature sprint Issues for OSS Sprint participants

Comments

@Lincong
Copy link

Lincong commented Feb 3, 2023

Original question/context:
https://line-armeria.slack.com/archives/C1NGPBUH2/p1675388028842779

The ConnectionPoolListener (set here) provides APIs to listen 2 types of connection events:

  1. Connection open
  2. Connection close

Consider adding APIs to the ConnectionPoolListener interface to listen to more types of connection events such as:

  1. Connection failed.
  2. Connection state transits to pending. // still trying to establish a connection.
  3. Connection state transits to active. // sending a request, waiting for response, or receiving a response.
  4. Connection state transits to idle. // after the last response has been received and before the next request is sent.

IMO Connection failed listener API is useful and feasible to add. Other connection state transition APIs ( above 2, 3, and 4) may not be very useful or may be very complex/challenging to implement. Let me know what you think @trustin . Thanks!

@jrhee17 jrhee17 added the sprint Issues for OSS Sprint participants label Apr 1, 2024
@ikhoon
Copy link
Contributor

ikhoon commented Apr 4, 2024

I propose new APIs for the new connection events.

public interface ConnectionPoolListener {

    // Since a connection becomes active immediately after it is open, 
    // this method can be replaced with `connectionActive()`.
    @Deprecated
    void connectionOpen(SessionProtocol protocol,
                        InetSocketAddress remoteAddr,
                        InetSocketAddress localAddr,
                        AttributeMap attrs) throws Exception;

    // This method will be invoked when either 1) a connection is established or
    // 2) an idle connection becomes active.
    default void connectionActive(SessionProtocol protocol,
                                  InetSocketAddress remoteAddr,
                                  InetSocketAddress localAddr,
                                  AttributeMap attrs, boolean isNew) throws Exception {
        if (isNew) {
            connectionOpen(protocol, remoteAddr, localAddr, attrs);
        }
    }

    // This method will be invoked when `KeepAliveHandler` detects 
    // that the connection's inactivity exceeds the idle timeout.
    default void connectionIdle(SessionProtocol protocol,
                                InetSocketAddress remoteAddr,
                                InetSocketAddress localAddr,
                                AttributeMap attrs) throws Exception {}

    default void connectionFailed(SessionProtocol protocol,
                                  InetSocketAddress remoteAddr,
                                  InetSocketAddress localAddr,
                                  Throwable cause) throws Exception {}

    void connectionClosed(SessionProtocol protocol,
                          InetSocketAddress remoteAddr,
                          InetSocketAddress localAddr,
                          AttributeMap attrs) throws Exception;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature sprint Issues for OSS Sprint participants
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants