TransferManagerParams getParams() { return new TransferManagerParams().withS3Client(resolveS3Client()) .withExecutorService(resolveExecutorService()) .withShutDownThreadPools(resolveShutDownThreadPools()) .withTransferManagerConfiguration(resolveConfiguration()); }
/** * Disables parallel downloads, see {@link #setDisableParallelDownloads(Boolean)} * <p> * Disabling parallel downloads might reduce performance for large files. * </p> * * @return This object for method chaining */ public TransferManagerBuilder disableParallelDownloads() { return withDisableParallelDownloads(Boolean.TRUE); }
private static void downloadFile(ParameterTool params) { final String bucket = params.getRequired("bucket"); final String s3file = params.getRequired("s3file"); final String localFile = params.getRequired("localFile"); TransferManager tx = TransferManagerBuilder.defaultTransferManager(); try { tx.download(bucket, s3file, new File(localFile)).waitForCompletion(); } catch (InterruptedException e) { System.out.println("Transfer interrupted"); } finally { tx.shutdownNow(); } }
@Override public TransferManager apply(TransferManagerParams params) { return new TransferManager(params); } };
/** * Forcefully shuts down this TransferManager instance - currently executing * transfers will not be allowed to finish. It also by default shuts down * the underlying Amazon S3 client. * * @see #shutdownNow(boolean) */ public void shutdownNow() { shutdownNow(true); }
@Override public synchronized void progressChanged(ProgressEvent progressEvent) { ProgressEventType eventType = progressEvent.getEventType(); if (previousType != eventType) { log.debug("Upload progress event (%s/%s): %s", host, key, eventType); previousType = eventType; } double transferred = transfer.getProgress().getPercentTransferred(); if (transferred >= (previousTransferred + 10.0)) { log.debug("Upload percentage (%s/%s): %.0f%%", host, key, transferred); previousTransferred = transferred; } } };
/** * @deprecated Replaced by {@link #getBytesTransferred()} */ public long getBytesTransfered() { return getBytesTransferred(); }
public CopyCallable(TransferManager transferManager, ExecutorService threadPool, CopyImpl copy, CopyObjectRequest copyObjectRequest, ObjectMetadata metadata, ProgressListenerChain progressListenerChain) { this.s3 = transferManager.getAmazonS3Client(); this.configuration = transferManager.getConfiguration(); this.threadPool = threadPool; this.copyObjectRequest = copyObjectRequest; this.metadata = metadata; this.listenerChain = progressListenerChain; this.copy = copy; }
private CopyMonitor(TransferManager manager, CopyImpl transfer, ExecutorService threadPool, CopyCallable multipartCopyCallable, CopyObjectRequest copyObjectRequest, ProgressListenerChain progressListenerChain) { this.s3 = manager.getAmazonS3Client(); this.multipartCopyCallable = multipartCopyCallable; this.origReq = copyObjectRequest; this.listener = progressListenerChain; this.transfer = transfer; this.threadPool = threadPool; }
@Override public synchronized boolean isDone() { for ( Transfer subTransfer : subTransfers ) { if ( !subTransfer.isDone() ) return false; } return true; }
/** * @return Create new instance of builder with all defaults set. */ public static TransferManagerBuilder standard() { return new TransferManagerBuilder(); }
/** * Constructor for use by classes that need to extend the TransferManager. * * @param builder - transfer manager builder with the required configuration */ protected TransferManager(TransferManagerBuilder builder) { this(builder.getParams()); }
/** * Sets the low level client used to make the service calls to Amazon S3. If no * client is specified, a default client will be created using {@link DefaultAwsRegionProviderChain} * and {@link DefaultAWSCredentialsProviderChain}. * * @param s3Client Client implementation to use * @return This object for method chaining. */ public final TransferManagerBuilder withS3Client(AmazonS3 s3Client) { setS3Client(s3Client); return this; }
/** * Sets a new {@link ExecutorFactory} for the builder. The factory is invoked for each transfer * manager created through the builder. * * @param executorFactory New executor factory to use. * @return This object for method chaining. */ public final TransferManagerBuilder withExecutorFactory(ExecutorFactory executorFactory) { setExecutorFactory(executorFactory); return this; }
/** * Sets the size threshold, in bytes, for when to use multi-part copy. Copy requests for objects * over this size will automatically use a multi-part copy strategy, while copy requests for * objects smaller than this threshold will use a single connection to copy the whole object. * * @param multipartCopyThreshold Threshold in which multipart copies will be performed. * @return This object for method chaining. */ public final TransferManagerBuilder withMultipartCopyThreshold(Long multipartCopyThreshold) { setMultipartCopyThreshold(multipartCopyThreshold); return this; }
/** * Releasing all resources created by <code>TransferManager</code> before it * is being garbage collected. */ @Override protected void finalize() throws Throwable { shutdownThreadPools(); }
/** * Sets the minimum size in bytes of each part when a multi-part copy operation is carried out. * Decreasing the minimum part size will cause a large number of copy part requests being * initiated. * * @param multipartCopyPartSize New minimum threshold for copy part size * @return This object for method chaining. */ public final TransferManagerBuilder withMultipartCopyPartSize(Long multipartCopyPartSize) { setMultipartCopyPartSize(multipartCopyPartSize); return this; }
/** * By default, when the transfer manager is shut down, the underlying {@link ExecutorService} is * also shut down. For cases where the same thread pool is reused across different workloads you * can set this option to false to disable that behavior. * * @param shutDownThreadPools True to shut down thread pools on transfer manager shutdown, false * otherwise. * @return This object for method chaining. */ public final TransferManagerBuilder withShutDownThreadPools(Boolean shutDownThreadPools) { setShutDownThreadPools(shutDownThreadPools); return this; }
private UploadMonitor(TransferManager manager, UploadImpl transfer, ExecutorService threadPool, UploadCallable multipartUploadCallable, PutObjectRequest putObjectRequest, ProgressListenerChain progressListenerChain) { this.s3 = manager.getAmazonS3Client(); this.multipartUploadCallable = multipartUploadCallable; this.origReq = putObjectRequest; this.listener = progressListenerChain; this.transfer = transfer; this.threadPool = threadPool; }