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

temporalio / sdk-java / #256

29 May 2024 06:28PM UTC coverage: 77.463% (+0.02%) from 77.448%
#256

push

github

web-flow
Add identity to WorkflowOptions (#2080)

Provides the ability to override identity specified in a WorkflowClient

9 of 12 new or added lines in 2 files covered. (75.0%)

6 existing lines in 2 files now uncovered.

19190 of 24773 relevant lines covered (77.46%)

0.77 hits per line

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

79.81
/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_WORKFLOW_TASK_EXECUTION_SIZE = 200;
63
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE = 200;
64
    private static final int DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE = 200;
65
    private static final long DEFAULT_DEADLOCK_DETECTION_TIMEOUT = 1000;
66
    private static final Duration DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL = Duration.ofSeconds(60);
1✔
67
    private static final Duration DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL =
1✔
68
        Duration.ofSeconds(30);
1✔
69

70
    private double maxWorkerActivitiesPerSecond;
71
    private int maxConcurrentActivityExecutionSize;
72
    private int maxConcurrentWorkflowTaskExecutionSize;
73
    private int maxConcurrentLocalActivityExecutionSize;
74
    private double maxTaskQueueActivitiesPerSecond;
75
    private int maxConcurrentWorkflowTaskPollers;
76
    private int maxConcurrentActivityTaskPollers;
77
    private boolean localActivityWorkerOnly;
78
    private long defaultDeadlockDetectionTimeout;
79
    private Duration maxHeartbeatThrottleInterval;
80
    private Duration defaultHeartbeatThrottleInterval;
81
    private Duration stickyQueueScheduleToStartTimeout;
82
    private boolean disableEagerExecution;
83
    private String buildId;
84
    private boolean useBuildIdForVersioning;
85
    private Duration stickyTaskQueueDrainTimeout;
86
    private SlotSupplier<WorkflowSlotInfo> workflowSlotSupplier;
87
    private SlotSupplier<ActivitySlotInfo> activitySlotSupplier;
88
    private SlotSupplier<LocalActivitySlotInfo> localActivitySlotSupplier;
89
    private String identity;
90

91
    private Builder() {}
92

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

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

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

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

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

191
    /**
192
     * Optional: Sets the rate limiting on number of activities that can be executed per second.
193
     * This is managed by the server and controls activities per second for the entire task queue
194
     * across all the workers. Notice that the number is represented in double, so that you can set
195
     * it to less than 1 if needed. For example, set the number to 0.1 means you want your activity
196
     * to be executed once every 10 seconds. This can be used to protect down stream services from
197
     * flooding. The zero value of this uses the default value. Default is unlimited.
198
     */
199
    public Builder setMaxTaskQueueActivitiesPerSecond(double maxTaskQueueActivitiesPerSecond) {
200
      this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
201
      return this;
1✔
202
    }
203

204
    /**
205
     * Sets the maximum number of simultaneous long poll requests to the Temporal Server to retrieve
206
     * workflow tasks. Changing this value will affect the rate at which the worker is able to
207
     * consume tasks from a task queue.
208
     *
209
     * <p>Due to internal logic where pollers alternate between sticky and non-sticky queues, this
210
     * value cannot be 1 and will be adjusted to 2 if set to that value.
211
     *
212
     * <p>Default is 5, which is chosen if set to zero.
213
     */
214
    public Builder setMaxConcurrentWorkflowTaskPollers(int maxConcurrentWorkflowTaskPollers) {
215
      this.maxConcurrentWorkflowTaskPollers = maxConcurrentWorkflowTaskPollers;
1✔
216
      return this;
1✔
217
    }
218

219
    /**
220
     * Number of simultaneous poll requests on workflow task queue. Note that the majority of the
221
     * workflow tasks will be using host local task queue due to caching. So try incrementing {@link
222
     * WorkerFactoryOptions.Builder#setWorkflowHostLocalPollThreadCount(int)} before this one.
223
     *
224
     * <p>Default is 5, which is chosen if set to zero.
225
     *
226
     * @deprecated Use {@link #setMaxConcurrentWorkflowTaskPollers}
227
     */
228
    @Deprecated
229
    public Builder setWorkflowPollThreadCount(int workflowPollThreadCount) {
230
      return setMaxConcurrentWorkflowTaskPollers(workflowPollThreadCount);
×
231
    }
232

233
    /**
234
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
235
     * worker is not throttled due to `MaxActivitiesPerSecond` or
236
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
237
     *
238
     * <p>Default is 5, which is chosen if set to zero.
239
     */
240
    public Builder setMaxConcurrentActivityTaskPollers(int maxConcurrentActivityTaskPollers) {
241
      this.maxConcurrentActivityTaskPollers = maxConcurrentActivityTaskPollers;
1✔
242
      return this;
1✔
243
    }
244

245
    /**
246
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
247
     * worker is not throttled due to `MaxActivitiesPerSecond` or
248
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
249
     *
250
     * <p>Default is 5, which is chosen if set to zero.
251
     *
252
     * @deprecated Use {@link #setMaxConcurrentActivityTaskPollers}
253
     */
254
    @Deprecated
255
    public Builder setActivityPollThreadCount(int activityPollThreadCount) {
256
      return setMaxConcurrentActivityTaskPollers(activityPollThreadCount);
×
257
    }
258

259
    /**
260
     * If set to true worker would only handle workflow tasks and local activities. Non-local
261
     * activities will not be executed by this worker.
262
     *
263
     * <p>Default is false.
264
     */
265
    public Builder setLocalActivityWorkerOnly(boolean localActivityWorkerOnly) {
266
      this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
267
      return this;
1✔
268
    }
269

270
    /**
271
     * @param defaultDeadlockDetectionTimeoutMs time period in ms that will be used to detect
272
     *     workflows deadlock. Default is 1000ms, which is chosen if set to zero.
273
     *     <p>Specifies an amount of time in milliseconds that workflow tasks are allowed to execute
274
     *     without interruption. If workflow task runs longer than specified interval without
275
     *     yielding (like calling an Activity), it will fail automatically.
276
     * @return {@code this}
277
     * @see io.temporal.internal.sync.PotentialDeadlockException
278
     */
279
    public Builder setDefaultDeadlockDetectionTimeout(long defaultDeadlockDetectionTimeoutMs) {
280
      if (defaultDeadlockDetectionTimeoutMs < 0) {
1✔
281
        throw new IllegalArgumentException(
×
282
            "Negative defaultDeadlockDetectionTimeout value: " + defaultDeadlockDetectionTimeoutMs);
283
      }
284
      this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeoutMs;
1✔
285
      return this;
1✔
286
    }
287

288
    /**
289
     * @param interval the maximum amount of time between sending each pending heartbeat to the
290
     *     server. Regardless of heartbeat timeout, no pending heartbeat will wait longer than this
291
     *     amount of time to send. Default is 60s, which is chosen if set to null or 0.
292
     * @return {@code this}
293
     */
294
    public Builder setMaxHeartbeatThrottleInterval(@Nullable Duration interval) {
295
      Preconditions.checkArgument(
×
296
          interval == null || !interval.isNegative(),
×
297
          "Negative maxHeartbeatThrottleInterval value: %s",
298
          interval);
299
      this.maxHeartbeatThrottleInterval = interval;
×
300
      return this;
×
301
    }
302

303
    /**
304
     * @param interval the default amount of time between sending each pending heartbeat to the
305
     *     server. This is used if the ActivityOptions do not provide a HeartbeatTimeout. Otherwise,
306
     *     the interval becomes a value a bit smaller than the given HeartbeatTimeout. Default is
307
     *     30s, which is chosen if set to null or 0.
308
     * @return {@code this}
309
     */
310
    public Builder setDefaultHeartbeatThrottleInterval(@Nullable Duration interval) {
311
      Preconditions.checkArgument(
×
312
          interval == null || !interval.isNegative(),
×
313
          "Negative defaultHeartbeatThrottleInterval value: %s",
314
          interval);
315
      this.defaultHeartbeatThrottleInterval = interval;
×
316
      return this;
×
317
    }
318

319
    /**
320
     * Timeout for a workflow task routed to the "sticky worker" - host that has the workflow
321
     * instance cached in memory. Once it times out, then it can be picked up by any worker.
322
     *
323
     * <p>Default value is 5 seconds.
324
     */
325
    public Builder setStickyQueueScheduleToStartTimeout(Duration timeout) {
326
      this.stickyQueueScheduleToStartTimeout = timeout;
1✔
327
      return this;
1✔
328
    }
329

330
    /**
331
     * Disable eager activities. If set to true, eager execution will not be requested for
332
     * activities requested from workflows bound to this Worker.
333
     *
334
     * <p>Eager activity execution means the server returns requested eager activities directly from
335
     * the workflow task back to this worker which is faster than non-eager which may be dispatched
336
     * to a separate worker.
337
     *
338
     * <p>Defaults to false, meaning that eager activity execution is permitted
339
     */
340
    public Builder setDisableEagerExecution(boolean disableEagerExecution) {
341
      this.disableEagerExecution = disableEagerExecution;
×
342
      return this;
×
343
    }
344

345
    /**
346
     * Opts the worker in to the Build-ID-based versioning feature. This ensures that the worker
347
     * will only receive tasks which it is compatible with. For more information see: TODO: Doc link
348
     *
349
     * <p>Defaults to false
350
     */
351
    @Experimental
352
    public Builder setUseBuildIdForVersioning(boolean useBuildIdForVersioning) {
353
      this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
354
      return this;
1✔
355
    }
356

357
    /**
358
     * Set a unique identifier for this worker. The identifier should be stable with respect to the
359
     * code the worker uses for workflows, activities, and interceptors. For more information see:
360
     * TODO: Doc link
361
     *
362
     * <p>A Build Id must be set if {@link #setUseBuildIdForVersioning(boolean)} is set true.
363
     */
364
    @Experimental
365
    public Builder setBuildId(String buildId) {
366
      this.buildId = buildId;
1✔
367
      return this;
1✔
368
    }
369

370
    /**
371
     * During graceful shutdown, as when calling {@link WorkerFactory#shutdown()}, if the workflow
372
     * cache is enabled, this timeout controls how long to wait for the sticky task queue to drain
373
     * before shutting down the worker. If set the worker will stop making new poll requests on the
374
     * normal task queue, but will continue to poll the sticky task queue until the timeout is
375
     * reached. This value should always be greater than clients rpc long poll timeout, which can be
376
     * set via {@link WorkflowServiceStubsOptions.Builder#setRpcLongPollTimeout(Duration)}.
377
     *
378
     * <p>Default is not to wait.
379
     */
380
    @Experimental
381
    public Builder setStickyTaskQueueDrainTimeout(Duration stickyTaskQueueDrainTimeout) {
382
      this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
383
      return this;
1✔
384
    }
385

386
    /**
387
     * Set the {@link SlotSupplier} for workflow tasks.
388
     *
389
     * <p>Note that this setting is mutually exclusive with {@link
390
     * #setMaxConcurrentWorkflowTaskExecutionSize(int)}.
391
     */
392
    @Experimental
393
    public void setWorkflowSlotSupplier(SlotSupplier<WorkflowSlotInfo> workflowSlotSupplier) {
394
      this.workflowSlotSupplier = workflowSlotSupplier;
×
395
    }
×
396

397
    /**
398
     * Set the {@link SlotSupplier} for activity tasks.
399
     *
400
     * <p>Note that this setting is mutually exclusive with {@link
401
     * #setMaxConcurrentActivityExecutionSize(int)}.
402
     */
403
    @Experimental
404
    public void setActivitySlotSupplier(SlotSupplier<ActivitySlotInfo> activitySlotSupplier) {
405
      this.activitySlotSupplier = activitySlotSupplier;
×
406
    }
×
407

408
    /**
409
     * Set the {@link SlotSupplier} for local activity tasks.
410
     *
411
     * <p>Note that this setting is mutually exclusive with {@link
412
     * #setMaxConcurrentLocalActivityExecutionSize(int)}.
413
     */
414
    @Experimental
415
    public void setLocalActivitySlotSupplier(
416
        SlotSupplier<LocalActivitySlotInfo> localActivitySlotSupplier) {
417
      this.localActivitySlotSupplier = localActivitySlotSupplier;
×
418
    }
×
419

420
    /** Override identity of the worker primary specified in a WorkflowClient options. */
421
    public Builder setIdentity(String identity) {
NEW
422
      this.identity = identity;
×
NEW
423
      return this;
×
424
    }
425

426
    public WorkerOptions build() {
427
      return new WorkerOptions(
1✔
428
          maxWorkerActivitiesPerSecond,
429
          maxConcurrentActivityExecutionSize,
430
          maxConcurrentWorkflowTaskExecutionSize,
431
          maxConcurrentLocalActivityExecutionSize,
432
          workflowSlotSupplier,
433
          activitySlotSupplier,
434
          localActivitySlotSupplier,
435
          maxTaskQueueActivitiesPerSecond,
436
          maxConcurrentWorkflowTaskPollers,
437
          maxConcurrentActivityTaskPollers,
438
          localActivityWorkerOnly,
439
          defaultDeadlockDetectionTimeout,
440
          maxHeartbeatThrottleInterval,
441
          defaultHeartbeatThrottleInterval,
442
          stickyQueueScheduleToStartTimeout,
443
          disableEagerExecution,
444
          useBuildIdForVersioning,
445
          buildId,
446
          stickyTaskQueueDrainTimeout,
447
          identity);
448
    }
449

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

497
      return new WorkerOptions(
1✔
498
          maxWorkerActivitiesPerSecond,
499
          maxConcurrentActivityExecutionSize == 0
1✔
500
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE
1✔
501
              : maxConcurrentActivityExecutionSize,
1✔
502
          maxConcurrentWorkflowTaskExecutionSize == 0
1✔
503
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE
1✔
504
              : maxConcurrentWorkflowTaskExecutionSize,
1✔
505
          maxConcurrentLocalActivityExecutionSize == 0
1✔
506
              ? DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE
1✔
507
              : maxConcurrentLocalActivityExecutionSize,
1✔
508
          workflowSlotSupplier,
509
          activitySlotSupplier,
510
          localActivitySlotSupplier,
511
          maxTaskQueueActivitiesPerSecond,
512
          maxConcurrentWorkflowTaskPollers == 0
1✔
513
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS
1✔
514
              : maxConcurrentWorkflowTaskPollers,
1✔
515
          maxConcurrentActivityTaskPollers == 0
1✔
516
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS
1✔
517
              : maxConcurrentActivityTaskPollers,
1✔
518
          localActivityWorkerOnly,
519
          defaultDeadlockDetectionTimeout == 0
1✔
520
              ? DEFAULT_DEADLOCK_DETECTION_TIMEOUT
1✔
521
              : defaultDeadlockDetectionTimeout,
1✔
522
          maxHeartbeatThrottleInterval == null || maxHeartbeatThrottleInterval.isZero()
1✔
523
              ? DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL
1✔
524
              : maxHeartbeatThrottleInterval,
1✔
525
          defaultHeartbeatThrottleInterval == null || defaultHeartbeatThrottleInterval.isZero()
1✔
526
              ? DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL
1✔
527
              : defaultHeartbeatThrottleInterval,
1✔
528
          stickyQueueScheduleToStartTimeout == null
1✔
529
              ? DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT
1✔
530
              : stickyQueueScheduleToStartTimeout,
1✔
531
          disableEagerExecution,
532
          useBuildIdForVersioning,
533
          buildId,
534
          stickyTaskQueueDrainTimeout == null
1✔
535
              ? DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT
1✔
536
              : stickyTaskQueueDrainTimeout,
1✔
537
          identity);
538
    }
539
  }
540

541
  private final double maxWorkerActivitiesPerSecond;
542
  private final int maxConcurrentActivityExecutionSize;
543
  private final int maxConcurrentWorkflowTaskExecutionSize;
544
  private final int maxConcurrentLocalActivityExecutionSize;
545
  private final SlotSupplier<WorkflowSlotInfo> workflowSlotSupplier;
546
  private final SlotSupplier<ActivitySlotInfo> activitySlotSupplier;
547
  private final SlotSupplier<LocalActivitySlotInfo> localActivitySlotSupplier;
548
  private final double maxTaskQueueActivitiesPerSecond;
549
  private final int maxConcurrentWorkflowTaskPollers;
550
  private final int maxConcurrentActivityTaskPollers;
551
  private final boolean localActivityWorkerOnly;
552
  private final long defaultDeadlockDetectionTimeout;
553
  private final Duration maxHeartbeatThrottleInterval;
554
  private final Duration defaultHeartbeatThrottleInterval;
555
  private final @Nonnull Duration stickyQueueScheduleToStartTimeout;
556
  private final boolean disableEagerExecution;
557
  private final boolean useBuildIdForVersioning;
558
  private final String buildId;
559
  private final Duration stickyTaskQueueDrainTimeout;
560
  private final String identity;
561

562
  private WorkerOptions(
563
      double maxWorkerActivitiesPerSecond,
564
      int maxConcurrentActivityExecutionSize,
565
      int maxConcurrentWorkflowTaskExecutionSize,
566
      int maxConcurrentLocalActivityExecutionSize,
567
      SlotSupplier<WorkflowSlotInfo> workflowSlotSupplier,
568
      SlotSupplier<ActivitySlotInfo> activitySlotSupplier,
569
      SlotSupplier<LocalActivitySlotInfo> localActivitySlotSupplier,
570
      double maxTaskQueueActivitiesPerSecond,
571
      int workflowPollThreadCount,
572
      int activityPollThreadCount,
573
      boolean localActivityWorkerOnly,
574
      long defaultDeadlockDetectionTimeout,
575
      Duration maxHeartbeatThrottleInterval,
576
      Duration defaultHeartbeatThrottleInterval,
577
      @Nonnull Duration stickyQueueScheduleToStartTimeout,
578
      boolean disableEagerExecution,
579
      boolean useBuildIdForVersioning,
580
      String buildId,
581
      Duration stickyTaskQueueDrainTimeout,
582
      String identity) {
1✔
583
    this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
584
    this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
585
    this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
586
    this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
587
    this.workflowSlotSupplier = workflowSlotSupplier;
1✔
588
    this.activitySlotSupplier = activitySlotSupplier;
1✔
589
    this.localActivitySlotSupplier = localActivitySlotSupplier;
1✔
590
    this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
591
    this.maxConcurrentWorkflowTaskPollers = workflowPollThreadCount;
1✔
592
    this.maxConcurrentActivityTaskPollers = activityPollThreadCount;
1✔
593
    this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
594
    this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeout;
1✔
595
    this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
1✔
596
    this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
1✔
597
    this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
1✔
598
    this.disableEagerExecution = disableEagerExecution;
1✔
599
    this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
600
    this.buildId = buildId;
1✔
601
    this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
602
    this.identity = identity;
1✔
603
  }
1✔
604

605
  public double getMaxWorkerActivitiesPerSecond() {
606
    return maxWorkerActivitiesPerSecond;
1✔
607
  }
608

609
  public int getMaxConcurrentActivityExecutionSize() {
610
    return maxConcurrentActivityExecutionSize;
1✔
611
  }
612

613
  public int getMaxConcurrentWorkflowTaskExecutionSize() {
614
    return maxConcurrentWorkflowTaskExecutionSize;
1✔
615
  }
616

617
  public int getMaxConcurrentLocalActivityExecutionSize() {
618
    return maxConcurrentLocalActivityExecutionSize;
1✔
619
  }
620

621
  public double getMaxTaskQueueActivitiesPerSecond() {
622
    return maxTaskQueueActivitiesPerSecond;
1✔
623
  }
624

625
  /**
626
   * @deprecated use {@link #getMaxConcurrentWorkflowTaskPollers}
627
   */
628
  @Deprecated
629
  public int getWorkflowPollThreadCount() {
630
    return getMaxConcurrentWorkflowTaskPollers();
×
631
  }
632

633
  public int getMaxConcurrentWorkflowTaskPollers() {
634
    return maxConcurrentWorkflowTaskPollers;
1✔
635
  }
636

637
  /**
638
   * @deprecated use {@link #getMaxConcurrentActivityTaskPollers}
639
   */
640
  @Deprecated
641
  public int getActivityPollThreadCount() {
642
    return getMaxConcurrentActivityTaskPollers();
×
643
  }
644

645
  public int getMaxConcurrentActivityTaskPollers() {
646
    return maxConcurrentActivityTaskPollers;
1✔
647
  }
648

649
  public long getDefaultDeadlockDetectionTimeout() {
650
    return defaultDeadlockDetectionTimeout;
1✔
651
  }
652

653
  public boolean isLocalActivityWorkerOnly() {
654
    return localActivityWorkerOnly;
1✔
655
  }
656

657
  public Duration getMaxHeartbeatThrottleInterval() {
658
    return maxHeartbeatThrottleInterval;
1✔
659
  }
660

661
  public Duration getDefaultHeartbeatThrottleInterval() {
662
    return defaultHeartbeatThrottleInterval;
1✔
663
  }
664

665
  @Nonnull
666
  public Duration getStickyQueueScheduleToStartTimeout() {
667
    return stickyQueueScheduleToStartTimeout;
1✔
668
  }
669

670
  public boolean isEagerExecutionDisabled() {
671
    return disableEagerExecution;
1✔
672
  }
673

674
  public boolean isUsingBuildIdForVersioning() {
675
    return useBuildIdForVersioning;
1✔
676
  }
677

678
  public String getBuildId() {
679
    return buildId;
1✔
680
  }
681

682
  public Duration getStickyTaskQueueDrainTimeout() {
683
    return stickyTaskQueueDrainTimeout;
1✔
684
  }
685

686
  public SlotSupplier<WorkflowSlotInfo> getWorkflowSlotSupplier() {
687
    return workflowSlotSupplier;
1✔
688
  }
689

690
  public SlotSupplier<ActivitySlotInfo> getActivitySlotSupplier() {
691
    return activitySlotSupplier;
1✔
692
  }
693

694
  public SlotSupplier<LocalActivitySlotInfo> getLocalActivitySlotSupplier() {
695
    return localActivitySlotSupplier;
1✔
696
  }
697

698
  @Nullable
699
  public String getIdentity() {
700
    return identity;
1✔
701
  }
702

703
  @Override
704
  public boolean equals(Object o) {
705
    if (this == o) return true;
1✔
706
    if (o == null || getClass() != o.getClass()) return false;
1✔
707
    WorkerOptions that = (WorkerOptions) o;
1✔
708
    return compare(maxWorkerActivitiesPerSecond, that.maxWorkerActivitiesPerSecond) == 0
1✔
709
        && maxConcurrentActivityExecutionSize == that.maxConcurrentActivityExecutionSize
710
        && maxConcurrentWorkflowTaskExecutionSize == that.maxConcurrentWorkflowTaskExecutionSize
711
        && maxConcurrentLocalActivityExecutionSize == that.maxConcurrentLocalActivityExecutionSize
712
        && compare(maxTaskQueueActivitiesPerSecond, that.maxTaskQueueActivitiesPerSecond) == 0
1✔
713
        && maxConcurrentWorkflowTaskPollers == that.maxConcurrentWorkflowTaskPollers
714
        && maxConcurrentActivityTaskPollers == that.maxConcurrentActivityTaskPollers
715
        && localActivityWorkerOnly == that.localActivityWorkerOnly
716
        && defaultDeadlockDetectionTimeout == that.defaultDeadlockDetectionTimeout
717
        && disableEagerExecution == that.disableEagerExecution
718
        && useBuildIdForVersioning == that.useBuildIdForVersioning
719
        && Objects.equals(workflowSlotSupplier, that.workflowSlotSupplier)
1✔
720
        && Objects.equals(activitySlotSupplier, that.activitySlotSupplier)
1✔
721
        && Objects.equals(localActivitySlotSupplier, that.localActivitySlotSupplier)
1✔
722
        && Objects.equals(maxHeartbeatThrottleInterval, that.maxHeartbeatThrottleInterval)
1✔
723
        && Objects.equals(defaultHeartbeatThrottleInterval, that.defaultHeartbeatThrottleInterval)
1✔
724
        && Objects.equals(stickyQueueScheduleToStartTimeout, that.stickyQueueScheduleToStartTimeout)
1✔
725
        && Objects.equals(buildId, that.buildId)
1✔
726
        && Objects.equals(stickyTaskQueueDrainTimeout, that.stickyTaskQueueDrainTimeout)
1✔
727
        && Objects.equals(identity, that.identity);
1✔
728
  }
729

730
  @Override
731
  public int hashCode() {
732
    return Objects.hash(
×
733
        maxWorkerActivitiesPerSecond,
×
734
        maxConcurrentActivityExecutionSize,
×
735
        maxConcurrentWorkflowTaskExecutionSize,
×
736
        maxConcurrentLocalActivityExecutionSize,
×
737
        workflowSlotSupplier,
738
        activitySlotSupplier,
739
        localActivitySlotSupplier,
740
        maxTaskQueueActivitiesPerSecond,
×
741
        maxConcurrentWorkflowTaskPollers,
×
742
        maxConcurrentActivityTaskPollers,
×
743
        localActivityWorkerOnly,
×
744
        defaultDeadlockDetectionTimeout,
×
745
        maxHeartbeatThrottleInterval,
746
        defaultHeartbeatThrottleInterval,
747
        stickyQueueScheduleToStartTimeout,
748
        disableEagerExecution,
×
749
        useBuildIdForVersioning,
×
750
        buildId,
751
        stickyTaskQueueDrainTimeout,
752
        identity);
753
  }
754

755
  @Override
756
  public String toString() {
757
    return "WorkerOptions{"
×
758
        + "maxWorkerActivitiesPerSecond="
759
        + maxWorkerActivitiesPerSecond
760
        + ", maxConcurrentActivityExecutionSize="
761
        + maxConcurrentActivityExecutionSize
762
        + ", maxConcurrentWorkflowTaskExecutionSize="
763
        + maxConcurrentWorkflowTaskExecutionSize
764
        + ", maxConcurrentLocalActivityExecutionSize="
765
        + maxConcurrentLocalActivityExecutionSize
766
        + ", workflowSlotSupplier="
767
        + workflowSlotSupplier
768
        + ", activitySlotSupplier="
769
        + activitySlotSupplier
770
        + ", localActivitySlotSupplier="
771
        + localActivitySlotSupplier
772
        + ", maxTaskQueueActivitiesPerSecond="
773
        + maxTaskQueueActivitiesPerSecond
774
        + ", maxConcurrentWorkflowTaskPollers="
775
        + maxConcurrentWorkflowTaskPollers
776
        + ", maxConcurrentActivityTaskPollers="
777
        + maxConcurrentActivityTaskPollers
778
        + ", localActivityWorkerOnly="
779
        + localActivityWorkerOnly
780
        + ", defaultDeadlockDetectionTimeout="
781
        + defaultDeadlockDetectionTimeout
782
        + ", maxHeartbeatThrottleInterval="
783
        + maxHeartbeatThrottleInterval
784
        + ", defaultHeartbeatThrottleInterval="
785
        + defaultHeartbeatThrottleInterval
786
        + ", stickyQueueScheduleToStartTimeout="
787
        + stickyQueueScheduleToStartTimeout
788
        + ", disableEagerExecution="
789
        + disableEagerExecution
790
        + ", useBuildIdForVersioning="
791
        + useBuildIdForVersioning
792
        + ", buildId='"
793
        + buildId
794
        + '\''
795
        + ", stickyTaskQueueDrainTimeout="
796
        + stickyTaskQueueDrainTimeout
797
        + ", identity="
798
        + identity
799
        + '}';
800
  }
801
}
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