@@ -91,13 +91,13 @@ public Boolean call() throws Exception {
9191 if (TransferNetworkLossHandler .getInstance () != null &&
9292 !TransferNetworkLossHandler .getInstance ().isNetworkConnected ()) {
9393 LOGGER .info ("Network not connected. Setting the state to WAITING_FOR_NETWORK." );
94- updater .updateState (upload .id , TransferState .WAITING_FOR_NETWORK );
95- return false ;
96- }
97- } catch (TransferUtilityException transferUtilityException ) {
98- LOGGER .error ("TransferUtilityException: [" + transferUtilityException + "]" );
94+ updater .updateState (upload .id , TransferState .WAITING_FOR_NETWORK );
95+ return false ;
96+ }
97+ } catch (TransferUtilityException transferUtilityException ) {
98+ LOGGER .error ("TransferUtilityException: [" + transferUtilityException + "]" );
9999 }
100-
100+
101101 updater .updateState (upload .id , TransferState .IN_PROGRESS );
102102 if (upload .isMultipart == 1 && upload .partNumber == 0 ) {
103103 /*
@@ -147,7 +147,7 @@ private Boolean uploadMultipartAndWaitForCompletion() throws ExecutionException
147147 upload .id , bytesAlreadyTransferred ));
148148 }
149149 }
150- UploadTaskProgressListener uploadTaskProgressListener = new UploadTaskProgressListener (upload );
150+ UploadTaskProgressListener uploadTaskProgressListener = new UploadTaskProgressListener (bytesAlreadyTransferred );
151151 updater .updateProgress (upload .id , bytesAlreadyTransferred , upload .bytesTotal , false );
152152
153153 requestList = dbUtil .getNonCompletedPartRequestsFromDB (upload .id ,
@@ -182,11 +182,11 @@ private Boolean uploadMultipartAndWaitForCompletion() throws ExecutionException
182182 if (TransferNetworkLossHandler .getInstance () != null &&
183183 !TransferNetworkLossHandler .getInstance ().isNetworkConnected ()) {
184184 LOGGER .info ("Network not connected. Setting the state to WAITING_FOR_NETWORK." );
185- updater .updateState (upload .id , TransferState .WAITING_FOR_NETWORK );
186- return false ;
187- }
188- } catch (TransferUtilityException transferUtilityException ) {
189- LOGGER .error ("TransferUtilityException: [" + transferUtilityException + "]" );
185+ updater .updateState (upload .id , TransferState .WAITING_FOR_NETWORK );
186+ return false ;
187+ }
188+ } catch (TransferUtilityException transferUtilityException ) {
189+ LOGGER .error ("TransferUtilityException: [" + transferUtilityException + "]" );
190190 }
191191 }
192192 } catch (final Exception e ) {
@@ -216,7 +216,7 @@ private Boolean uploadMultipartAndWaitForCompletion() throws ExecutionException
216216 return false ;
217217 }
218218
219- // interrupted due to network. Set the TransferState to
219+ // interrupted due to network. Set the TransferState to
220220 // WAITING_FOR_NETWORK if the individual parts were waiting for network
221221 for (final UploadPartTaskMetadata task : uploadPartTasks .values ()) {
222222 if (TransferState .WAITING_FOR_NETWORK .equals (task .state )) {
@@ -230,11 +230,11 @@ private Boolean uploadMultipartAndWaitForCompletion() throws ExecutionException
230230 if (TransferNetworkLossHandler .getInstance () != null &&
231231 !TransferNetworkLossHandler .getInstance ().isNetworkConnected ()) {
232232 LOGGER .info ("Network not connected. Setting the state to WAITING_FOR_NETWORK." );
233- updater .updateState (upload .id , TransferState .WAITING_FOR_NETWORK );
234- return false ;
235- }
236- } catch (TransferUtilityException transferUtilityException ) {
237- LOGGER .error ("TransferUtilityException: [" + transferUtilityException + "]" );
233+ updater .updateState (upload .id , TransferState .WAITING_FOR_NETWORK );
234+ return false ;
235+ }
236+ } catch (TransferUtilityException transferUtilityException ) {
237+ LOGGER .error ("TransferUtilityException: [" + transferUtilityException + "]" );
238238 }
239239
240240 // interrupted due to reasons other than network.
@@ -497,9 +497,11 @@ class UploadTaskProgressListener implements ProgressListener {
497497
498498 // This variable tracks the previously reported total bytes transferred.
499499 private long prevTotalBytesTransferredOfAllParts ;
500+ private final long bytesAlreadyTransferred ;
500501
501- UploadTaskProgressListener (TransferRecord upload ) {
502- this .prevTotalBytesTransferredOfAllParts = upload .bytesCurrent ;
502+ UploadTaskProgressListener (long bytesAlreadyTransferred ) {
503+ prevTotalBytesTransferredOfAllParts = bytesAlreadyTransferred ;
504+ this .bytesAlreadyTransferred = bytesAlreadyTransferred ;
503505 }
504506
505507 @ Override
@@ -508,26 +510,25 @@ public void progressChanged(final ProgressEvent progressEvent) {
508510 }
509511
510512 public synchronized void onProgressChanged (final int partNum ,
511- final long bytesTransferredSoFarForPartNum ) {
513+ final long bytesTransferredSoFarForPartNum ) {
512514 UploadPartTaskMetadata partNumTask = uploadPartTasks .get (partNum );
513515 if (partNumTask == null ) {
514516 LOGGER .info ("Update received for unknown part. Ignoring." );
515517 return ;
516518 }
517519
518520 partNumTask .bytesTransferredSoFar = bytesTransferredSoFarForPartNum ;
519-
520- // Compute the sum of bytesTransferredSoFar for all parts
521- long totalBytesTransferredOfAllParts = 0 ;
521+ // Compute the sum of bytesTransferredSoFar for all parts and already completed parts
522+ long totalBytesTransferredOfAllParts = bytesAlreadyTransferred ;
522523 for (Map .Entry <Integer , UploadPartTaskMetadata > part : uploadPartTasks .entrySet ()) {
523524 totalBytesTransferredOfAllParts += part .getValue ().bytesTransferredSoFar ;
524525 }
525-
526526 // Update the transfer record and the transfer listener
527- // when the accumulated total bytesTransferred (totalBytesTransferredOfAllParts)
528- // exceeds the previously reported toal bytesTransferred
527+ // when the accumulated total bytesTransferred (totalBytesTransferredOfAllParts)
528+ // exceeds the previously reported toal bytesTransferred
529529 // (prevTotalBytesTransferredOfAllParts).
530- if (totalBytesTransferredOfAllParts > prevTotalBytesTransferredOfAllParts ) {
530+ if (totalBytesTransferredOfAllParts > prevTotalBytesTransferredOfAllParts &&
531+ totalBytesTransferredOfAllParts <= upload .bytesTotal ) {
531532 updater .updateProgress (UploadTask .this .upload .id ,
532533 totalBytesTransferredOfAllParts ,
533534 UploadTask .this .upload .bytesTotal ,
0 commit comments