47
47
* <p>This class includes settings that are applicable to all server streaming calls, which
48
48
* currently just includes retries and watchdog timers.
49
49
*
50
- * <p>The watchdog timer is configured via {@code idleTimeout}. The watchdog will terminate any
51
- * stream that has not has seen any demand (via {@link StreamController#request(int)}) in the
52
- * configured interval. To turn off idle checks, set the interval to {@link Duration#ZERO}.
50
+ * <p>The watchdog timer is configured via {@code idleTimeout} and {@code waitTimeout}. The watchdog
51
+ * will terminate any stream that has not has seen any demand (via {@link
52
+ * StreamController#request(int)}) in the configured interval or has not seen a message from the
53
+ * server in {@code waitTimeout}. To turn off idle checks, set the interval to {@link
54
+ * Duration#ZERO}.
53
55
*
54
56
* <p>Retry configuration allows for the stream to be restarted and resumed. It is composed of 3
55
57
* parts: the retryable codes, the retry settings and the stream resumption strategy. The retryable
@@ -79,12 +81,14 @@ public final class ServerStreamingCallSettings<RequestT, ResponseT>
79
81
@ Nonnull private final StreamResumptionStrategy <RequestT , ResponseT > resumptionStrategy ;
80
82
81
83
@ Nonnull private final Duration idleTimeout ;
84
+ @ Nonnull private final Duration waitTimeout ;
82
85
83
86
private ServerStreamingCallSettings (Builder <RequestT , ResponseT > builder ) {
84
87
this .retryableCodes = ImmutableSet .copyOf (builder .retryableCodes );
85
88
this .retrySettings = builder .retrySettingsBuilder .build ();
86
89
this .resumptionStrategy = builder .resumptionStrategy ;
87
90
this .idleTimeout = builder .idleTimeout ;
91
+ this .waitTimeout = builder .waitTimeout ;
88
92
}
89
93
90
94
/**
@@ -123,6 +127,15 @@ public Duration getIdleTimeout() {
123
127
return idleTimeout ;
124
128
}
125
129
130
+ /**
131
+ * See the class documentation of {@link ServerStreamingCallSettings} for a description of what
132
+ * the {@link #waitTimeout} does.
133
+ */
134
+ @ Nonnull
135
+ public Duration getWaitTimeout () {
136
+ return waitTimeout ;
137
+ }
138
+
126
139
public Builder <RequestT , ResponseT > toBuilder () {
127
140
return new Builder <>(this );
128
141
}
@@ -135,6 +148,7 @@ public static <RequestT, ResponseT> Builder<RequestT, ResponseT> newBuilder() {
135
148
public String toString () {
136
149
return MoreObjects .toStringHelper (this )
137
150
.add ("idleTimeout" , idleTimeout )
151
+ .add ("waitTimeout" , waitTimeout )
138
152
.add ("retryableCodes" , retryableCodes )
139
153
.add ("retrySettings" , retrySettings )
140
154
.toString ();
@@ -148,13 +162,16 @@ public static class Builder<RequestT, ResponseT>
148
162
149
163
@ Nonnull private Duration idleTimeout ;
150
164
165
+ @ Nonnull private Duration waitTimeout ;
166
+
151
167
/** Initialize the builder with default settings */
152
168
private Builder () {
153
169
this .retryableCodes = ImmutableSet .of ();
154
170
this .retrySettingsBuilder = RetrySettings .newBuilder ();
155
171
this .resumptionStrategy = new SimpleStreamResumptionStrategy <>();
156
172
157
173
this .idleTimeout = Duration .ZERO ;
174
+ this .waitTimeout = Duration .ZERO ;
158
175
}
159
176
160
177
private Builder (ServerStreamingCallSettings <RequestT , ResponseT > settings ) {
@@ -164,6 +181,7 @@ private Builder(ServerStreamingCallSettings<RequestT, ResponseT> settings) {
164
181
this .resumptionStrategy = settings .resumptionStrategy ;
165
182
166
183
this .idleTimeout = settings .idleTimeout ;
184
+ this .waitTimeout = settings .waitTimeout ;
167
185
}
168
186
169
187
/**
@@ -233,9 +251,9 @@ public Builder<RequestT, ResponseT> setSimpleTimeoutNoRetries(@Nonnull Duration
233
251
.setInitialRetryDelay (Duration .ZERO )
234
252
.setRetryDelayMultiplier (1 )
235
253
.setMaxRetryDelay (Duration .ZERO )
236
- .setInitialRpcTimeout (Duration . ZERO )
254
+ .setInitialRpcTimeout (timeout )
237
255
.setRpcTimeoutMultiplier (1 )
238
- .setMaxRpcTimeout (Duration . ZERO )
256
+ .setMaxRpcTimeout (timeout )
239
257
.setMaxAttempts (1 )
240
258
.build ());
241
259
@@ -264,14 +282,27 @@ public Duration getIdleTimeout() {
264
282
}
265
283
266
284
/**
267
- * See the class documentation of {@link ServerStreamingCallSettings} for a description of what
268
- * the {@link #idleTimeout} does. {@link Duration#ZERO} disables the watchdog .
285
+ * Set how long to wait before considering the stream orphaned by the user and closing it.
286
+ * {@link Duration#ZERO} disables the check for abandoned streams .
269
287
*/
270
288
public Builder <RequestT , ResponseT > setIdleTimeout (@ Nonnull Duration idleTimeout ) {
271
289
this .idleTimeout = Preconditions .checkNotNull (idleTimeout );
272
290
return this ;
273
291
}
274
292
293
+ @ Nonnull
294
+ public Duration getWaitTimeout () {
295
+ return waitTimeout ;
296
+ }
297
+
298
+ /**
299
+ * Set the maximum amount of time to wait for the next message from the server. {@link
300
+ * Duration#ZERO} disables the check for abandoned streams.
301
+ */
302
+ public void setWaitTimeout (@ Nonnull Duration waitTimeout ) {
303
+ this .waitTimeout = waitTimeout ;
304
+ }
305
+
275
306
@ Override
276
307
public ServerStreamingCallSettings <RequestT , ResponseT > build () {
277
308
return new ServerStreamingCallSettings <>(this );
0 commit comments