Skip to content

Commit fbdfcb1

Browse files
author
Stephane Landelle
committed
All bytes are notified since 4.0.9
1 parent b153319 commit fbdfcb1

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package org.asynchttpclient.listener;
1414

1515
import java.util.concurrent.ConcurrentLinkedQueue;
16-
import java.util.concurrent.atomic.AtomicLong;
1716

1817
import org.asynchttpclient.AsyncCompletionHandlerBase;
1918
import org.asynchttpclient.FluentCaseInsensitiveStringsMap;
@@ -42,7 +41,7 @@
4241
* public void onBytesReceived(ByteBuffer buffer) {
4342
* }
4443
* <p/>
45-
* public void onBytesSent(ByteBuffer buffer) {
44+
* public void onBytesSent(long amount, long current, long total) {
4645
* }
4746
* <p/>
4847
* public void onRequestResponseCompleted() {
@@ -62,8 +61,6 @@ public class TransferCompletionHandler extends AsyncCompletionHandlerBase {
6261
private final ConcurrentLinkedQueue<TransferListener> listeners = new ConcurrentLinkedQueue<TransferListener>();
6362
private final boolean accumulateResponseBytes;
6463
private TransferAdapter transferAdapter;
65-
private AtomicLong bytesTransferred = new AtomicLong(0);
66-
private AtomicLong totalBytesToTransfer = new AtomicLong(-1);
6764

6865
/**
6966
* 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
136133

137134
@Override
138135
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-
}
143136
fireOnEnd();
144137
return response;
145138
}
@@ -152,33 +145,8 @@ public STATE onHeaderWriteCompleted() {
152145
return STATE.CONTINUE;
153146
}
154147

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-
175148
@Override
176149
public STATE onContentWriteProgress(long amount, long current, long total) {
177-
bytesTransferred.addAndGet(amount);
178-
179-
if (total > 0L)
180-
totalBytesToTransfer.set(total);
181-
182150
fireOnBytesSent(amount, current, total);
183151
return STATE.CONTINUE;
184152
}

0 commit comments

Comments
 (0)