• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #266

05 Jun 2024 09:32PM UTC coverage: 77.42% (-0.04%) from 77.459%
#266

push

github

web-flow
Add toString to ServiceStubOptions (#2089)

0 of 33 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

19249 of 24863 relevant lines covered (77.42%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.68
/temporal-serviceclient/src/main/java/io/temporal/serviceclient/WorkflowServiceStubsOptions.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.serviceclient;
22

23
import io.grpc.health.v1.HealthCheckResponse;
24
import io.temporal.serviceclient.rpcretry.DefaultStubServiceOperationRpcRetryOptions;
25
import java.time.Duration;
26
import java.util.*;
27

28
public final class WorkflowServiceStubsOptions extends ServiceStubsOptions {
29
  /**
30
   * RPC timeout used for all long poll calls on Temporal Server side. Long poll returns with an
31
   * empty result after this server timeout.
32
   */
33
  public static final Duration DEFAULT_SERVER_LONG_POLL_RPC_TIMEOUT = Duration.ofSeconds(60);
1✔
34
  /** Default RPC timeout used for all long poll calls. */
35
  public static final Duration DEFAULT_POLL_RPC_TIMEOUT =
1✔
36
      DEFAULT_SERVER_LONG_POLL_RPC_TIMEOUT.plus(Duration.ofSeconds(10));
1✔
37
  /** Default RPC timeout for workflow queries */
38
  public static final Duration DEFAULT_QUERY_RPC_TIMEOUT = Duration.ofSeconds(10);
1✔
39

40
  private static final WorkflowServiceStubsOptions DEFAULT_INSTANCE =
1✔
41
      newBuilder().validateAndBuildWithDefaults();
1✔
42

43
  /**
44
   * Asks client to perform a health check after gRPC connection to the Server is created by making
45
   * a request to endpoint to make sure that the server is accessible.
46
   */
47
  private final boolean disableHealthCheck;
48

49
  /** The gRPC timeout for long poll calls */
50
  private final Duration rpcLongPollTimeout;
51

52
  /** The gRPC timeout for query workflow call */
53
  private final Duration rpcQueryTimeout;
54

55
  /** Retry options for outgoing RPC calls */
56
  private final RpcRetryOptions rpcRetryOptions;
57

58
  public static Builder newBuilder() {
59
    return new Builder();
1✔
60
  }
61

62
  public static Builder newBuilder(ServiceStubsOptions options) {
63
    return new Builder(options);
1✔
64
  }
65

66
  public static WorkflowServiceStubsOptions getDefaultInstance() {
67
    return DEFAULT_INSTANCE;
1✔
68
  }
69

70
  private WorkflowServiceStubsOptions(
71
      ServiceStubsOptions serviceStubsOptions,
72
      boolean disableHealthCheck,
73
      Duration rpcLongPollTimeout,
74
      Duration rpcQueryTimeout,
75
      RpcRetryOptions rpcRetryOptions) {
76
    super(serviceStubsOptions);
1✔
77
    this.disableHealthCheck = disableHealthCheck;
1✔
78
    this.rpcLongPollTimeout = rpcLongPollTimeout;
1✔
79
    this.rpcQueryTimeout = rpcQueryTimeout;
1✔
80
    this.rpcRetryOptions = rpcRetryOptions;
1✔
81
  }
1✔
82

83
  /**
84
   * @return false when client checks endpoint to make sure that the server is accessible.
85
   * @deprecated ServiceStubs don't perform health check on start anymore to allow lazy
86
   *     connectivity. Users that prefer old behavior should explicitly call {@link
87
   *     ServiceStubs#healthCheck()} on client/stubs start and wait until it returns {@link
88
   *     HealthCheckResponse.ServingStatus#SERVING}
89
   */
90
  @Deprecated
91
  public boolean getDisableHealthCheck() {
92
    return disableHealthCheck;
×
93
  }
94

95
  /**
96
   * @return Returns the rpc timout for long poll requests.
97
   */
98
  public Duration getRpcLongPollTimeout() {
99
    return rpcLongPollTimeout;
1✔
100
  }
101

102
  /**
103
   * @return Returns the rpc timout for query workflow requests.
104
   */
105
  public Duration getRpcQueryTimeout() {
106
    return rpcQueryTimeout;
1✔
107
  }
108

109
  /**
110
   * @return Returns rpc retry options for outgoing requests to the temporal server that supposed to
111
   *     be processed and returned fast, like start workflow (not long polls or awaits for workflow
112
   *     finishing).
113
   */
114
  public RpcRetryOptions getRpcRetryOptions() {
115
    return rpcRetryOptions;
1✔
116
  }
117

118
  @Override
119
  public boolean equals(Object o) {
NEW
120
    if (this == o) return true;
×
NEW
121
    if (o == null || getClass() != o.getClass()) return false;
×
NEW
122
    WorkflowServiceStubsOptions that = (WorkflowServiceStubsOptions) o;
×
NEW
123
    return disableHealthCheck == that.disableHealthCheck
×
NEW
124
        && Objects.equals(rpcLongPollTimeout, that.rpcLongPollTimeout)
×
NEW
125
        && Objects.equals(rpcQueryTimeout, that.rpcQueryTimeout)
×
NEW
126
        && Objects.equals(rpcRetryOptions, that.rpcRetryOptions);
×
127
  }
128

129
  @Override
130
  public int hashCode() {
NEW
131
    return Objects.hash(disableHealthCheck, rpcLongPollTimeout, rpcQueryTimeout, rpcRetryOptions);
×
132
  }
133

134
  @Override
135
  public String toString() {
NEW
136
    return "WorkflowServiceStubsOptions{"
×
137
        + "disableHealthCheck="
138
        + disableHealthCheck
139
        + ", rpcLongPollTimeout="
140
        + rpcLongPollTimeout
141
        + ", rpcQueryTimeout="
142
        + rpcQueryTimeout
143
        + ", rpcRetryOptions="
144
        + rpcRetryOptions
145
        + '}';
146
  }
147

148
  /** Builder is the builder for ClientOptions. */
149
  public static class Builder extends ServiceStubsOptions.Builder<Builder> {
150
    private boolean disableHealthCheck = true;
1✔
151
    private Duration rpcLongPollTimeout = DEFAULT_POLL_RPC_TIMEOUT;
1✔
152
    private Duration rpcQueryTimeout = DEFAULT_QUERY_RPC_TIMEOUT;
1✔
153
    private RpcRetryOptions rpcRetryOptions = DefaultStubServiceOperationRpcRetryOptions.INSTANCE;
1✔
154

155
    private Builder() {}
1✔
156

157
    private Builder(ServiceStubsOptions options) {
158
      super(options);
1✔
159
      if (options instanceof WorkflowServiceStubsOptions) {
1✔
160
        WorkflowServiceStubsOptions castedOptions = (WorkflowServiceStubsOptions) options;
1✔
161
        this.rpcLongPollTimeout = castedOptions.rpcLongPollTimeout;
1✔
162
        this.rpcQueryTimeout = castedOptions.rpcQueryTimeout;
1✔
163
        this.rpcRetryOptions = castedOptions.rpcRetryOptions;
1✔
164
      }
165
    }
1✔
166

167
    /**
168
     * If false, enables client to make a request to health check endpoint to make sure that the
169
     * server is accessible.
170
     *
171
     * @deprecated Use more explicit {@link
172
     *     WorkflowServiceStubs#newServiceStubs(WorkflowServiceStubsOptions)} that doesn't perform
173
     *     an explicit connection and health check.
174
     */
175
    @Deprecated
176
    public Builder setDisableHealthCheck(boolean disableHealthCheck) {
177
      this.disableHealthCheck = disableHealthCheck;
×
178
      return this;
×
179
    }
180

181
    /**
182
     * Sets the rpc timeout value for non-query and non-long-poll calls. Default is 10 seconds.
183
     *
184
     * <p>This timeout is applied to only a single rpc server call, not a complete client-server
185
     * interaction. In case of failure, the requests are automatically retried according to {@link
186
     * #setRpcRetryOptions(RpcRetryOptions)}. The full interaction is limited by {@link
187
     * RpcRetryOptions.Builder#setExpiration(Duration)} or {@link
188
     * RpcRetryOptions.Builder#setMaximumAttempts(int)}}, whichever happens first.
189
     *
190
     * <p>For example, let's consider you've called {@code WorkflowClient#start}, and this timeout
191
     * is set to 10s, while {@link RpcRetryOptions.Builder#setExpiration(Duration)} is set to 60s,
192
     * and the server is responding slowly. The first two RPC calls may time out and be retried, but
193
     * if the third one completes fast, the overall {@code WorkflowClient#start} call will
194
     * successfully resolve.
195
     */
196
    @Override
197
    public Builder setRpcTimeout(Duration timeout) {
198
      return super.setRpcTimeout(timeout);
×
199
    }
200

201
    /**
202
     * Sets the rpc timeout value for the following long poll based operations:
203
     * PollWorkflowTaskQueue, PollActivityTaskQueue, GetWorkflowExecutionHistory. Defaults to 70
204
     * seconds.
205
     *
206
     * <p>Server always responds below this timeout. Most users should never modify the default
207
     * value of 70s. The only reasonable reason to modify this timeout it if there is a reversed
208
     * proxy in the network that cuts the gRPC requests really short and there is no way to adjust
209
     * it.
210
     */
211
    public Builder setRpcLongPollTimeout(Duration timeout) {
212
      this.rpcLongPollTimeout = Objects.requireNonNull(timeout);
1✔
213
      return this;
1✔
214
    }
215

216
    /**
217
     * Sets the rpc timeout value for query calls. Default is 10 seconds.
218
     *
219
     * <p>This timeout is applied to only a single rpc server call, not a complete client-server
220
     * interaction. In case of failure, the requests are automatically retried according to {@link
221
     * #setRpcRetryOptions(RpcRetryOptions)}. The full interaction is limited by {@link
222
     * RpcRetryOptions.Builder#setExpiration(Duration)} or {@link
223
     * RpcRetryOptions.Builder#setMaximumAttempts(int)}}, whichever happens first.
224
     *
225
     * <p>For example, let's consider you've called {@code WorkflowStub#query}, and this timeout is
226
     * set to 10s, while {@link RpcRetryOptions.Builder#setExpiration(Duration)} is set to 60s, and
227
     * the server is responding slowly or the query is not getting picked up by the worker for any
228
     * reason. The first two RPC calls may time out and be retried, but if the third one completes
229
     * fast, the overall {@code WorkflowStub#query} call will successfully resolve.
230
     */
231
    public Builder setRpcQueryTimeout(Duration rpcQueryTimeout) {
232
      this.rpcQueryTimeout = rpcQueryTimeout;
1✔
233
      return this;
1✔
234
    }
235

236
    /**
237
     * Allows customization of retry options for the outgoing RPC calls to temporal service.
238
     *
239
     * <p>Note that default values should be reasonable for most users, be cautious when changing
240
     * these values as it may result in increased load to the temporal backend or bad network
241
     * instability tolerance.
242
     *
243
     * <p>Defaults are:
244
     *
245
     * <ul>
246
     *   <li>Retries are limited by the maximum period of 1 minute
247
     *   <li>Initial period between retries: 50ms
248
     *   <li>Exponential Backoff Coefficient (exponential rate) for the retry period is 2
249
     * </ul>
250
     *
251
     * @see <a href="http://backoffcalculator.com">Backoff Calculator</a> to get a grasp on an
252
     *     Exponential Backoff as a retry strategy
253
     * @see #setRpcTimeout(Duration)
254
     * @see #setRpcQueryTimeout(Duration)
255
     */
256
    public Builder setRpcRetryOptions(RpcRetryOptions rpcRetryOptions) {
257
      this.rpcRetryOptions = rpcRetryOptions;
1✔
258
      return this;
1✔
259
    }
260

261
    /**
262
     * Sets the rpc timeout value for query calls. Default is 10 seconds.
263
     *
264
     * @param timeout timeout.
265
     * @deprecated use {{@link #setRpcQueryTimeout(Duration)}}
266
     */
267
    public Builder setQueryRpcTimeout(Duration timeout) {
268
      this.rpcQueryTimeout = Objects.requireNonNull(timeout);
×
269
      return this;
×
270
    }
271

272
    /**
273
     * Builds and returns a ClientOptions object.
274
     *
275
     * @return ClientOptions object with the specified params.
276
     */
277
    public WorkflowServiceStubsOptions build() {
278
      return new WorkflowServiceStubsOptions(
1✔
279
          super.build(),
1✔
280
          this.disableHealthCheck,
281
          this.rpcLongPollTimeout,
282
          this.rpcQueryTimeout,
283
          this.rpcRetryOptions);
284
    }
285

286
    public WorkflowServiceStubsOptions validateAndBuildWithDefaults() {
287
      ServiceStubsOptions serviceStubsOptions = super.validateAndBuildWithDefaults();
1✔
288
      RpcRetryOptions retryOptions =
1✔
289
          RpcRetryOptions.newBuilder(this.rpcRetryOptions).validateBuildWithDefaults();
1✔
290
      return new WorkflowServiceStubsOptions(
1✔
291
          serviceStubsOptions,
292
          this.disableHealthCheck,
293
          this.rpcLongPollTimeout,
294
          this.rpcQueryTimeout,
295
          retryOptions);
296
    }
297
  }
298
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc