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

Class DelayedStream

core/src/main/java/io/grpc/internal/DelayedStream.java:44–551  ·  view source on GitHub ↗

A stream that queues requests before the transport is available, and delegates to a real stream implementation when the transport is available. ClientStream itself doesn't require thread-safety. However, the state of DelayedStream may be internally altered by different threads, t

Source from the content-addressed store, hash-verified

42 * necessary.
43 */
44class DelayedStream implements ClientStream {
45 private final String bufferContext;
46 /** {@code true} once realStream is valid and all pending calls have been drained. */
47 private volatile boolean passThrough;
48 /**
49 * Non-{@code null} iff start has been called. Used to assert methods are called in appropriate
50 * order, but also used if an error occurs before {@code realStream} is set.
51 */
52 private ClientStreamListener listener;
53 /** Must hold {@code this} lock when setting. */
54 private ClientStream realStream;
55 @GuardedBy("this")
56 private Status error;
57 @GuardedBy("this")
58 private List<Runnable> pendingCalls = new ArrayList<>();
59 @GuardedBy("this")
60 private DelayedStreamListener delayedListener;
61 @GuardedBy("this")
62 private long startTimeNanos;
63 @GuardedBy("this")
64 private long streamSetTimeNanos;
65 // No need to synchronize; start() synchronization provides a happens-before
66 private List<Runnable> preStartPendingCalls = new ArrayList<>();
67
68 /**
69 * Create a delayed stream with debug context {@code bufferContext}. The context is what this
70 * stream is delayed by (e.g., "connecting", "call_credentials").
71 */
72 public DelayedStream(String bufferContext) {
73 this.bufferContext = checkNotNull(bufferContext, "bufferContext");
74 }
75
76 @Override
77 public void setMaxInboundMessageSize(final int maxSize) {
78 checkState(listener == null, "May only be called before start");
79 preStartPendingCalls.add(new Runnable() {
80 @Override
81 public void run() {
82 realStream.setMaxInboundMessageSize(maxSize);
83 }
84 });
85 }
86
87 @Override
88 public void setMaxOutboundMessageSize(final int maxSize) {
89 checkState(listener == null, "May only be called before start");
90 preStartPendingCalls.add(new Runnable() {
91 @Override
92 public void run() {
93 realStream.setMaxOutboundMessageSize(maxSize);
94 }
95 });
96 }
97
98 @Override
99 public void setDeadline(final Deadline deadline) {
100 checkState(listener == null, "May only be called before start");
101 preStartPendingCalls.add(new Runnable() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected