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

temporalio / sdk-java / #333

16 Oct 2024 07:28PM UTC coverage: 78.65% (+0.6%) from 78.085%
#333

push

github

web-flow
Fix code coverage (#2275)

22670 of 28824 relevant lines covered (78.65%)

0.79 hits per line

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

88.79
/temporal-sdk/src/main/java/io/temporal/worker/WorkerOptions.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.worker;
22

23
import static java.lang.Double.compare;
24

25
import com.google.common.base.Preconditions;
26
import io.temporal.common.Experimental;
27
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
28
import io.temporal.worker.tuning.*;
29
import java.time.Duration;
30
import java.util.Objects;
31
import javax.annotation.Nonnull;
32
import javax.annotation.Nullable;
33

34
public final class WorkerOptions {
35

36
  public static Builder newBuilder() {
37
    return new Builder();
1✔
38
  }
39

40
  public static Builder newBuilder(WorkerOptions options) {
41
    return new Builder(options);
1✔
42
  }
43

44
  public static WorkerOptions getDefaultInstance() {
45
    return DEFAULT_INSTANCE;
1✔
46
  }
47

48
  static final Duration DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT = Duration.ofSeconds(5);
1✔
49

50
  static final Duration DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT = Duration.ofSeconds(0);
1✔
51

52
  private static final WorkerOptions DEFAULT_INSTANCE;
53

54
  static {
55
    DEFAULT_INSTANCE = WorkerOptions.newBuilder().validateAndBuildWithDefaults();
1✔
56
  }
1✔
57

58
  public static final class Builder {
59

60
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS = 5;
61
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS = 5;
62
    private static final int DEFAULT_MAX_CONCURRENT_NEXUS_TASK_POLLERS = 5;
63
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE = 200;
64
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE = 200;
65
    private static final int DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE = 200;
66
    private static final int DEFAULT_MAX_CONCURRENT_NEXUS_EXECUTION_SIZE = 200;
67
    private static final long DEFAULT_DEADLOCK_DETECTION_TIMEOUT = 1000;
68
    private static final Duration DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL = Duration.ofSeconds(60);
1✔
69
    private static final Duration DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL =
1✔
70
        Duration.ofSeconds(30);
1✔
71

72
    private double maxWorkerActivitiesPerSecond;
73
    private int maxConcurrentActivityExecutionSize;
74
    private int maxConcurrentWorkflowTaskExecutionSize;
75
    private int maxConcurrentLocalActivityExecutionSize;
76
    private int maxConcurrentNexusExecutionSize;
77
    private double maxTaskQueueActivitiesPerSecond;
78
    private int maxConcurrentWorkflowTaskPollers;
79
    private int maxConcurrentActivityTaskPollers;
80
    private int maxConcurrentNexusTaskPollers;
81
    private boolean localActivityWorkerOnly;
82
    private long defaultDeadlockDetectionTimeout;
83
    private Duration maxHeartbeatThrottleInterval;
84
    private Duration defaultHeartbeatThrottleInterval;
85
    private Duration stickyQueueScheduleToStartTimeout;
86
    private boolean disableEagerExecution;
87
    private String buildId;
88
    private boolean useBuildIdForVersioning;
89
    private Duration stickyTaskQueueDrainTimeout;
90
    private WorkerTuner workerTuner;
91
    private String identity;
92

93
    private Builder() {}
94

95
    private Builder(WorkerOptions o) {
1✔
96
      if (o == null) {
1✔
97
        return;
1✔
98
      }
99
      this.maxWorkerActivitiesPerSecond = o.maxWorkerActivitiesPerSecond;
1✔
100
      this.maxConcurrentActivityExecutionSize = o.maxConcurrentActivityExecutionSize;
1✔
101
      this.maxConcurrentWorkflowTaskExecutionSize = o.maxConcurrentWorkflowTaskExecutionSize;
1✔
102
      this.maxConcurrentLocalActivityExecutionSize = o.maxConcurrentLocalActivityExecutionSize;
1✔
103
      this.maxConcurrentNexusExecutionSize = o.maxConcurrentNexusExecutionSize;
1✔
104
      this.workerTuner = o.workerTuner;
1✔
105
      this.maxTaskQueueActivitiesPerSecond = o.maxTaskQueueActivitiesPerSecond;
1✔
106
      this.maxConcurrentWorkflowTaskPollers = o.maxConcurrentWorkflowTaskPollers;
1✔
107
      this.maxConcurrentNexusTaskPollers = o.maxConcurrentNexusTaskPollers;
1✔
108
      this.maxConcurrentActivityTaskPollers = o.maxConcurrentActivityTaskPollers;
1✔
109
      this.localActivityWorkerOnly = o.localActivityWorkerOnly;
1✔
110
      this.defaultDeadlockDetectionTimeout = o.defaultDeadlockDetectionTimeout;
1✔
111
      this.maxHeartbeatThrottleInterval = o.maxHeartbeatThrottleInterval;
1✔
112
      this.defaultHeartbeatThrottleInterval = o.defaultHeartbeatThrottleInterval;
1✔
113
      this.stickyQueueScheduleToStartTimeout = o.stickyQueueScheduleToStartTimeout;
1✔
114
      this.disableEagerExecution = o.disableEagerExecution;
1✔
115
      this.useBuildIdForVersioning = o.useBuildIdForVersioning;
1✔
116
      this.buildId = o.buildId;
1✔
117
      this.stickyTaskQueueDrainTimeout = o.stickyTaskQueueDrainTimeout;
1✔
118
      this.identity = o.identity;
1✔
119
    }
1✔
120

121
    /**
122
     * @param maxWorkerActivitiesPerSecond Maximum number of activities started per second by this
123
     *     worker. Default is 0 which means unlimited.
124
     * @return {@code this}
125
     *     <p>If worker is not fully loaded while tasks are backing up on the service consider
126
     *     increasing {@link #setMaxConcurrentActivityTaskPollers(int)}.
127
     *     <p>Note that this is a per worker limit. Use {@link
128
     *     #setMaxTaskQueueActivitiesPerSecond(double)} to set per task queue limit across multiple
129
     *     workers.
130
     */
131
    public Builder setMaxWorkerActivitiesPerSecond(double maxWorkerActivitiesPerSecond) {
132
      if (maxWorkerActivitiesPerSecond < 0) {
1✔
133
        throw new IllegalArgumentException(
×
134
            "Negative maxWorkerActivitiesPerSecond value: " + maxWorkerActivitiesPerSecond);
135
      }
136
      this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
137
      return this;
1✔
138
    }
139

140
    /**
141
     * @param maxConcurrentActivityExecutionSize Maximum number of activities executed in parallel.
142
     *     Default is 200, which is chosen if set to zero.
143
     * @return {@code this}
144
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
145
     */
146
    public Builder setMaxConcurrentActivityExecutionSize(int maxConcurrentActivityExecutionSize) {
147
      if (maxConcurrentActivityExecutionSize < 0) {
1✔
148
        throw new IllegalArgumentException(
×
149
            "Negative maxConcurrentActivityExecutionSize value: "
150
                + maxConcurrentActivityExecutionSize);
151
      }
152
      this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
153
      return this;
1✔
154
    }
155

156
    /**
157
     * @param maxConcurrentWorkflowTaskExecutionSize Maximum number of simultaneously executed
158
     *     workflow tasks. Default is 200, which is chosen if set to zero.
159
     * @return {@code this}
160
     *     <p>Note that this is not related to the total number of open workflows which do not need
161
     *     to be loaded in a worker when they are not making state transitions.
162
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
163
     */
164
    public Builder setMaxConcurrentWorkflowTaskExecutionSize(
165
        int maxConcurrentWorkflowTaskExecutionSize) {
166
      if (maxConcurrentWorkflowTaskExecutionSize < 0) {
1✔
167
        throw new IllegalArgumentException(
×
168
            "Negative maxConcurrentWorkflowTaskExecutionSize value: "
169
                + maxConcurrentWorkflowTaskExecutionSize);
170
      }
171
      this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
172
      return this;
1✔
173
    }
174

175
    /**
176
     * @param maxConcurrentLocalActivityExecutionSize Maximum number of local activities executed in
177
     *     parallel. Default is 200, which is chosen if set to zero.
178
     * @return {@code this}
179
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
180
     */
181
    public Builder setMaxConcurrentLocalActivityExecutionSize(
182
        int maxConcurrentLocalActivityExecutionSize) {
183
      if (maxConcurrentLocalActivityExecutionSize < 0) {
1✔
184
        throw new IllegalArgumentException(
×
185
            "Negative maxConcurrentLocalActivityExecutionSize value: "
186
                + maxConcurrentLocalActivityExecutionSize);
187
      }
188
      this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
189
      return this;
1✔
190
    }
191

192
    /**
193
     * @param maxConcurrentNexusExecutionSize Maximum number of nexus tasks executed in parallel.
194
     *     Default is 200, which is chosen if set to zero.
195
     * @return {@code this}
196
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
197
     */
198
    @Experimental
199
    public Builder setMaxConcurrentNexusExecutionSize(int maxConcurrentNexusExecutionSize) {
200
      if (maxConcurrentNexusExecutionSize < 0) {
1✔
201
        throw new IllegalArgumentException(
×
202
            "Negative maxConcurrentNexusExecutionSize value: " + maxConcurrentNexusExecutionSize);
203
      }
204
      this.maxConcurrentNexusExecutionSize = maxConcurrentNexusExecutionSize;
1✔
205
      return this;
1✔
206
    }
207

208
    /**
209
     * Optional: Sets the rate limiting on number of activities that can be executed per second.
210
     * This is managed by the server and controls activities per second for the entire task queue
211
     * across all the workers. Notice that the number is represented in double, so that you can set
212
     * it to less than 1 if needed. For example, set the number to 0.1 means you want your activity
213
     * to be executed once every 10 seconds. This can be used to protect down stream services from
214
     * flooding. The zero value of this uses the default value. Default is unlimited.
215
     */
216
    public Builder setMaxTaskQueueActivitiesPerSecond(double maxTaskQueueActivitiesPerSecond) {
217
      this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
218
      return this;
1✔
219
    }
220

221
    /**
222
     * Sets the maximum number of simultaneous long poll requests to the Temporal Server to retrieve
223
     * workflow tasks. Changing this value will affect the rate at which the worker is able to
224
     * consume tasks from a task queue.
225
     *
226
     * <p>Due to internal logic where pollers alternate between sticky and non-sticky queues, this
227
     * value cannot be 1 and will be adjusted to 2 if set to that value.
228
     *
229
     * <p>Default is 5, which is chosen if set to zero.
230
     */
231
    public Builder setMaxConcurrentWorkflowTaskPollers(int maxConcurrentWorkflowTaskPollers) {
232
      this.maxConcurrentWorkflowTaskPollers = maxConcurrentWorkflowTaskPollers;
1✔
233
      return this;
1✔
234
    }
235

236
    /**
237
     * Sets the maximum number of simultaneous long poll requests to the Temporal Server to retrieve
238
     * nexus tasks. Changing this value will affect the rate at which the worker is able to consume
239
     * tasks from a task queue.
240
     *
241
     * <p>Default is 5, which is chosen if set to zero.
242
     */
243
    @Experimental
244
    public Builder setMaxConcurrentNexusTaskPollers(int maxConcurrentNexusTaskPollers) {
245
      this.maxConcurrentNexusTaskPollers = maxConcurrentNexusTaskPollers;
1✔
246
      return this;
1✔
247
    }
248

249
    /**
250
     * Number of simultaneous poll requests on workflow task queue. Note that the majority of the
251
     * workflow tasks will be using host local task queue due to caching. So try incrementing {@link
252
     * WorkerFactoryOptions.Builder#setWorkflowHostLocalPollThreadCount(int)} before this one.
253
     *
254
     * <p>Default is 5, which is chosen if set to zero.
255
     *
256
     * @deprecated Use {@link #setMaxConcurrentWorkflowTaskPollers}
257
     */
258
    @Deprecated
259
    public Builder setWorkflowPollThreadCount(int workflowPollThreadCount) {
260
      return setMaxConcurrentWorkflowTaskPollers(workflowPollThreadCount);
×
261
    }
262

263
    /**
264
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
265
     * worker is not throttled due to `MaxActivitiesPerSecond` or
266
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
267
     *
268
     * <p>Default is 5, which is chosen if set to zero.
269
     */
270
    public Builder setMaxConcurrentActivityTaskPollers(int maxConcurrentActivityTaskPollers) {
271
      this.maxConcurrentActivityTaskPollers = maxConcurrentActivityTaskPollers;
1✔
272
      return this;
1✔
273
    }
274

275
    /**
276
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
277
     * worker is not throttled due to `MaxActivitiesPerSecond` or
278
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
279
     *
280
     * <p>Default is 5, which is chosen if set to zero.
281
     *
282
     * @deprecated Use {@link #setMaxConcurrentActivityTaskPollers}
283
     */
284
    @Deprecated
285
    public Builder setActivityPollThreadCount(int activityPollThreadCount) {
286
      return setMaxConcurrentActivityTaskPollers(activityPollThreadCount);
×
287
    }
288

289
    /**
290
     * If set to true worker would only handle workflow tasks and local activities. Non-local
291
     * activities will not be executed by this worker.
292
     *
293
     * <p>Default is false.
294
     */
295
    public Builder setLocalActivityWorkerOnly(boolean localActivityWorkerOnly) {
296
      this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
297
      return this;
1✔
298
    }
299

300
    /**
301
     * @param defaultDeadlockDetectionTimeoutMs time period in ms that will be used to detect
302
     *     workflows deadlock. Default is 1000ms, which is chosen if set to zero.
303
     *     <p>Specifies an amount of time in milliseconds that workflow tasks are allowed to execute
304
     *     without interruption. If workflow task runs longer than specified interval without
305
     *     yielding (like calling an Activity), it will fail automatically.
306
     * @return {@code this}
307
     * @see io.temporal.internal.sync.PotentialDeadlockException
308
     */
309
    public Builder setDefaultDeadlockDetectionTimeout(long defaultDeadlockDetectionTimeoutMs) {
310
      if (defaultDeadlockDetectionTimeoutMs < 0) {
1✔
311
        throw new IllegalArgumentException(
×
312
            "Negative defaultDeadlockDetectionTimeout value: " + defaultDeadlockDetectionTimeoutMs);
313
      }
314
      this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeoutMs;
1✔
315
      return this;
1✔
316
    }
317

318
    /**
319
     * @param interval the maximum amount of time between sending each pending heartbeat to the
320
     *     server. Regardless of heartbeat timeout, no pending heartbeat will wait longer than this
321
     *     amount of time to send. Default is 60s, which is chosen if set to null or 0.
322
     * @return {@code this}
323
     */
324
    public Builder setMaxHeartbeatThrottleInterval(@Nullable Duration interval) {
325
      Preconditions.checkArgument(
1✔
326
          interval == null || !interval.isNegative(),
1✔
327
          "Negative maxHeartbeatThrottleInterval value: %s",
328
          interval);
329
      this.maxHeartbeatThrottleInterval = interval;
1✔
330
      return this;
1✔
331
    }
332

333
    /**
334
     * @param interval the default amount of time between sending each pending heartbeat to the
335
     *     server. This is used if the ActivityOptions do not provide a HeartbeatTimeout. Otherwise,
336
     *     the interval becomes a value a bit smaller than the given HeartbeatTimeout. Default is
337
     *     30s, which is chosen if set to null or 0.
338
     * @return {@code this}
339
     */
340
    public Builder setDefaultHeartbeatThrottleInterval(@Nullable Duration interval) {
341
      Preconditions.checkArgument(
1✔
342
          interval == null || !interval.isNegative(),
1✔
343
          "Negative defaultHeartbeatThrottleInterval value: %s",
344
          interval);
345
      this.defaultHeartbeatThrottleInterval = interval;
1✔
346
      return this;
1✔
347
    }
348

349
    /**
350
     * Timeout for a workflow task routed to the "sticky worker" - host that has the workflow
351
     * instance cached in memory. Once it times out, then it can be picked up by any worker.
352
     *
353
     * <p>Default value is 5 seconds.
354
     */
355
    public Builder setStickyQueueScheduleToStartTimeout(Duration timeout) {
356
      this.stickyQueueScheduleToStartTimeout = timeout;
1✔
357
      return this;
1✔
358
    }
359

360
    /**
361
     * Disable eager activities. If set to true, eager execution will not be requested for
362
     * activities requested from workflows bound to this Worker.
363
     *
364
     * <p>Eager activity execution means the server returns requested eager activities directly from
365
     * the workflow task back to this worker which is faster than non-eager which may be dispatched
366
     * to a separate worker.
367
     *
368
     * <p>Defaults to false, meaning that eager activity execution is permitted
369
     */
370
    public Builder setDisableEagerExecution(boolean disableEagerExecution) {
371
      this.disableEagerExecution = disableEagerExecution;
1✔
372
      return this;
1✔
373
    }
374

375
    /**
376
     * Opts the worker in to the Build-ID-based versioning feature. This ensures that the worker
377
     * will only receive tasks which it is compatible with. For more information see: TODO: Doc link
378
     *
379
     * <p>Defaults to false
380
     */
381
    @Experimental
382
    public Builder setUseBuildIdForVersioning(boolean useBuildIdForVersioning) {
383
      this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
384
      return this;
1✔
385
    }
386

387
    /**
388
     * Set a unique identifier for this worker. The identifier should be stable with respect to the
389
     * code the worker uses for workflows, activities, and interceptors. For more information see:
390
     * TODO: Doc link
391
     *
392
     * <p>A Build Id must be set if {@link #setUseBuildIdForVersioning(boolean)} is set true.
393
     */
394
    @Experimental
395
    public Builder setBuildId(String buildId) {
396
      this.buildId = buildId;
1✔
397
      return this;
1✔
398
    }
399

400
    /**
401
     * During graceful shutdown, as when calling {@link WorkerFactory#shutdown()}, if the workflow
402
     * cache is enabled, this timeout controls how long to wait for the sticky task queue to drain
403
     * before shutting down the worker. If set the worker will stop making new poll requests on the
404
     * normal task queue, but will continue to poll the sticky task queue until the timeout is
405
     * reached. This value should always be greater than clients rpc long poll timeout, which can be
406
     * set via {@link WorkflowServiceStubsOptions.Builder#setRpcLongPollTimeout(Duration)}.
407
     *
408
     * <p>Default is not to wait.
409
     */
410
    @Experimental
411
    public Builder setStickyTaskQueueDrainTimeout(Duration stickyTaskQueueDrainTimeout) {
412
      this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
413
      return this;
1✔
414
    }
415

416
    /**
417
     * Set a {@link WorkerTuner} to determine how slots will be allocated for different types of
418
     * tasks.
419
     */
420
    @Experimental
421
    public Builder setWorkerTuner(WorkerTuner workerTuner) {
422
      this.workerTuner = workerTuner;
1✔
423
      return this;
1✔
424
    }
425

426
    /** Override identity of the worker primary specified in a WorkflowClient options. */
427
    public Builder setIdentity(String identity) {
428
      this.identity = identity;
1✔
429
      return this;
1✔
430
    }
431

432
    public WorkerOptions build() {
433
      return new WorkerOptions(
1✔
434
          maxWorkerActivitiesPerSecond,
435
          maxConcurrentActivityExecutionSize,
436
          maxConcurrentWorkflowTaskExecutionSize,
437
          maxConcurrentLocalActivityExecutionSize,
438
          maxConcurrentNexusExecutionSize,
439
          workerTuner,
440
          maxTaskQueueActivitiesPerSecond,
441
          maxConcurrentWorkflowTaskPollers,
442
          maxConcurrentActivityTaskPollers,
443
          maxConcurrentNexusTaskPollers,
444
          localActivityWorkerOnly,
445
          defaultDeadlockDetectionTimeout,
446
          maxHeartbeatThrottleInterval,
447
          defaultHeartbeatThrottleInterval,
448
          stickyQueueScheduleToStartTimeout,
449
          disableEagerExecution,
450
          useBuildIdForVersioning,
451
          buildId,
452
          stickyTaskQueueDrainTimeout,
453
          identity);
454
    }
455

456
    public WorkerOptions validateAndBuildWithDefaults() {
457
      Preconditions.checkState(
1✔
458
          maxWorkerActivitiesPerSecond >= 0, "negative maxActivitiesPerSecond");
459
      Preconditions.checkState(
1✔
460
          maxConcurrentActivityExecutionSize >= 0, "negative maxConcurrentActivityExecutionSize");
461
      Preconditions.checkState(
1✔
462
          maxConcurrentWorkflowTaskExecutionSize >= 0,
463
          "negative maxConcurrentWorkflowTaskExecutionSize");
464
      Preconditions.checkState(
1✔
465
          maxConcurrentLocalActivityExecutionSize >= 0,
466
          "negative maxConcurrentLocalActivityExecutionSize");
467
      if (workerTuner != null) {
1✔
468
        Preconditions.checkState(
1✔
469
            maxConcurrentActivityExecutionSize == 0,
470
            "maxConcurrentActivityExecutionSize must not be set if workerTuner is set");
471
      }
472
      if (workerTuner != null) {
1✔
473
        Preconditions.checkState(
1✔
474
            maxConcurrentWorkflowTaskExecutionSize == 0,
475
            "maxConcurrentWorkflowTaskExecutionSize must not be set if workerTuner is set");
476
      }
477
      if (workerTuner != null) {
1✔
478
        Preconditions.checkState(
1✔
479
            maxConcurrentLocalActivityExecutionSize == 0,
480
            "maxConcurrentLocalActivityExecutionSize must not be set if workerTuner is set");
481
      }
482
      Preconditions.checkState(
1✔
483
          maxTaskQueueActivitiesPerSecond >= 0, "negative taskQueueActivitiesPerSecond");
484
      Preconditions.checkState(
1✔
485
          maxConcurrentWorkflowTaskPollers >= 0, "negative maxConcurrentWorkflowTaskPollers");
486
      Preconditions.checkState(
1✔
487
          maxConcurrentActivityTaskPollers >= 0, "negative maxConcurrentActivityTaskPollers");
488
      Preconditions.checkState(
1✔
489
          defaultDeadlockDetectionTimeout >= 0, "negative defaultDeadlockDetectionTimeout");
490
      Preconditions.checkState(
1✔
491
          stickyQueueScheduleToStartTimeout == null
492
              || !stickyQueueScheduleToStartTimeout.isNegative(),
1✔
493
          "negative stickyQueueScheduleToStartTimeout");
494
      if (useBuildIdForVersioning) {
1✔
495
        Preconditions.checkState(
1✔
496
            buildId != null && !buildId.isEmpty(),
1✔
497
            "buildId must be set non-empty if useBuildIdForVersioning is set true");
498
      }
499
      Preconditions.checkState(
1✔
500
          stickyTaskQueueDrainTimeout == null || !stickyTaskQueueDrainTimeout.isNegative(),
1✔
501
          "negative stickyTaskQueueDrainTimeout");
502
      Preconditions.checkState(
1✔
503
          maxConcurrentNexusTaskPollers >= 0, "negative maxConcurrentNexusTaskPollers");
504

505
      return new WorkerOptions(
1✔
506
          maxWorkerActivitiesPerSecond,
507
          maxConcurrentActivityExecutionSize == 0
1✔
508
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE
1✔
509
              : maxConcurrentActivityExecutionSize,
1✔
510
          maxConcurrentWorkflowTaskExecutionSize == 0
1✔
511
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE
1✔
512
              : maxConcurrentWorkflowTaskExecutionSize,
1✔
513
          maxConcurrentLocalActivityExecutionSize == 0
1✔
514
              ? DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE
1✔
515
              : maxConcurrentLocalActivityExecutionSize,
1✔
516
          maxConcurrentNexusExecutionSize == 0
1✔
517
              ? DEFAULT_MAX_CONCURRENT_NEXUS_EXECUTION_SIZE
1✔
518
              : maxConcurrentNexusExecutionSize,
1✔
519
          workerTuner,
520
          maxTaskQueueActivitiesPerSecond,
521
          maxConcurrentWorkflowTaskPollers == 0
1✔
522
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS
1✔
523
              : maxConcurrentWorkflowTaskPollers,
1✔
524
          maxConcurrentActivityTaskPollers == 0
1✔
525
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS
1✔
526
              : maxConcurrentActivityTaskPollers,
1✔
527
          maxConcurrentNexusTaskPollers == 0
1✔
528
              ? DEFAULT_MAX_CONCURRENT_NEXUS_TASK_POLLERS
1✔
529
              : maxConcurrentNexusTaskPollers,
1✔
530
          localActivityWorkerOnly,
531
          defaultDeadlockDetectionTimeout == 0
1✔
532
              ? DEFAULT_DEADLOCK_DETECTION_TIMEOUT
1✔
533
              : defaultDeadlockDetectionTimeout,
1✔
534
          maxHeartbeatThrottleInterval == null || maxHeartbeatThrottleInterval.isZero()
1✔
535
              ? DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL
1✔
536
              : maxHeartbeatThrottleInterval,
1✔
537
          defaultHeartbeatThrottleInterval == null || defaultHeartbeatThrottleInterval.isZero()
1✔
538
              ? DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL
1✔
539
              : defaultHeartbeatThrottleInterval,
1✔
540
          stickyQueueScheduleToStartTimeout == null
1✔
541
              ? DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT
1✔
542
              : stickyQueueScheduleToStartTimeout,
1✔
543
          disableEagerExecution,
544
          useBuildIdForVersioning,
545
          buildId,
546
          stickyTaskQueueDrainTimeout == null
1✔
547
              ? DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT
1✔
548
              : stickyTaskQueueDrainTimeout,
1✔
549
          identity);
550
    }
551
  }
552

553
  private final double maxWorkerActivitiesPerSecond;
554
  private final int maxConcurrentActivityExecutionSize;
555
  private final int maxConcurrentWorkflowTaskExecutionSize;
556
  private final int maxConcurrentLocalActivityExecutionSize;
557
  private final int maxConcurrentNexusExecutionSize;
558
  private final WorkerTuner workerTuner;
559
  private final double maxTaskQueueActivitiesPerSecond;
560
  private final int maxConcurrentWorkflowTaskPollers;
561
  private final int maxConcurrentActivityTaskPollers;
562
  private final int maxConcurrentNexusTaskPollers;
563
  private final boolean localActivityWorkerOnly;
564
  private final long defaultDeadlockDetectionTimeout;
565
  private final Duration maxHeartbeatThrottleInterval;
566
  private final Duration defaultHeartbeatThrottleInterval;
567
  private final @Nonnull Duration stickyQueueScheduleToStartTimeout;
568
  private final boolean disableEagerExecution;
569
  private final boolean useBuildIdForVersioning;
570
  private final String buildId;
571
  private final Duration stickyTaskQueueDrainTimeout;
572
  private final String identity;
573

574
  private WorkerOptions(
575
      double maxWorkerActivitiesPerSecond,
576
      int maxConcurrentActivityExecutionSize,
577
      int maxConcurrentWorkflowTaskExecutionSize,
578
      int maxConcurrentLocalActivityExecutionSize,
579
      int maxConcurrentNexusExecutionSize,
580
      WorkerTuner workerTuner,
581
      double maxTaskQueueActivitiesPerSecond,
582
      int workflowPollThreadCount,
583
      int activityPollThreadCount,
584
      int nexusPollThreadCount,
585
      boolean localActivityWorkerOnly,
586
      long defaultDeadlockDetectionTimeout,
587
      Duration maxHeartbeatThrottleInterval,
588
      Duration defaultHeartbeatThrottleInterval,
589
      @Nonnull Duration stickyQueueScheduleToStartTimeout,
590
      boolean disableEagerExecution,
591
      boolean useBuildIdForVersioning,
592
      String buildId,
593
      Duration stickyTaskQueueDrainTimeout,
594
      String identity) {
1✔
595
    this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
596
    this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
597
    this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
598
    this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
599
    this.maxConcurrentNexusExecutionSize = maxConcurrentNexusExecutionSize;
1✔
600
    this.workerTuner = workerTuner;
1✔
601
    this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
602
    this.maxConcurrentWorkflowTaskPollers = workflowPollThreadCount;
1✔
603
    this.maxConcurrentActivityTaskPollers = activityPollThreadCount;
1✔
604
    this.maxConcurrentNexusTaskPollers = nexusPollThreadCount;
1✔
605
    this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
606
    this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeout;
1✔
607
    this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
1✔
608
    this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
1✔
609
    this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
1✔
610
    this.disableEagerExecution = disableEagerExecution;
1✔
611
    this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
612
    this.buildId = buildId;
1✔
613
    this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
614
    this.identity = identity;
1✔
615
  }
1✔
616

617
  public double getMaxWorkerActivitiesPerSecond() {
618
    return maxWorkerActivitiesPerSecond;
1✔
619
  }
620

621
  public int getMaxConcurrentActivityExecutionSize() {
622
    return maxConcurrentActivityExecutionSize;
1✔
623
  }
624

625
  public int getMaxConcurrentWorkflowTaskExecutionSize() {
626
    return maxConcurrentWorkflowTaskExecutionSize;
1✔
627
  }
628

629
  public int getMaxConcurrentLocalActivityExecutionSize() {
630
    return maxConcurrentLocalActivityExecutionSize;
1✔
631
  }
632

633
  public int getMaxConcurrentNexusExecutionSize() {
634
    return maxConcurrentNexusExecutionSize;
1✔
635
  }
636

637
  public double getMaxTaskQueueActivitiesPerSecond() {
638
    return maxTaskQueueActivitiesPerSecond;
1✔
639
  }
640

641
  /**
642
   * @deprecated use {@link #getMaxConcurrentWorkflowTaskPollers}
643
   */
644
  @Deprecated
645
  public int getWorkflowPollThreadCount() {
646
    return getMaxConcurrentWorkflowTaskPollers();
×
647
  }
648

649
  public int getMaxConcurrentWorkflowTaskPollers() {
650
    return maxConcurrentWorkflowTaskPollers;
1✔
651
  }
652

653
  /**
654
   * @deprecated use {@link #getMaxConcurrentActivityTaskPollers}
655
   */
656
  @Deprecated
657
  public int getActivityPollThreadCount() {
658
    return getMaxConcurrentActivityTaskPollers();
×
659
  }
660

661
  public int getMaxConcurrentActivityTaskPollers() {
662
    return maxConcurrentActivityTaskPollers;
1✔
663
  }
664

665
  public int getMaxConcurrentNexusTaskPollers() {
666
    return maxConcurrentNexusTaskPollers;
1✔
667
  }
668

669
  public long getDefaultDeadlockDetectionTimeout() {
670
    return defaultDeadlockDetectionTimeout;
1✔
671
  }
672

673
  public boolean isLocalActivityWorkerOnly() {
674
    return localActivityWorkerOnly;
1✔
675
  }
676

677
  public Duration getMaxHeartbeatThrottleInterval() {
678
    return maxHeartbeatThrottleInterval;
1✔
679
  }
680

681
  public Duration getDefaultHeartbeatThrottleInterval() {
682
    return defaultHeartbeatThrottleInterval;
1✔
683
  }
684

685
  @Nonnull
686
  public Duration getStickyQueueScheduleToStartTimeout() {
687
    return stickyQueueScheduleToStartTimeout;
1✔
688
  }
689

690
  public boolean isEagerExecutionDisabled() {
691
    return disableEagerExecution;
1✔
692
  }
693

694
  public boolean isUsingBuildIdForVersioning() {
695
    return useBuildIdForVersioning;
1✔
696
  }
697

698
  public String getBuildId() {
699
    return buildId;
1✔
700
  }
701

702
  public Duration getStickyTaskQueueDrainTimeout() {
703
    return stickyTaskQueueDrainTimeout;
1✔
704
  }
705

706
  public WorkerTuner getWorkerTuner() {
707
    return workerTuner;
1✔
708
  }
709

710
  @Nullable
711
  public String getIdentity() {
712
    return identity;
1✔
713
  }
714

715
  @Override
716
  public boolean equals(Object o) {
717
    if (this == o) return true;
1✔
718
    if (o == null || getClass() != o.getClass()) return false;
1✔
719
    WorkerOptions that = (WorkerOptions) o;
1✔
720
    return compare(maxWorkerActivitiesPerSecond, that.maxWorkerActivitiesPerSecond) == 0
1✔
721
        && maxConcurrentActivityExecutionSize == that.maxConcurrentActivityExecutionSize
722
        && maxConcurrentWorkflowTaskExecutionSize == that.maxConcurrentWorkflowTaskExecutionSize
723
        && maxConcurrentLocalActivityExecutionSize == that.maxConcurrentLocalActivityExecutionSize
724
        && maxConcurrentNexusExecutionSize == that.maxConcurrentNexusExecutionSize
725
        && compare(maxTaskQueueActivitiesPerSecond, that.maxTaskQueueActivitiesPerSecond) == 0
1✔
726
        && maxConcurrentWorkflowTaskPollers == that.maxConcurrentWorkflowTaskPollers
727
        && maxConcurrentActivityTaskPollers == that.maxConcurrentActivityTaskPollers
728
        && maxConcurrentNexusTaskPollers == that.maxConcurrentNexusTaskPollers
729
        && localActivityWorkerOnly == that.localActivityWorkerOnly
730
        && defaultDeadlockDetectionTimeout == that.defaultDeadlockDetectionTimeout
731
        && disableEagerExecution == that.disableEagerExecution
732
        && useBuildIdForVersioning == that.useBuildIdForVersioning
733
        && Objects.equals(workerTuner, that.workerTuner)
1✔
734
        && Objects.equals(maxHeartbeatThrottleInterval, that.maxHeartbeatThrottleInterval)
1✔
735
        && Objects.equals(defaultHeartbeatThrottleInterval, that.defaultHeartbeatThrottleInterval)
1✔
736
        && Objects.equals(stickyQueueScheduleToStartTimeout, that.stickyQueueScheduleToStartTimeout)
1✔
737
        && Objects.equals(buildId, that.buildId)
1✔
738
        && Objects.equals(stickyTaskQueueDrainTimeout, that.stickyTaskQueueDrainTimeout)
1✔
739
        && Objects.equals(identity, that.identity);
1✔
740
  }
741

742
  @Override
743
  public int hashCode() {
744
    return Objects.hash(
×
745
        maxWorkerActivitiesPerSecond,
×
746
        maxConcurrentActivityExecutionSize,
×
747
        maxConcurrentWorkflowTaskExecutionSize,
×
748
        maxConcurrentLocalActivityExecutionSize,
×
749
        maxConcurrentNexusExecutionSize,
×
750
        workerTuner,
751
        maxTaskQueueActivitiesPerSecond,
×
752
        maxConcurrentWorkflowTaskPollers,
×
753
        maxConcurrentActivityTaskPollers,
×
754
        maxConcurrentNexusTaskPollers,
×
755
        localActivityWorkerOnly,
×
756
        defaultDeadlockDetectionTimeout,
×
757
        maxHeartbeatThrottleInterval,
758
        defaultHeartbeatThrottleInterval,
759
        stickyQueueScheduleToStartTimeout,
760
        disableEagerExecution,
×
761
        useBuildIdForVersioning,
×
762
        buildId,
763
        stickyTaskQueueDrainTimeout,
764
        identity);
765
  }
766

767
  @Override
768
  public String toString() {
769
    return "WorkerOptions{"
×
770
        + "maxWorkerActivitiesPerSecond="
771
        + maxWorkerActivitiesPerSecond
772
        + ", maxConcurrentActivityExecutionSize="
773
        + maxConcurrentActivityExecutionSize
774
        + ", maxConcurrentWorkflowTaskExecutionSize="
775
        + maxConcurrentWorkflowTaskExecutionSize
776
        + ", maxConcurrentLocalActivityExecutionSize="
777
        + maxConcurrentLocalActivityExecutionSize
778
        + ", maxConcurrentNexusExecutionSize="
779
        + maxConcurrentNexusExecutionSize
780
        + ", workerTuner="
781
        + workerTuner
782
        + ", maxTaskQueueActivitiesPerSecond="
783
        + maxTaskQueueActivitiesPerSecond
784
        + ", maxConcurrentWorkflowTaskPollers="
785
        + maxConcurrentWorkflowTaskPollers
786
        + ", maxConcurrentActivityTaskPollers="
787
        + maxConcurrentActivityTaskPollers
788
        + ", maxConcurrentNexusTaskPollers="
789
        + maxConcurrentNexusTaskPollers
790
        + ", localActivityWorkerOnly="
791
        + localActivityWorkerOnly
792
        + ", defaultDeadlockDetectionTimeout="
793
        + defaultDeadlockDetectionTimeout
794
        + ", maxHeartbeatThrottleInterval="
795
        + maxHeartbeatThrottleInterval
796
        + ", defaultHeartbeatThrottleInterval="
797
        + defaultHeartbeatThrottleInterval
798
        + ", stickyQueueScheduleToStartTimeout="
799
        + stickyQueueScheduleToStartTimeout
800
        + ", disableEagerExecution="
801
        + disableEagerExecution
802
        + ", useBuildIdForVersioning="
803
        + useBuildIdForVersioning
804
        + ", buildId='"
805
        + buildId
806
        + '\''
807
        + ", stickyTaskQueueDrainTimeout="
808
        + stickyTaskQueueDrainTimeout
809
        + ", identity="
810
        + identity
811
        + '}';
812
  }
813
}
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