From 23f90a546f137d012e3fdc9046b0d98b388244ce Mon Sep 17 00:00:00 2001 From: dapengzhang0 Date: Thu, 27 Jul 2017 12:15:00 -0700 Subject: [PATCH] rm checking code path --- .../java/io/grpc/internal/ClientCallImpl.java | 49 ++++--------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/ClientCallImpl.java b/core/src/main/java/io/grpc/internal/ClientCallImpl.java index 09f5fef37b06..85d24a121926 100644 --- a/core/src/main/java/io/grpc/internal/ClientCallImpl.java +++ b/core/src/main/java/io/grpc/internal/ClientCallImpl.java @@ -47,11 +47,10 @@ import io.grpc.Status; import java.io.InputStream; import java.util.concurrent.CancellationException; -import java.util.concurrent.Delayed; import java.util.concurrent.Executor; +import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -67,7 +66,7 @@ final class ClientCallImpl extends ClientCall { private final MethodDescriptor method; private final Executor callExecutor; private final Context context; - private volatile ScheduledFuture deadlineCancellationFuture; + private volatile Future deadlineCancellationFuture; private final boolean unaryRequest; private final CallOptions callOptions; private ClientStream stream; @@ -151,26 +150,6 @@ public void start(final Listener observer, Metadata headers) { checkNotNull(observer, "observer"); checkNotNull(headers, "headers"); - if (deadlineCancellationExecutor == null) { - stream = NoopClientStream.INSTANCE; - class ClosedDueToChannelTermination extends ContextRunnable { - ClosedDueToChannelTermination() { - super(context); - } - - @Override - public void runInContext() { - closeObserver( - observer, - Status.UNAVAILABLE.withDescription("Channel is already terminated"), - new Metadata()); - } - } - - callExecutor.execute(new ClosedDueToChannelTermination()); - return; - } - if (context.isCancelled()) { // Context is already cancelled so no need to create a real stream, just notify the observer // of cancellation via callback on the executor @@ -256,7 +235,9 @@ public void runInContext() { context.addListener(cancellationListener, directExecutor()); if (effectiveDeadline != null // If the context has the effective deadline, we don't need to schedule an extra task. - && context.getDeadline() != effectiveDeadline) { + && context.getDeadline() != effectiveDeadline + // If the channel has been terminated, we don't need to schedule an extra task. + && deadlineCancellationExecutor != null) { deadlineCancellationFuture = startDeadlineTimer(effectiveDeadline); } if (cancelListenersShouldBeRemoved) { @@ -308,7 +289,7 @@ private static void logIfContextNarrowedTimeout(long effectiveTimeout, private void removeContextListenerAndCancelDeadlineFuture() { context.removeListener(cancellationListener); - ScheduledFuture f = deadlineCancellationFuture; + Future f = deadlineCancellationFuture; if (f != null) { f.cancel(false); } @@ -330,27 +311,17 @@ public void run() { } } - private ScheduledFuture startDeadlineTimer(final Deadline deadline) { + private Future startDeadlineTimer(final Deadline deadline) { long remainingNanos = deadline.timeRemaining(TimeUnit.NANOSECONDS); try { return deadlineCancellationExecutor .schedule(new LogExceptionRunnable(new DeadlineTimer(remainingNanos)), remainingNanos, TimeUnit.NANOSECONDS); } catch (RejectedExecutionException e) { - class CancelledFuture implements ScheduledFuture { - @Override - public long getDelay(TimeUnit unit) { - return deadline.timeRemaining(unit); - } - - @Override - public int compareTo(Delayed delayed) { - throw new UnsupportedOperationException(); - } - + class CancelledFuture implements Future { @Override public boolean cancel(boolean mayInterruptIfRunning) { - return true; + return false; } @Override @@ -360,7 +331,7 @@ public boolean isCancelled() { @Override public boolean isDone() { - return false; + return true; } @Override