13
13
package org .asynchttpclient .listener ;
14
14
15
15
import java .util .concurrent .ConcurrentLinkedQueue ;
16
- import java .util .concurrent .atomic .AtomicLong ;
17
16
18
17
import org .asynchttpclient .AsyncCompletionHandlerBase ;
19
18
import org .asynchttpclient .FluentCaseInsensitiveStringsMap ;
42
41
* public void onBytesReceived(ByteBuffer buffer) {
43
42
* }
44
43
* <p/>
45
- * public void onBytesSent(ByteBuffer buffer ) {
44
+ * public void onBytesSent(long amount, long current, long total ) {
46
45
* }
47
46
* <p/>
48
47
* public void onRequestResponseCompleted() {
@@ -62,8 +61,6 @@ public class TransferCompletionHandler extends AsyncCompletionHandlerBase {
62
61
private final ConcurrentLinkedQueue <TransferListener > listeners = new ConcurrentLinkedQueue <TransferListener >();
63
62
private final boolean accumulateResponseBytes ;
64
63
private TransferAdapter transferAdapter ;
65
- private AtomicLong bytesTransferred = new AtomicLong (0 );
66
- private AtomicLong totalBytesToTransfer = new AtomicLong (-1 );
67
64
68
65
/**
69
66
* Create a TransferCompletionHandler that will not accumulate bytes. The resulting {@link org.asynchttpclient.Response#getResponseBody()},
@@ -136,10 +133,6 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep
136
133
137
134
@ Override
138
135
public Response onCompleted (Response response ) throws Exception {
139
- if (bytesTransferred .get () > 0L ) {
140
- // onContentWriteCompleted hasn't been notified, it would have been set to -1L (async race)
141
- onContentWriteCompleted ();
142
- }
143
136
fireOnEnd ();
144
137
return response ;
145
138
}
@@ -152,33 +145,8 @@ public STATE onHeaderWriteCompleted() {
152
145
return STATE .CONTINUE ;
153
146
}
154
147
155
- @ Override
156
- public STATE onContentWriteCompleted () {
157
- // onContentWriteProgress might not have been called on last write
158
- long transferred = bytesTransferred .getAndSet (-1L );
159
- long expected = totalBytesToTransfer .get ();
160
-
161
- if (expected <= 0L && transferAdapter != null ) {
162
- FluentCaseInsensitiveStringsMap headers = transferAdapter .getHeaders ();
163
- String contentLengthString = headers .getFirstValue ("Content-Length" );
164
- if (contentLengthString != null )
165
- expected = Long .valueOf (contentLengthString );
166
- }
167
-
168
- if (expected > 0L && transferred != expected ) {
169
- fireOnBytesSent (expected - transferred , expected , expected );
170
- }
171
-
172
- return STATE .CONTINUE ;
173
- }
174
-
175
148
@ Override
176
149
public STATE onContentWriteProgress (long amount , long current , long total ) {
177
- bytesTransferred .addAndGet (amount );
178
-
179
- if (total > 0L )
180
- totalBytesToTransfer .set (total );
181
-
182
150
fireOnBytesSent (amount , current , total );
183
151
return STATE .CONTINUE ;
184
152
}
0 commit comments