本文整理汇总了Java中com.amazonaws.event.ProgressEvent.getEventType方法的典型用法代码示例。如果您正苦于以下问题:Java ProgressEvent.getEventType方法的具体用法?Java ProgressEvent.getEventType怎么用?Java ProgressEvent.getEventType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.event.ProgressEvent
的用法示例。
在下文中一共展示了ProgressEvent.getEventType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public void progressChanged(ProgressEvent progressEvent) {
StringBuilder message = new StringBuilder();
switch (progressEvent.getEventType()) {
case TRANSFER_STARTED_EVENT:
message.append("Starting: ").append(description);
break;
case TRANSFER_COMPLETED_EVENT:
message.append("Completed: ").append(description);
break;
case TRANSFER_FAILED_EVENT:
message.append("Falied: ").append(description);
break;
default:
break;
}
context.setStatus(message.toString());
}
示例2: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
public void progressChanged(ProgressEvent progressEvent) {
if (progress != null) {
progress.progress();
}
// There are 3 http ops here, but this should be close enough for now
ProgressEventType pet = progressEvent.getEventType();
if (pet == TRANSFER_PART_STARTED_EVENT ||
pet == TRANSFER_COMPLETED_EVENT) {
statistics.incrementWriteOps(1);
}
long transferred = upload.getProgress().getBytesTransferred();
long delta = transferred - lastBytesTransferred;
if (statistics != null && delta != 0) {
statistics.incrementBytesWritten(delta);
}
lastBytesTransferred = transferred;
}
示例3: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public void progressChanged(ProgressEvent event)
{
if ( event.getEventType() == ProgressEventType.REQUEST_CONTENT_LENGTH_EVENT )
{
contentLength = event.getBytes();
getLog().info("Content size: " + contentLength + " bytes");
}
else if ( event.getEventType() == ProgressEventType.REQUEST_BYTE_TRANSFER_EVENT )
{
contentSent += event.getBytesTransferred();
double div = (double) (((double)contentSent/(double)contentLength));
double mul = div*(double)100.0;
int mod = (int)mul / 10;
if ( mod > lastTenPct )
{
lastTenPct = mod;
getLog().info("Uploaded " + (mod*10) + "% of " + (contentLength/(1024*1024)) + " MB");
}
}
}
示例4: createProgressListener
import com.amazonaws.event.ProgressEvent; //导入方法依赖的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;
}
}
};
}
示例5: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public void progressChanged(ProgressEvent progressEvent) {
ProgressEventType type = progressEvent.getEventType();
if (type.equals(TRANSFER_COMPLETED_EVENT) || type.equals(TRANSFER_STARTED_EVENT)) {
out.println();
}
if (type.isByteCountEvent()) {
long timeLeft = getTimeLeft();
if (lastTimeLeft < 1 && timeLeft > 0) {
// prime this value with a sane starting point
lastTimeLeft = timeLeft;
}
// use an exponential moving average to smooth the estimate
lastTimeLeft += 0.90 * (timeLeft - lastTimeLeft);
out.print(String.format("\r%1$s %2$s / %3$s %4$s ",
generate(saturatedCast(round(completed + (progress.getPercentTransferred() * multiplier)))),
humanReadableByteCount(progress.getBytesTransferred(), true),
humanReadableByteCount(progress.getTotalBytesToTransfer(), true), fromSeconds(lastTimeLeft)));
out.flush();
}
}
示例6: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public void progressChanged(ProgressEvent progressEvent) {
if (progressEvent.getEventType() == ProgressEventType.REQUEST_CONTENT_LENGTH_EVENT) {
partSize = progressEvent.getBytes();
ArchiveUploadHighLevel.this.log.info("Part size: " + partSize);
}
if (progressEvent.getEventType() == ProgressEventType.CLIENT_REQUEST_SUCCESS_EVENT) {
counter += partSize;
int percentage = (int)(counter * 100.0 / total);
ArchiveUploadHighLevel.this.log.info("Successfully transferred: " + counter + " / " + total + " (" + percentage + "%)");
}
}
示例7: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public void progressChanged(ProgressEvent progressEvent) {
ProgressEventType type = progressEvent.getEventType();
if (type.isByteCountEvent())
return;
if (type != types[count]) {
throw new AssertionError("Expect event type "
+ types[count] + " but got "
+ progressEvent.getEventType());
}
count++;
}
示例8: filter
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public ProgressEvent filter(ProgressEvent progressEvent) {
// Block COMPLETE events from the low-level GetObject operation,
// but we still want to keep the BytesTransferred
return progressEvent.getEventType() == ProgressEventType.TRANSFER_COMPLETED_EVENT
? null // discard this event
: progressEvent
;
}
示例9: copyFile
import com.amazonaws.event.ProgressEvent; //导入方法依赖的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.setSSEAlgorithm(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.getEventType()) {
case TRANSFER_PART_COMPLETED_EVENT:
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");
}
}
示例10: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public void progressChanged(ProgressEvent progressEvent) {
if (progressEvent.getEventType() == ProgressEventType.CLIENT_REQUEST_FAILED_EVENT) {
logger.warn(progressEvent.toString());
}
logger.info(progressEvent.toString());
}
示例11: copyFromLocalFile
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
/**
* The src file is on the local disk. Add it to FS at
* the given dst name.
*
* This version doesn't need to create a temporary file to calculate the md5.
* Sadly this doesn't seem to be used by the shell cp :(
*
* delSrc indicates if the source should be removed
* @param delSrc whether to delete the src
* @param overwrite whether to overwrite an existing file
* @param src path
* @param dst path
*/
@Override
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path src,
Path dst) throws IOException {
String key = pathToKey(dst);
if (!overwrite && exists(dst)) {
throw new IOException(dst + " already exists");
}
if (LOG.isDebugEnabled()) {
LOG.debug("Copying local file from " + src + " to " + dst);
}
// Since we have a local file, we don't need to stream into a temporary file
LocalFileSystem local = getLocal(getConf());
File srcfile = local.pathToFile(src);
final ObjectMetadata om = new ObjectMetadata();
if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
om.setSSEAlgorithm(serverSideEncryptionAlgorithm);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, srcfile);
putObjectRequest.setCannedAcl(cannedACL);
putObjectRequest.setMetadata(om);
ProgressListener progressListener = new ProgressListener() {
public void progressChanged(ProgressEvent progressEvent) {
switch (progressEvent.getEventType()) {
case TRANSFER_PART_COMPLETED_EVENT:
statistics.incrementWriteOps(1);
break;
default:
break;
}
}
};
Upload up = transfers.upload(putObjectRequest);
up.addProgressListener(progressListener);
try {
up.waitForUploadResult();
statistics.incrementWriteOps(1);
} catch (InterruptedException e) {
throw new IOException("Got interrupted, cancelling");
}
// This will delete unnecessary fake parent directories
finishedWrite(key);
if (delSrc) {
local.delete(src, false);
}
}
示例12: downloadParseAndCreateStats
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
private void downloadParseAndCreateStats(AWSCostStatsCreationContext statsData, String awsBucketName) throws IOException {
try {
// Creating a working directory for downloading and processing the bill
final Path workingDirPath = Paths.get(System.getProperty(TEMP_DIR_LOCATION),
UUID.randomUUID().toString());
Files.createDirectories(workingDirPath);
AWSCsvBillParser parser = new AWSCsvBillParser();
final String csvBillZipFileName = parser
.getCsvBillFileName(statsData.billMonthToDownload, statsData.accountId, true);
Path csvBillZipFilePath = Paths.get(workingDirPath.toString(), csvBillZipFileName);
ProgressListener listener = new ProgressListener() {
@Override
public void progressChanged(ProgressEvent progressEvent) {
try {
ProgressEventType eventType = progressEvent.getEventType();
if (ProgressEventType.TRANSFER_COMPLETED_EVENT.equals(eventType)) {
OperationContext.restoreOperationContext(statsData.opContext);
LocalDate billMonth = new LocalDate(
statsData.billMonthToDownload.getYear(),
statsData.billMonthToDownload.getMonthOfYear(), 1);
logWithContext(statsData, Level.INFO, () -> String.format("Processing" +
" bill for the month: %s.", billMonth));
parser.parseDetailedCsvBill(statsData.ignorableInvoiceCharge, csvBillZipFilePath,
statsData.awsAccountIdToComputeStates.keySet(),
getHourlyStatsConsumer(billMonth, statsData),
getMonthlyStatsConsumer(billMonth, statsData));
deleteTempFiles();
// Continue downloading and processing the bills for past and current months' bills
statsData.billMonthToDownload = statsData.billMonthToDownload.plusMonths(1);
handleCostStatsCreationRequest(statsData);
} else if (ProgressEventType.TRANSFER_FAILED_EVENT.equals(eventType)) {
deleteTempFiles();
billDownloadFailureHandler(statsData, awsBucketName, new IOException(
"Download of AWS CSV Bill '" + csvBillZipFileName + "' failed."));
}
} catch (Exception exception) {
deleteTempFiles();
billDownloadFailureHandler(statsData, awsBucketName, exception);
}
}
private void deleteTempFiles() {
try {
Files.deleteIfExists(csvBillZipFilePath);
Files.deleteIfExists(workingDirPath);
} catch (IOException e) {
// Ignore IO exception while cleaning files.
}
}
};
GetObjectRequest getObjectRequest = new GetObjectRequest(awsBucketName,
csvBillZipFileName).withGeneralProgressListener(listener);
statsData.s3Client.download(getObjectRequest, csvBillZipFilePath.toFile());
} catch (AmazonS3Exception s3Exception) {
billDownloadFailureHandler(statsData, awsBucketName, s3Exception);
}
}
示例13: progressChanged
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
@Override
public void progressChanged(ProgressEvent progressEvent) {
switch (progressEvent.getEventType()) {
case CLIENT_REQUEST_FAILED_EVENT:
LOGGER.debug("Failed API request for upload: {}", key);
break;
case CLIENT_REQUEST_RETRY_EVENT:
LOGGER.debug("Retrying API request for upload: {}", key);
break;
case CLIENT_REQUEST_STARTED_EVENT:
LOGGER.trace("Starting API request for upload: {}", key);
break;
case CLIENT_REQUEST_SUCCESS_EVENT:
LOGGER.trace("Finished API request for upload: {}", key);
break;
case TRANSFER_CANCELED_EVENT:
LOGGER.warn("Cancelled upload {}", key);
break;
case TRANSFER_COMPLETED_EVENT:
final long took = System.nanoTime() - start;
uploadTime.update(took, TimeUnit.NANOSECONDS);
successCounter.inc();
LOGGER.info(
"Finished uploading \"{}\" ({} events, {} bytes) in {}ms",
key, count, size, (took / 1000000));
break;
case TRANSFER_FAILED_EVENT:
LOGGER.error("Failed to upload: {}", key);
failedCounter.inc();
break;
case TRANSFER_PART_COMPLETED_EVENT:
LOGGER.trace("Completed part for \"{}\" bytes: {}", key,
progressEvent.getBytes());
break;
case TRANSFER_PART_FAILED_EVENT:
LOGGER.debug("Failed part for \"{}\" bytes: {}", key,
progressEvent.getBytes());
break;
case TRANSFER_PART_STARTED_EVENT:
LOGGER.trace("Started part for \"{}\" bytes: {}", key,
progressEvent.getBytes());
break;
case TRANSFER_PREPARING_EVENT:
LOGGER.debug("Preparing upload \"{}\" total size: {} bytes", key,
size);
break;
case TRANSFER_STARTED_EVENT:
LOGGER.info("Started uploading: {}", key);
break;
case HTTP_REQUEST_COMPLETED_EVENT:
case HTTP_REQUEST_CONTENT_RESET_EVENT:
case HTTP_REQUEST_STARTED_EVENT:
case HTTP_RESPONSE_COMPLETED_EVENT:
case HTTP_RESPONSE_CONTENT_RESET_EVENT:
case HTTP_RESPONSE_STARTED_EVENT:
case REQUEST_BYTE_TRANSFER_EVENT:
case REQUEST_CONTENT_LENGTH_EVENT:
case RESPONSE_BYTE_DISCARD_EVENT:
case RESPONSE_BYTE_TRANSFER_EVENT:
case RESPONSE_CONTENT_LENGTH_EVENT:
default:
LOGGER.trace("Unknown progress event: {}", progressEvent);
break;
}
}
示例14: processReceivedEvent
import com.amazonaws.event.ProgressEvent; //导入方法依赖的package包/类
private void processReceivedEvent(ProgressEvent progressEvent) {
ProgressEventType eventType = progressEvent.getEventType();
long bytesTransferred = progressEvent.getBytesTransferred();
switch(eventType) {
case REQUEST_BYTE_TRANSFER_EVENT:
done += bytesTransferred;
chunk -= bytesTransferred;
if (chunk<=0) {
logger.info(String.format("Sent %s of %s bytes", done, total));
chunk = total / CHUNK;
}
break;
case TRANSFER_COMPLETED_EVENT:
logger.info("Transfer finished");
break;
case TRANSFER_FAILED_EVENT:
logger.error("Transfer failed");
break;
case TRANSFER_STARTED_EVENT:
done = 0;
logger.info("Transfer started");
break;
case REQUEST_CONTENT_LENGTH_EVENT:
total = progressEvent.getBytes();
chunk = total / CHUNK;
logger.info("Length is " + progressEvent.getBytes());
break;
case CLIENT_REQUEST_STARTED_EVENT:
case HTTP_REQUEST_STARTED_EVENT:
case HTTP_REQUEST_COMPLETED_EVENT:
case HTTP_RESPONSE_STARTED_EVENT:
case HTTP_RESPONSE_COMPLETED_EVENT:
case CLIENT_REQUEST_SUCCESS_EVENT:
// no-op
break;
default:
logger.debug("Transfer event " + progressEvent.getEventType() + " transfered bytes was " + bytesTransferred);
break;
}
}