MCPcopy Index your code
hub / github.com/grpc/grpc-java / RetriableStream

Class RetriableStream

core/src/main/java/io/grpc/internal/RetriableStream.java:55–1618  ·  view source on GitHub ↗

A logical ClientStream that is retriable.

Source from the content-addressed store, hash-verified

53
54/** A logical {@link ClientStream} that is retriable. */
55abstract class RetriableStream<ReqT> implements ClientStream {
56 @VisibleForTesting
57 static final Metadata.Key<String> GRPC_PREVIOUS_RPC_ATTEMPTS =
58 Metadata.Key.of("grpc-previous-rpc-attempts", Metadata.ASCII_STRING_MARSHALLER);
59
60 @VisibleForTesting
61 static final Metadata.Key<String> GRPC_RETRY_PUSHBACK_MS =
62 Metadata.Key.of("grpc-retry-pushback-ms", Metadata.ASCII_STRING_MARSHALLER);
63
64 private static final Status CANCELLED_BECAUSE_COMMITTED =
65 Status.CANCELLED.withDescription("Stream thrown away because RetriableStream committed");
66
67 private final MethodDescriptor<ReqT, ?> method;
68 private final Executor callExecutor;
69 private final Executor listenerSerializeExecutor = new SynchronizationContext(
70 new UncaughtExceptionHandler() {
71 @Override
72 public void uncaughtException(Thread t, Throwable e) {
73 throw Status.fromThrowable(e)
74 .withDescription("Uncaught exception in the SynchronizationContext. Re-thrown.")
75 .asRuntimeException();
76 }
77 }
78 );
79 private final ScheduledExecutorService scheduledExecutorService;
80 // Must not modify it.
81 private final Metadata headers;
82 @Nullable
83 private final RetryPolicy retryPolicy;
84 @Nullable
85 private final HedgingPolicy hedgingPolicy;
86 private final boolean isHedging;
87
88 /** Must be held when updating state, accessing state.buffer, or certain substream attributes. */
89 private final Object lock = new Object();
90
91 private final ChannelBufferMeter channelBufferUsed;
92 private final long perRpcBufferLimit;
93 private final long channelBufferLimit;
94 @Nullable
95 private final Throttle throttle;
96 @GuardedBy("lock")
97 private final InsightBuilder closedSubstreamsInsight = new InsightBuilder();
98
99 private volatile State state = new State(
100 new ArrayList<BufferEntry>(8), Collections.<Substream>emptyList(), null, null, false, false,
101 false, 0);
102
103 /**
104 * Either non-local transparent retry happened or reached server's application logic.
105 *
106 * <p>Note that local-only transparent retries are unlimited.
107 */
108 private final AtomicBoolean noMoreTransparentRetry = new AtomicBoolean();
109 private final AtomicInteger localOnlyTransparentRetries = new AtomicInteger();
110 private final AtomicInteger inFlightSubStreams = new AtomicInteger();
111 private SavedCloseMasterListenerReason savedCloseMasterListenerReason;
112

Callers

nothing calls this directly

Calls 4

getFlagMethod · 0.95
withDescriptionMethod · 0.80
emptyListMethod · 0.80
ofMethod · 0.45

Tested by

no test coverage detected