Skip to content

Commit

Permalink
rm checking code path
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 committed Jul 27, 2017
1 parent 6f09430 commit 23f90a5
Showing 1 changed file with 10 additions and 39 deletions.
49 changes: 10 additions & 39 deletions core/src/main/java/io/grpc/internal/ClientCallImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -67,7 +66,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
private final MethodDescriptor<ReqT, RespT> 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;
Expand Down Expand Up @@ -151,26 +150,6 @@ public void start(final Listener<RespT> 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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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<Void> {
@Override
public long getDelay(TimeUnit unit) {
return deadline.timeRemaining(unit);
}

@Override
public int compareTo(Delayed delayed) {
throw new UnsupportedOperationException();
}

class CancelledFuture implements Future<Void> {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return true;
return false;
}

@Override
Expand All @@ -360,7 +331,7 @@ public boolean isCancelled() {

@Override
public boolean isDone() {
return false;
return true;
}

@Override
Expand Down

0 comments on commit 23f90a5

Please sign in to comment.