Skip to content

Commit 1972c9b

Browse files
committed
Drop AsyncHandlerExtensions in favor of default methods in AsyncHandler
As those methods are just hooks that don’t involve additional computations.
1 parent 6056552 commit 1972c9b

11 files changed

+240
-457
lines changed

client/src/main/java/org/asynchttpclient/AsyncHandler.java

+129
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616
package org.asynchttpclient;
1717

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;
1824
import io.netty.handler.codec.http.HttpHeaders;
1925

2026

@@ -118,4 +124,127 @@ default State onTrailingHeadersReceived(HttpHeaders headers) throws Exception {
118124
* @throws Exception if something wrong happens
119125
*/
120126
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+
}
121250
}

client/src/main/java/org/asynchttpclient/handler/AsyncHandlerExtensions.java

-137
This file was deleted.

client/src/main/java/org/asynchttpclient/handler/AsyncHandlerExtensionsUtils.java

-25
This file was deleted.

client/src/main/java/org/asynchttpclient/handler/ExtendedAsyncHandler.java

-81
This file was deleted.

0 commit comments

Comments
 (0)