|
15 | 15 | */
|
16 | 16 | package org.asynchttpclient;
|
17 | 17 |
|
| 18 | +import java.net.InetSocketAddress; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import org.asynchttpclient.netty.request.NettyRequest; |
| 22 | + |
| 23 | +import io.netty.channel.Channel; |
18 | 24 | import io.netty.handler.codec.http.HttpHeaders;
|
19 | 25 |
|
20 | 26 |
|
@@ -118,4 +124,127 @@ default State onTrailingHeadersReceived(HttpHeaders headers) throws Exception {
|
118 | 124 | * @throws Exception if something wrong happens
|
119 | 125 | */
|
120 | 126 | T onCompleted() throws Exception;
|
| 127 | + |
| 128 | + // ////////// DNS ///////////////// |
| 129 | + |
| 130 | + /** |
| 131 | + * Notify the callback before hostname resolution |
| 132 | + * |
| 133 | + * @param name the name to be resolved |
| 134 | + */ |
| 135 | + default void onHostnameResolutionAttempt(String name) { |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Notify the callback after hostname resolution was successful. |
| 140 | + * |
| 141 | + * @param name the name to be resolved |
| 142 | + * @param addresses the resolved addresses |
| 143 | + */ |
| 144 | + default void onHostnameResolutionSuccess(String name, List<InetSocketAddress> addresses) { |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Notify the callback after hostname resolution failed. |
| 149 | + * |
| 150 | + * @param name the name to be resolved |
| 151 | + * @param cause the failure cause |
| 152 | + */ |
| 153 | + default void onHostnameResolutionFailure(String name, Throwable cause) { |
| 154 | + } |
| 155 | + |
| 156 | + // ////////////// TCP CONNECT //////// |
| 157 | + |
| 158 | + /** |
| 159 | + * Notify the callback when trying to open a new connection. |
| 160 | + * |
| 161 | + * Might be called several times if the name was resolved to multiple addresses and we failed to connect to the first(s) one(s). |
| 162 | + * |
| 163 | + * @param remoteAddress the address we try to connect to |
| 164 | + */ |
| 165 | + default void onTcpConnectAttempt(InetSocketAddress remoteAddress) { |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Notify the callback after a successful connect |
| 170 | + * |
| 171 | + * @param remoteAddress the address we try to connect to |
| 172 | + * @param connection the connection |
| 173 | + */ |
| 174 | + default void onTcpConnectSuccess(InetSocketAddress remoteAddress, Channel connection) { |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * Notify the callback after a failed connect. |
| 179 | + * |
| 180 | + * Might be called several times, or be followed by onTcpConnectSuccess when the name was resolved to multiple addresses. |
| 181 | + * |
| 182 | + * @param remoteAddress the address we try to connect to |
| 183 | + * @param cause the cause of the failure |
| 184 | + */ |
| 185 | + default void onTcpConnectFailure(InetSocketAddress remoteAddress, Throwable cause) { |
| 186 | + } |
| 187 | + |
| 188 | + // ////////////// TLS /////////////// |
| 189 | + |
| 190 | + /** |
| 191 | + * Notify the callback before TLS handshake |
| 192 | + */ |
| 193 | + default void onTlsHandshakeAttempt() { |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * Notify the callback after the TLS was successful |
| 198 | + */ |
| 199 | + default void onTlsHandshakeSuccess() { |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Notify the callback after the TLS failed |
| 204 | + * |
| 205 | + * @param cause the cause of the failure |
| 206 | + */ |
| 207 | + default void onTlsHandshakeFailure(Throwable cause) { |
| 208 | + } |
| 209 | + |
| 210 | + // /////////// POOLING ///////////// |
| 211 | + |
| 212 | + /** |
| 213 | + * Notify the callback when trying to fetch a connection from the pool. |
| 214 | + */ |
| 215 | + default void onConnectionPoolAttempt() { |
| 216 | + } |
| 217 | + |
| 218 | + /** |
| 219 | + * Notify the callback when a new connection was successfully fetched from the pool. |
| 220 | + * |
| 221 | + * @param connection the connection |
| 222 | + */ |
| 223 | + default void onConnectionPooled(Channel connection) { |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Notify the callback when trying to offer a connection to the pool. |
| 228 | + * |
| 229 | + * @param connection the connection |
| 230 | + */ |
| 231 | + default void onConnectionOffer(Channel connection) { |
| 232 | + } |
| 233 | + |
| 234 | + // //////////// SENDING ////////////// |
| 235 | + |
| 236 | + /** |
| 237 | + * Notify the callback when a request is being written on the channel. If the original request causes multiple requests to be sent, for example, because of authorization or |
| 238 | + * retry, it will be notified multiple times. |
| 239 | + * |
| 240 | + * @param request the real request object as passed to the provider |
| 241 | + */ |
| 242 | + default void onRequestSend(NettyRequest request) { |
| 243 | + } |
| 244 | + |
| 245 | + /** |
| 246 | + * Notify the callback every time a request is being retried. |
| 247 | + */ |
| 248 | + default void onRetry() { |
| 249 | + } |
121 | 250 | }
|
0 commit comments