本文整理汇总了Java中com.amazonaws.event.ProgressListener类的典型用法代码示例。如果您正苦于以下问题:Java ProgressListener类的具体用法?Java ProgressListener怎么用?Java ProgressListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProgressListener类属于com.amazonaws.event包,在下文中一共展示了ProgressListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeRequest
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
/**
* Publishes the "request content length" event, and returns an input stream, which will be
* made mark-and-resettable if possible, for progress tracking purposes.
*
* @return an input stream, which will be made mark-and-resettable if possible, for progress
* tracking purposes; or null if the request doesn't have an input stream
*/
private InputStream beforeRequest() {
ProgressListener listener = requestConfig.getProgressListener();
reportContentLength(listener);
if (request.getContent() == null) {
return null;
}
final InputStream content = monitorStreamProgress(listener,
buffer(
makeResettable(
request.getContent())));
if (AmazonHttpClient.unreliableTestConfig == null) {
return content;
}
return wrapWithUnreliableStream(content);
}
示例2: verifyBaseAfterCopy
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
private static void verifyBaseAfterCopy(final ProgressListener listener,
final AWSCredentials credentials,
final RequestMetricCollector collector,
final AmazonWebServiceRequest from, final AmazonWebServiceRequest to) {
RequestClientOptions toOptions;
Map<String, String> headers = to.getCustomRequestHeaders();
assertTrue(2 == headers.size());
assertEquals("v1", headers.get("k1"));
assertEquals("v2", headers.get("k2"));
Map<String, List<String>> parmas = to.getCustomQueryParameters();
assertTrue(2 == parmas.size());
assertEquals(Arrays.asList("v1"), parmas.get("k1"));
assertEquals(Arrays.asList("v2a", "v2b"), parmas.get("k2"));
assertSame(listener, to.getGeneralProgressListener());
assertSame(credentials, to.getRequestCredentials());
assertSame(collector, to.getRequestMetricCollector());
assertTrue(1234 == to.getReadLimit());
toOptions = to.getRequestClientOptions();
assertEquals(
from.getRequestClientOptions().getClientMarker(
Marker.USER_AGENT),
toOptions.getClientMarker(Marker.USER_AGENT));
assertTrue(1234 == toOptions.getReadLimit());
}
示例3: createProgressListener
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
private ProgressListener createProgressListener(Transfer transfer)
{
return new ProgressListener()
{
private ProgressEventType previousType;
private double previousTransferred;
@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;
}
}
};
}
示例4: doUpload
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
Upload doUpload(String bucket, String fileName, InputStream is, ObjectMetadata metadata) {
final PutObjectRequest putObjectRequest = new PutObjectRequest(
bucket,
fileName,
is,
metadata
);
final String object = bucket + s3TargetConfigBean.s3Config.delimiter + fileName;
Upload upload = transferManager.upload(putObjectRequest);
upload.addProgressListener((ProgressListener) progressEvent -> {
switch (progressEvent.getEventType()) {
case TRANSFER_STARTED_EVENT:
LOG.debug("Started uploading object {} into Amazon S3", object);
break;
case TRANSFER_COMPLETED_EVENT:
LOG.debug("Completed uploading object {} into Amazon S3", object);
break;
case TRANSFER_FAILED_EVENT:
LOG.debug("Failed uploading object {} into Amazon S3", object);
break;
default:
break;
}
});
return upload;
}
示例5: store
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
@Override
public void store( final Movie movie ) throws MovieNotStoredException
{
final String key = movie.getMovieId().getMovieId();
logger.info( "Uploading {} to S3 key {}", movie, key );
final File movieFile = movie.getPath().toFile();
final PutObjectRequest putObjectRequest = new PutObjectRequest( S3_BUCKET_HOOD_ETS_SOURCE, key, movieFile );
final ProgressListener progressListener = new S3ProgressListener( key, movieFile.length() );
try
{
final Upload upload = this.transferManager.upload( putObjectRequest );
upload.addProgressListener( progressListener );
upload.waitForCompletion();
}
catch ( AmazonClientException | InterruptedException e )
{
this.transferManager.abortMultipartUploads( S3_BUCKET_HOOD_ETS_SOURCE, new Date() );
throw new MovieNotStoredException( movie, e );
}
logger.info( "Upload complete." );
}
示例6: getProgressListener
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
/**
* Returns the optional progress listener for receiving updates about object
* download status.
*
* @return the optional progress listener for receiving updates about object
* download status.
*
* @deprecated use {@link #getGeneralProgressListener()} instead.
*/
@Deprecated
public com.amazonaws.services.s3.model.ProgressListener getProgressListener() {
ProgressListener generalProgressListener = getGeneralProgressListener();
if (generalProgressListener instanceof LegacyS3ProgressListener) {
return ((LegacyS3ProgressListener)generalProgressListener).unwrap();
} else {
return null;
}
}
示例7: copyFile
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
private void copyFile(String srcKey, String dstKey) throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("copyFile " + srcKey + " -> " + dstKey);
}
ObjectMetadata srcom = s3.getObjectMetadata(bucket, srcKey);
final ObjectMetadata dstom = srcom.clone();
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
dstom.setServerSideEncryption(serverSideEncryptionAlgorithm);
}
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, srcKey, bucket, dstKey);
copyObjectRequest.setCannedAccessControlList(cannedACL);
copyObjectRequest.setNewObjectMetadata(dstom);
ProgressListener progressListener = new ProgressListener() {
public void progressChanged(ProgressEvent progressEvent) {
switch (progressEvent.getEventCode()) {
case ProgressEvent.PART_COMPLETED_EVENT_CODE:
statistics.incrementWriteOps(1);
break;
default:
break;
}
}
};
Copy copy = transfers.copy(copyObjectRequest);
copy.addProgressListener(progressListener);
try {
copy.waitForCopyResult();
statistics.incrementWriteOps(1);
} catch (InterruptedException e) {
throw new IOException("Got interrupted, cancelling");
}
}
示例8: doExecute
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
private Response<Output> doExecute() throws InterruptedException {
runBeforeRequestHandlers();
setSdkTransactionId(request);
setUserAgent(request);
ProgressListener listener = requestConfig.getProgressListener();
// add custom headers
request.getHeaders().putAll(config.getHeaders());
request.getHeaders().putAll(requestConfig.getCustomRequestHeaders());
// add custom query parameters
mergeQueryParameters(requestConfig.getCustomQueryParameters());
Response<Output> response = null;
final InputStream origContent = request.getContent();
final InputStream toBeClosed = beforeRequest(); // for progress tracking
// make "notCloseable", so reset would work with retries
final InputStream notCloseable = (toBeClosed == null) ? null
: ReleasableInputStream.wrap(toBeClosed).disableClose();
request.setContent(notCloseable);
try {
publishProgress(listener, ProgressEventType.CLIENT_REQUEST_STARTED_EVENT);
response = executeHelper();
publishProgress(listener, ProgressEventType.CLIENT_REQUEST_SUCCESS_EVENT);
awsRequestMetrics.getTimingInfo().endTiming();
afterResponse(response);
return response;
} catch (AmazonClientException e) {
publishProgress(listener, ProgressEventType.CLIENT_REQUEST_FAILED_EVENT);
afterError(response, e);
throw e;
} finally {
// Always close so any progress tracking would get the final events propagated.
closeQuietly(toBeClosed, log);
request.setContent(origContent); // restore the original content
}
}
示例9: reportContentLength
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
/**
* If content length is present on the request, report it to the progress listener.
*
* @param listener Listener to notify.
*/
private void reportContentLength(ProgressListener listener) {
Map<String, String> headers = request.getHeaders();
String contentLengthStr = headers.get("Content-Length");
if (contentLengthStr != null) {
try {
long contentLength = Long.parseLong(contentLengthStr);
publishRequestContentLength(listener, contentLength);
} catch (NumberFormatException e) {
log.warn("Cannot parse the Content-Length header of the request.");
}
}
}
示例10: pauseBeforeRetry
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
/**
* Pause before the next retry and record metrics around retry behavior.
*/
private void pauseBeforeRetry(ExecOneRequestParams execOneParams,
final ProgressListener listener) throws InterruptedException {
publishProgress(listener, ProgressEventType.CLIENT_REQUEST_RETRY_EVENT);
// Notify the progress listener of the retry
awsRequestMetrics.startEvent(Field.RetryPauseTime);
try {
doPauseBeforeRetry(execOneParams);
} finally {
awsRequestMetrics.endEvent(Field.RetryPauseTime);
}
}
示例11: copyBaseTo
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
@Test
public void copyBaseTo() {
final ProgressListener listener = new SyncProgressListener() {
@Override
public void progressChanged(ProgressEvent progressEvent) {
}
};
final AWSCredentials credentials = new BasicAWSCredentials("accesskey",
"accessid");
final RequestMetricCollector collector = new RequestMetricCollector() {
@Override
public void collectMetrics(Request<?> request, Response<?> response) {
}
};
final AmazonWebServiceRequest from = new AmazonWebServiceRequest() {
};
from.setGeneralProgressListener(listener);
from.setRequestCredentials(credentials);
from.setRequestMetricCollector(collector);
from.putCustomRequestHeader("k1", "v1");
from.putCustomRequestHeader("k2", "v2");
from.putCustomQueryParameter("k1", "v1");
from.putCustomQueryParameter("k2", "v2a");
from.putCustomQueryParameter("k2", "v2b");
from.getRequestClientOptions().setReadLimit(1234);
final AmazonWebServiceRequest to = new AmazonWebServiceRequest() {
};
// Before copy
RequestClientOptions toOptions;
verifyBaseBeforeCopy(to);
// After copy
from.copyBaseTo(to);
verifyBaseAfterCopy(listener, credentials, collector, from, to);
}
示例12: verifyBaseBeforeCopy
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
public static void verifyBaseBeforeCopy(final AmazonWebServiceRequest to) {
assertNull(to.getCustomRequestHeaders());
assertNull(to.getCustomQueryParameters());
assertSame(ProgressListener.NOOP, to.getGeneralProgressListener());
assertNull(to.getRequestCredentials());
assertNull(to.getRequestMetricCollector());
assertTrue(RequestClientOptions.DEFAULT_STREAM_BUFFER_SIZE == to
.getReadLimit());
RequestClientOptions toOptions = to.getRequestClientOptions();
assertNull(toOptions.getClientMarker(Marker.USER_AGENT));
assertTrue(RequestClientOptions.DEFAULT_STREAM_BUFFER_SIZE == toOptions
.getReadLimit());
}
示例13: customProgressListenerSetInBaseRequest_IsSetOnAdapter
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
@Test
public void customProgressListenerSetInBaseRequest_IsSetOnAdapter() {
EmptyAmazonWebServiceRequest request = new EmptyAmazonWebServiceRequest();
ProgressListener listener = mock(ProgressListener.class);
request.setGeneralProgressListener(listener);
AmazonWebServiceRequestAdapter adapter = new AmazonWebServiceRequestAdapter(request);
assertEquals(listener, adapter.getProgressListener());
}
示例14: onPersistableTransfer
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
@Override
public void onPersistableTransfer(PersistableTransfer persistableTransfer) {
for (ProgressListener listener : getListeners()) {
if (listener instanceof S3ProgressListener) {
S3ProgressListener s3listener = (S3ProgressListener)listener;
s3listener.onPersistableTransfer(persistableTransfer);
}
}
}
示例15: getProgressListener
import com.amazonaws.event.ProgressListener; //导入依赖的package包/类
/**
* Returns the optional progress listener for receiving updates about object
* upload status.
*
* @return the optional progress listener for receiving updates about object
* upload status.
*
* @deprecated use {@link #getGeneralProgressListener()} instead.
*/
@Deprecated
public com.amazonaws.services.s3.model.ProgressListener getProgressListener() {
ProgressListener generalProgressListener = getGeneralProgressListener();
if (generalProgressListener instanceof LegacyS3ProgressListener) {
return ((LegacyS3ProgressListener)generalProgressListener).unwrap();
} else {
return null;
}
}