Skip to content

Commit 8373cc3

Browse files
author
Stephane Landelle
committed
Implement onRequestSent for Netty provider, close AsyncHttpClient#434
1 parent 22cb35a commit 8373cc3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
*
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the Apache License Version 2.0 is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
package org.asynchttpclient;
14+
15+
/**
16+
* This interface hosts new low level callback methods on {@link AsyncHandler}.
17+
* For now, those methods are in a dedicated interface in order not to break the existing API,
18+
* but could be merged into one of the existing ones in AHC 2.
19+
*
20+
* More additional hooks might come, such as:
21+
* <ul>
22+
* <li>onRetry()</li>
23+
* <li>onConnected()</li>
24+
* <li>onConnectionClosed()</li>
25+
* <li>onBytesSent(long numberOfBytes)</li>
26+
* <li>onBytesReceived(long numberOfBytes)</li>
27+
* </ul>
28+
*/
29+
public interface AsyncHandlerExtensions {
30+
31+
/**
32+
* Notify the callback when a request is being written on the wire.
33+
* If the original request causes multiple requests to be sent, for example, because of authorization or retry,
34+
* it will be notified multiple times.
35+
* Currently only supported by the Netty provider.
36+
*/
37+
void onRequestSent();
38+
}

providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.concurrent.atomic.AtomicBoolean;
4646

4747
import org.asynchttpclient.AsyncHandler;
48+
import org.asynchttpclient.AsyncHandlerExtensions;
4849
import org.asynchttpclient.AsyncHttpClientConfig;
4950
import org.asynchttpclient.Body;
5051
import org.asynchttpclient.BodyGenerator;
@@ -501,6 +502,9 @@ public final <T> void writeRequest(final Channel channel, final AsyncHttpClientC
501502
// FIXME That doesn't just leave to true, the set is always done? and what's the point of not having a is/get?
502503
if (future.getAndSetWriteHeaders(true)) {
503504
try {
505+
if (future.getAsyncHandler() instanceof AsyncHandlerExtensions) {
506+
AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onRequestSent();
507+
}
504508
channel.writeAndFlush(nettyRequest, channel.newProgressivePromise()).addListener(new ProgressListener(config, true, future.getAsyncHandler(), future));
505509
} catch (Throwable cause) {
506510
// FIXME why not notify?

0 commit comments

Comments
 (0)