Skip to content

Commit e6f7219

Browse files
committed
chore: Use HttpJsonClientCallImpl in main branch
1 parent 7f04a7f commit e6f7219

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonClientCallImpl.java

+9-27
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.concurrent.CancellationException;
4747
import java.util.concurrent.Executor;
4848
import java.util.concurrent.ScheduledExecutorService;
49-
import java.util.concurrent.ScheduledFuture;
5049
import java.util.concurrent.TimeUnit;
5150
import javax.annotation.Nullable;
5251

@@ -122,11 +121,6 @@ final class HttpJsonClientCallImpl<RequestT, ResponseT>
122121
@GuardedBy("lock")
123122
private volatile boolean closed;
124123

125-
// Store the timeout future created by the deadline schedule executor. The future
126-
// can be cancelled if a response has been received before the timeout.
127-
@GuardedBy("lock")
128-
private ScheduledFuture<?> timeoutFuture;
129-
130124
HttpJsonClientCallImpl(
131125
ApiMethodDescriptor<RequestT, ResponseT> methodDescriptor,
132126
String endpoint,
@@ -173,20 +167,16 @@ public void start(Listener<ResponseT> responseListener, HttpJsonMetadata request
173167
Preconditions.checkState(this.listener == null, "The call is already started");
174168
this.listener = responseListener;
175169
this.requestHeaders = requestHeaders;
170+
}
176171

177-
// Use the timeout duration value instead of calculating the future Instant
178-
// Only schedule the deadline if the RPC timeout has been set in the RetrySettings
179-
Duration timeout = callOptions.getTimeout();
180-
if (timeout != null) {
181-
// The future timeout value is guaranteed to not be a negative value as the
182-
// RetryAlgorithm will not retry
183-
long timeoutMs = timeout.toMillis();
184-
// Assign the scheduled future so that it can be cancelled if the timeout task
185-
// is not needed (response received prior to timeout)
186-
timeoutFuture =
187-
this.deadlineCancellationExecutor.schedule(
188-
this::timeout, timeoutMs, TimeUnit.MILLISECONDS);
189-
}
172+
// Use the timeout duration value instead of calculating the future Instant
173+
// Only schedule the deadline if the RPC timeout has been set in the RetrySettings
174+
Duration timeout = callOptions.getTimeout();
175+
if (timeout != null) {
176+
// The future timeout value is guaranteed to not be a negative value as the
177+
// RetryAlgorithm will not retry
178+
long timeoutMs = timeout.toMillis();
179+
this.deadlineCancellationExecutor.schedule(this::timeout, timeoutMs, TimeUnit.MILLISECONDS);
190180
}
191181
}
192182

@@ -440,14 +430,6 @@ private void close(
440430
return;
441431
}
442432
closed = true;
443-
444-
// Cancel the timeout future if there is a timeout task created
445-
if (timeoutFuture != null) {
446-
// timeout() invokes close(), but cancelling a completed task should no-op
447-
timeoutFuture.cancel(true);
448-
timeoutFuture = null;
449-
}
450-
451433
// Best effort task cancellation (to not be confused with task's thread interruption).
452434
// If the task is in blocking I/O waiting for the server response, it will keep waiting for
453435
// the response from the server, but once response is received the task will exit silently.

0 commit comments

Comments
 (0)