Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2012-2015 Amazon Technologies, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *    http://aws.amazon.com/apache2.0
  *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and
 * limitations under the License.
 */
package com.amazonaws.services.s3.transfer.internal;
Interface for multiple file transfers
public abstract class MultipleFileTransfer<T extends Transferextends AbstractTransfer {
    protected final Collection<? extends T> subTransfers;

    
Whether any of the sub-transfers has started.
    private AtomicBoolean subTransferStarted = new AtomicBoolean(false);
    MultipleFileTransfer(String descriptionTransferProgress transferProgress,
            ProgressListenerChain progressListenerChainCollection<? extends T> subTransfers) {
        super(descriptiontransferProgressprogressListenerChain);
        this. = subTransfers;
    }

    
Set the state based on the states of all file downloads. Assumes all file downloads are done.

A single failed sub-transfer makes the entire transfer failed. If there are no failed sub-transfers, a single canceled sub-transfer makes the entire transfer canceled. Otherwise, we consider ourselves Completed.

    public void collateFinalState() {
        boolean seenCanceled = false;
        for ( T download :  ) {
            if ( download.getState() == . ) {
                setState(.);
                return;
            } else if ( download.getState() == . ) {
                seenCanceled = true;
            }
        }
        if ( seenCanceled )
            setState(.);
        else
            setState(.);
    }

    
Override this method so that TransferState updates are also sent out to the progress listener chain in forms of ProgressEvent.
    @Override
    public void setState(TransferState state) {
        super.setState(state);
        switch (state) {
        case :
            break;
        case :
            if ( .compareAndSet(falsetrue) ) {
                /* The first InProgress signal */
            }
            /* Don't need any event code update for subsequent InProgress signals */
            break;
        case :
            break;
        case :
            break;
        case :
            break;
        default:
            break;
        }
    }
New to GrepCode? Check out our FAQ X