List of usage examples for com.amazonaws.services.s3.transfer Transfer waitForCompletion
public void waitForCompletion() throws AmazonClientException, AmazonServiceException, InterruptedException;
From source file:aws.example.s3.XferMgrProgress.java
License:Open Source License
public static void waitForCompletion(Transfer xfer) { try {//from ww w .ja v a 2 s .c o m xfer.waitForCompletion(); } catch (AmazonServiceException e) { System.err.println("Amazon service error: " + e.getMessage()); System.exit(1); } catch (AmazonClientException e) { System.err.println("Amazon client error: " + e.getMessage()); System.exit(1); } catch (InterruptedException e) { System.err.println("Transfer interrupted: " + e.getMessage()); System.exit(1); } }
From source file:biz.neustar.webmetrics.plugins.neustar_s3_maven_plugin.S3UploadMojo.java
License:Apache License
/** */ private boolean upload(AmazonS3 s3, String bucketName, File sourceFile, String targetPath) throws MojoExecutionException { TransferManager mgr = new TransferManager(s3); Transfer transfer = null; transfer = mgr.upload(bucketName, targetPath, sourceFile); try {//w w w . jav a2s .c o m transfer.waitForCompletion(); getLog().info("Transferred " + transfer.getProgress().getBytesTransfered() + " bytes."); } catch (AmazonServiceException e) { e.printStackTrace(); return false; } catch (AmazonClientException e) { e.printStackTrace(); return false; } catch (InterruptedException e) { e.printStackTrace(); return false; } return true; }
From source file:com.github.abhinavmishra14.aws.s3.service.impl.AwsS3IamServiceImpl.java
License:Open Source License
@Override public boolean uploadDirectoryOrFileAndListenProgress(final String bucketName, final File source, final String virtualDirectoryKeyPrefix) throws AmazonClientException, AmazonServiceException, FileNotFoundException { LOGGER.info("uploadDirectoryOrFileAndWaitForCompletion invoked, bucketName: {} , Source: {}", bucketName, source.getAbsolutePath());/* w ww .ja v a2s. c o m*/ Transfer transfer = null; final TransferManager transferMgr = new TransferManager(s3client); if (source.isFile()) { transfer = transferMgr.upload(bucketName, source.getPath(), source); } else if (source.isDirectory()) { //upload recursively transfer = transferMgr.uploadDirectory(bucketName, virtualDirectoryKeyPrefix, source, true); } else { throw new FileNotFoundException("File is neither a regular file nor a directory " + source); } // You can poll your transfer's status to check its progress if (transfer.isDone()) { LOGGER.info("Start: {} , State: {} and Progress (%): {}", transfer.getDescription(), transfer.getState(), transfer.getProgress().getPercentTransferred()); } // Add progressListener to listen asynchronous notifications about your transfer's progress // Uncomment below code snippet during development /*transfer.addProgressListener(new ProgressListener() { public void progressChanged(ProgressEvent event) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Transferred bytes: " + (long) event.getBytesTransferred()); } } });*/ try { //Block the current thread and wait for completion //If the transfer fails AmazonClientException will be thrown transfer.waitForCompletion(); } catch (AmazonClientException | InterruptedException excp) { LOGGER.error("Exception occured while waiting for transfer: ", excp); } LOGGER.info("End: {} , State: {} , Progress (%): {}", transfer.getDescription(), transfer.getState(), transfer.getProgress().getPercentTransferred()); return transfer.isDone(); }
From source file:doug.iotdemo.mojo.deployer.Deployer.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { AmazonS3 s3 = new AmazonS3Client(); if (!s3.doesBucketExist(bucketName)) { throw new MojoExecutionException("bucket " + bucketName + " does not exist"); }//from ww w.ja v a 2 s . c o m getLog().info("Uploading " + source.getName() + " to s3://" + bucketName + "/" + bucketKey); TransferManager manager = new TransferManager(s3); Transfer transfer; if (source.isFile()) { transfer = manager.upload(bucketName, bucketKey, source); } else if (source.isDirectory()) { transfer = manager.uploadDirectory(bucketName, bucketKey, source, true); } else { throw new MojoExecutionException("Unknown file type " + source.getAbsolutePath()); } try { transfer.waitForCompletion(); } catch (InterruptedException e) { throw new MojoExecutionException("Upload to S3 failed", e); } }
From source file:org.ow2.proactive.scheduler.examples.SchedulerExamplesUtils.java
License:Open Source License
/** * waits for the transfer to complete, catching any exceptions that occur. * @param xfer/*from w w w. jav a 2 s . co m*/ */ static void waitForCompletion(Transfer xfer) { try { xfer.waitForCompletion(); } catch (AmazonServiceException e) { logger.error("Amazon service error: " + e.getMessage()); System.exit(1); } catch (AmazonClientException e) { logger.error("Amazon client error: " + e.getMessage()); System.exit(1); } catch (InterruptedException e) { logger.error("Transfer interrupted: " + e.getMessage()); Thread.currentThread().interrupt(); System.exit(1); } }
From source file:squash.deployment.lambdas.utils.TransferUtils.java
License:Apache License
/** * Waits for S3 transfers to complete.// www . j a va2 s .c o m * * <p>S3 transfers via the S3 TransferManager are asynchronous. This can be used * by all transfers (uploads, copies, and downloads) to wait until they have * completed. * * @param transfer returned by the TransferManager when transfer is initiated. * @param logger a CloudwatchLogs logger. * @throws AmazonServiceException if any errors occurred in S3 during the wait. * @throws InterruptedException if the wait is interrupted. */ public static void waitForS3Transfer(Transfer transfer, LambdaLogger logger) throws InterruptedException { while (transfer.isDone() == false) { logger.log("Transfer progress: " + transfer.getProgress().getPercentTransferred() + "%"); try { Thread.sleep(100); // milliseconds } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.log("Transfer thread interrupted"); throw e; } } logger.log("Transfer is done - now wait for completion to see if transfer succeeded."); try { transfer.waitForCompletion(); // Will throw if transfer failed } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.log("Transfer thread interrupted"); throw e; } }