Skip to content

Commit

Permalink
core: not to expose ClientCallImpl#cancelled()
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 authored Jul 19, 2017
1 parent 7e9e5a5 commit 946c29a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/src/main/java/io/grpc/internal/ClientCallImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.grpc.Compressor;
import io.grpc.CompressorRegistry;
import io.grpc.Context;
import io.grpc.Context.CancellationListener;
import io.grpc.Deadline;
import io.grpc.DecompressorRegistry;
import io.grpc.InternalDecompressorRegistry;
Expand All @@ -57,8 +58,7 @@
/**
* Implementation of {@link ClientCall}.
*/
final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT>
implements Context.CancellationListener {
final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {

private static final Logger log = Logger.getLogger(ClientCallImpl.class.getName());

Expand All @@ -73,6 +73,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT>
private boolean cancelCalled;
private boolean halfCloseCalled;
private final ClientTransportProvider clientTransportProvider;
private final CancellationListener cancellationListener = new ContextCancellationListener();
private ScheduledExecutorService deadlineCancellationExecutor;
private DecompressorRegistry decompressorRegistry = DecompressorRegistry.getDefaultInstance();
private CompressorRegistry compressorRegistry = CompressorRegistry.getDefaultInstance();
Expand All @@ -97,9 +98,11 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT>
this.deadlineCancellationExecutor = deadlineCancellationExecutor;
}

@Override
public void cancelled(Context context) {
stream.cancel(statusFromCancelled(context));
private final class ContextCancellationListener implements CancellationListener {
@Override
public void cancelled(Context context) {
stream.cancel(statusFromCancelled(context));
}
}

/**
Expand Down Expand Up @@ -228,7 +231,7 @@ public void runInContext() {
// they receive cancel before start. Issue #1343 has more details

// Propagate later Context cancellation to the remote side.
context.addListener(this, directExecutor());
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
Expand Down Expand Up @@ -284,7 +287,7 @@ private static void logIfContextNarrowedTimeout(long effectiveTimeout,
}

private void removeContextListenerAndCancelDeadlineFuture() {
context.removeListener(this);
context.removeListener(cancellationListener);
ScheduledFuture<?> f = deadlineCancellationFuture;
if (f != null) {
f.cancel(false);
Expand Down

0 comments on commit 946c29a

Please sign in to comment.