aboutsummaryrefslogtreecommitdiff
path: root/guava/src/com/google/common/util/concurrent/ClosingFuture.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava/src/com/google/common/util/concurrent/ClosingFuture.java')
-rw-r--r--guava/src/com/google/common/util/concurrent/ClosingFuture.java43
1 files changed, 27 insertions, 16 deletions
diff --git a/guava/src/com/google/common/util/concurrent/ClosingFuture.java b/guava/src/com/google/common/util/concurrent/ClosingFuture.java
index 79aa0aa0e..efdf56d8a 100644
--- a/guava/src/com/google/common/util/concurrent/ClosingFuture.java
+++ b/guava/src/com/google/common/util/concurrent/ClosingFuture.java
@@ -58,7 +58,6 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -196,7 +195,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
// TODO(dpb): GWT compatibility.
public final class ClosingFuture<V extends @Nullable Object> {
- private static final Logger logger = Logger.getLogger(ClosingFuture.class.getName());
+ private static final LazyLogger logger = new LazyLogger(ClosingFuture.class);
/**
* An object that can capture objects to be closed later, when a {@link ClosingFuture} pipeline is
@@ -681,7 +680,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
*
* <p>After calling this method, you may not call {@link #finishToFuture()}, {@link
* #finishToValueAndCloser(ValueAndCloserConsumer, Executor)}, or any other derivation method on
- * this {@code ClosingFuture}.
+ * the original {@code ClosingFuture} instance.
*
* @param function transforms the value of this step to the value of the derived step
* @param executor executor to run the function in
@@ -774,7 +773,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
*
* <p>After calling this method, you may not call {@link #finishToFuture()}, {@link
* #finishToValueAndCloser(ValueAndCloserConsumer, Executor)}, or any other derivation method on
- * this {@code ClosingFuture}.
+ * the original {@code ClosingFuture} instance.
*
* @param function transforms the value of this step to a {@code ClosingFuture} with the value of
* the derived step
@@ -865,7 +864,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
*
* <p>After calling this method, you may not call {@link #finishToFuture()}, {@link
* #finishToValueAndCloser(ValueAndCloserConsumer, Executor)}, or any other derivation method on
- * this {@code ClosingFuture}.
+ * the original {@code ClosingFuture} instance.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception
* type is matched against this step's exception. "This step's exception" means the cause of
@@ -958,7 +957,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
*
* <p>After calling this method, you may not call {@link #finishToFuture()}, {@link
* #finishToValueAndCloser(ValueAndCloserConsumer, Executor)}, or any other derivation method on
- * this {@code ClosingFuture}.
+ * the original {@code ClosingFuture} instance.
*
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception
* type is matched against this step's exception. "This step's exception" means the cause of
@@ -1015,13 +1014,13 @@ public final class ClosingFuture<V extends @Nullable Object> {
*
* <p>After calling this method, you may not call {@link
* #finishToValueAndCloser(ValueAndCloserConsumer, Executor)}, this method, or any other
- * derivation method on this {@code ClosingFuture}.
+ * derivation method on the original {@code ClosingFuture} instance.
*
* @return a {@link Future} that represents the final value or exception of the pipeline
*/
public FluentFuture<V> finishToFuture() {
if (compareAndUpdateState(OPEN, WILL_CLOSE)) {
- logger.log(FINER, "will close {0}", this);
+ logger.get().log(FINER, "will close {0}", this);
future.addListener(
new Runnable() {
@Override
@@ -1060,7 +1059,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
* receiver can store the {@link ValueAndCloser} outside the receiver for later synchronous use.
*
* <p>After calling this method, you may not call {@link #finishToFuture()}, this method again, or
- * any other derivation method on this {@code ClosingFuture}.
+ * any other derivation method on the original {@code ClosingFuture} instance.
*
* @param consumer a callback whose method will be called (using {@code executor}) when this
* operation is done
@@ -1121,7 +1120,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
*/
@CanIgnoreReturnValue
public boolean cancel(boolean mayInterruptIfRunning) {
- logger.log(FINER, "cancelling {0}", this);
+ logger.get().log(FINER, "cancelling {0}", this);
boolean cancelled = future.cancel(mayInterruptIfRunning);
if (cancelled) {
close();
@@ -1130,7 +1129,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
}
private void close() {
- logger.log(FINER, "closing {0}", this);
+ logger.get().log(FINER, "closing {0}", this);
closeables.close();
}
@@ -2144,7 +2143,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
@Override
protected void finalize() {
if (state.get().equals(OPEN)) {
- logger.log(SEVERE, "Uh oh! An open ClosingFuture has leaked and will close: {0}", this);
+ logger.get().log(SEVERE, "Uh oh! An open ClosingFuture has leaked and will close: {0}", this);
FluentFuture<V> unused = finishToFuture();
}
}
@@ -2159,14 +2158,26 @@ public final class ClosingFuture<V extends @Nullable Object> {
try {
closeable.close();
} catch (Exception e) {
+ /*
+ * In guava-jre, any kind of Exception may be thrown because `closeable` has type
+ * `AutoCloseable`.
+ *
+ * In guava-android, the only kinds of Exception that may be thrown are
+ * RuntimeException and IOException because `closeable` has type `Closeable`—except
+ * that we have to account for sneaky checked exception.
+ */
restoreInterruptIfIsInterruptedException(e);
- logger.log(WARNING, "thrown by close()", e);
+ logger.get().log(WARNING, "thrown by close()", e);
}
});
} catch (RejectedExecutionException e) {
- if (logger.isLoggable(WARNING)) {
- logger.log(
- WARNING, String.format("while submitting close to %s; will close inline", executor), e);
+ if (logger.get().isLoggable(WARNING)) {
+ logger
+ .get()
+ .log(
+ WARNING,
+ String.format("while submitting close to %s; will close inline", executor),
+ e);
}
closeQuietly(closeable, directExecutor());
}