com.amazonaws.services.s3.transfer.internal.future.CompositeFuture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-java-sdk-s3 Show documentation
Show all versions of aws-java-sdk-s3 Show documentation
The AWS Java SDK for Amazon S3 module holds the client classes that are used for communicating with Amazon Simple Storage Service
/*
* Copyright 2020-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. 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.future;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* An implementation of {@link Future} that aggregates the results of multiple futures into a single result.
*/
public class CompositeFuture implements Future> {
private final List extends Future> futures;
public CompositeFuture(List extends Future> futures) {
this.futures = futures;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
boolean anyCancelled = false;
for (Future future : futures) {
anyCancelled |= future.cancel(mayInterruptIfRunning);
}
return anyCancelled;
}
@Override
public boolean isCancelled() {
for (Future future : futures) {
if (!future.isCancelled()) {
return false;
}
}
return true;
}
@Override
public boolean isDone() {
for (Future future : futures) {
if (!future.isDone()) {
return false;
}
}
return true;
}
@Override
public List get() throws InterruptedException, ExecutionException {
List results = new ArrayList();
for (Future future : futures) {
results.add(future.get());
}
return results;
}
@Override
public List get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
long doneTime = System.nanoTime() + unit.toNanos(timeout);
List results = new ArrayList();
for (Future future : futures) {
long timeLeft = doneTime - System.nanoTime();
results.add(future.get(timeLeft, TimeUnit.NANOSECONDS));
}
return results;
}
}