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;
 
 import static com.amazonaws.event.SDKProgressPublisher.publishProgress;
 
 
Abstract transfer implementation.
 
 public abstract class AbstractTransfer implements Transfer {

    
The current state of this transfer.
 
     protected volatile TransferState state = .;
 
     protected TransferMonitor monitor;

    
The progress of this transfer.
 
     private final TransferProgress transferProgress;
 
     private final String description;

    
Hook for adding/removing more progress listeners.
 
     protected final ProgressListenerChain listenerChain;

    
Collection of listeners to be notified for changes to the state of this transfer via setState()
 
 
     AbstractTransfer(String descriptionTransferProgress transferProgressProgressListenerChain progressListenerChain) {
         this(descriptiontransferProgressprogressListenerChainnull);
     }
 
     AbstractTransfer(String descriptionTransferProgress transferProgress,
             ProgressListenerChain progressListenerChainTransferStateChangeListener stateChangeListener) {
         this. = description;
         this. = progressListenerChain;
         this. = transferProgress;
         addStateChangeListener(stateChangeListener);
     }

    
Returns whether or not the transfer is finished (i.e. completed successfully, failed, or was canceled). This method should never block.

Returns:
Returns true if this transfer is finished (i.e. completed successfully, failed, or was canceled). Returns false if otherwise.
 
     public final synchronized boolean isDone() {
         return ( == . ||
                  == . ||
                  == .);
     }

    
Waits for this transfer to complete. This is a blocking call; the current thread is suspended until this transfer completes.

Throws:
com.amazonaws.AmazonClientException If any errors were encountered in the client while making the request or handling the response.
com.amazonaws.AmazonServiceException If any errors occurred in Amazon S3 while processing the request.
java.lang.InterruptedException If this thread is interrupted while waiting for the transfer to complete.
 
     public void waitForCompletion()
         try {
             Object result = null;
             while (!.isDone() || result == null) {
                 Future<?> f = .getFuture();
                result = f.get();
            }
        } catch (ExecutionException e) {
            rethrowExecutionException(e);
        }
    }

    
Waits for this transfer to finish and returns any error that occurred, or returns null if no errors occurred. This is a blocking call; the current thread will be suspended until this transfer either fails or completes successfully.

Returns:
Any error that occurred while processing this transfer. Otherwise returns null if no errors occurred.
Throws:
java.lang.InterruptedException If this thread is interrupted while waiting for the transfer to complete.
        try {
            while (!.isDone()) {
                .getFuture().get();
            }
            .getFuture().get();
            return null;
        } catch (ExecutionException e) {
            return unwrapExecutionException(e);
        }
    }

    
Returns a human-readable description of this transfer.

Returns:
A human-readable description of this transfer.
    public String getDescription() {
        return ;
    }

    
Returns the current state of this transfer.

Returns:
The current state of this transfer.
    public synchronized TransferState getState() {
        return ;
    }

    
Sets the current state of this transfer.
    public void setState(TransferState state) {
        synchronized (this) {
            this. = state;
        }
        for ( TransferStateChangeListener listener :  ) {
            listener.transferStateChanged(thisstate);
        }
    }

    
Notifies all the registered state change listeners of the state update.
    public void notifyStateChangeListeners(TransferState state) {
        for ( TransferStateChangeListener listener :  ) {
            listener.transferStateChanged(thisstate);
        }
    }

    
Adds the specified progress listener to the list of listeners receiving updates about this transfer's progress.

Parameters:
listener The progress listener to add.
    public synchronized void addProgressListener(ProgressListener listener) {
        .addProgressListener(listener);
    }

    
Removes the specified progress listener from the list of progress listeners receiving updates about this transfer's progress.

Parameters:
listener The progress listener to remove.
    public synchronized void removeProgressListener(ProgressListener listener) {
        .removeProgressListener(listener);
    }

    
    @Deprecated
    public synchronized void addProgressListener(com.amazonaws.services.s3.model.ProgressListener listener) {
    }

    
    @Deprecated
    public synchronized void removeProgressListener(com.amazonaws.services.s3.model.ProgressListener listener) {
    }

    
Adds the given state change listener to the collection of listeners.
    public synchronized void addStateChangeListener(TransferStateChangeListener listener) {
        if ( listener != null )
            .add(listener);
    }

    
Removes the given state change listener from the collection of listeners.
    public synchronized void removeStateChangeListener(TransferStateChangeListener listener) {
        if ( listener != null )
            .remove(listener);
    }

    
Returns progress information about this transfer.

Returns:
The progress information about this transfer.
    public TransferProgress getProgress() {
        return ;
    }

    
Sets the monitor used to poll for transfer completion.
    public void setMonitor(TransferMonitor monitor) {
        this. = monitor;
    }
    public TransferMonitor getMonitor() {
        return ;
    }
    protected void fireProgressEvent(final ProgressEventType eventType) {
        publishProgress(eventType);
    }

    
Examines the cause of the specified ExecutionException and either rethrows it directly (if it's a type of AmazonClientException) or wraps it in an AmazonClientException and rethrows it.

Parameters:
e The execution exception to examine.
    protected void rethrowExecutionException(ExecutionException e) {
        throw unwrapExecutionException(e);
    }

    
Unwraps the root exception that caused the specified ExecutionException and returns it. If it was not an instance of AmazonClientException, it is wrapped as an AmazonClientException.

Parameters:
e The ExecutionException to unwrap.
Returns:
The root exception that caused the specified ExecutionException.
        Throwable t = e.getCause();
        if (t instanceof AmazonClientExceptionreturn (AmazonClientException)t;
        return new AmazonClientException("Unable to complete transfer: " + t.getMessage(), t);
    }
New to GrepCode? Check out our FAQ X