Skip to content

Commit 1fa45b4

Browse files
author
Stephane Landelle
committed
Implement onRequestSent for Netty provider
1 parent 9bc2a50 commit 1fa45b4

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 com.ning.http.client;
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+
}

src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.ning.http.client.AsyncHandler;
1919
import com.ning.http.client.AsyncHandler.STATE;
20+
import com.ning.http.client.AsyncHandlerExtensions;
2021
import com.ning.http.client.AsyncHttpClientConfig;
2122
import com.ning.http.client.AsyncHttpProvider;
2223
import com.ning.http.client.Body;
@@ -506,6 +507,9 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
506507
// Leave it to true.
507508
if (future.getAndSetWriteHeaders(true)) {
508509
try {
510+
if (future.getAsyncHandler() instanceof AsyncHandlerExtensions)
511+
AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onRequestSent();
512+
509513
channel.write(nettyRequest).addListener(new ProgressListener(true, future.getAsyncHandler(), future));
510514
} catch (Throwable cause) {
511515
log.debug(cause.getMessage(), cause);

0 commit comments

Comments
 (0)