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

temporalio / sdk-java / #345

24 Jul 2026 11:20PM UTC coverage: 68.152%. First build
#345

push

github

web-flow
Make eager activity reservation limit configurable (#2970)

7064 of 12428 branches covered (56.84%)

Branch coverage included in aggregate %.

14 of 15 new or added lines in 4 files covered. (93.33%)

29361 of 41019 relevant lines covered (71.58%)

0.72 hits per line

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

81.23
/temporal-sdk/src/main/java/io/temporal/worker/WorkerOptions.java
1
package io.temporal.worker;
2

3
import static java.lang.Double.compare;
4

5
import com.google.common.base.Preconditions;
6
import io.temporal.common.Experimental;
7
import io.temporal.internal.Config;
8
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
9
import io.temporal.worker.tuning.*;
10
import java.time.Duration;
11
import java.util.Objects;
12
import javax.annotation.Nonnull;
13
import javax.annotation.Nullable;
14

15
public final class WorkerOptions {
16

17
  public static Builder newBuilder() {
18
    return new Builder();
1✔
19
  }
20

21
  public static Builder newBuilder(WorkerOptions options) {
22
    return new Builder(options);
1✔
23
  }
24

25
  public static WorkerOptions getDefaultInstance() {
26
    return DEFAULT_INSTANCE;
1✔
27
  }
28

29
  static final Duration DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT = Duration.ofSeconds(5);
1✔
30

31
  static final Duration DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT = Duration.ofSeconds(0);
1✔
32

33
  private static final WorkerOptions DEFAULT_INSTANCE;
34

35
  static {
36
    DEFAULT_INSTANCE = WorkerOptions.newBuilder().validateAndBuildWithDefaults();
1✔
37
  }
1✔
38

39
  public static final class Builder {
40

41
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS = 5;
42
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS = 5;
43
    private static final int DEFAULT_MAX_CONCURRENT_NEXUS_TASK_POLLERS = 5;
44
    private static final int DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE = 200;
45
    private static final int DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE = 200;
46
    private static final int DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE = 200;
47
    private static final int DEFAULT_MAX_CONCURRENT_NEXUS_EXECUTION_SIZE = 200;
48
    private static final long DEFAULT_DEADLOCK_DETECTION_TIMEOUT = 1000;
49
    private static final Duration DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL = Duration.ofSeconds(60);
1✔
50
    private static final Duration DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL =
1✔
51
        Duration.ofSeconds(30);
1✔
52

53
    private double maxWorkerActivitiesPerSecond;
54
    private int maxConcurrentActivityExecutionSize;
55
    private int maxConcurrentWorkflowTaskExecutionSize;
56
    private int maxConcurrentLocalActivityExecutionSize;
57
    private int maxConcurrentNexusExecutionSize;
58
    private double maxTaskQueueActivitiesPerSecond;
59
    private int maxConcurrentWorkflowTaskPollers;
60
    private int maxConcurrentActivityTaskPollers;
61
    private int maxConcurrentNexusTaskPollers;
62
    private boolean localActivityWorkerOnly;
63
    private long defaultDeadlockDetectionTimeout;
64
    private Duration maxHeartbeatThrottleInterval;
65
    private Duration defaultHeartbeatThrottleInterval;
66
    private Duration stickyQueueScheduleToStartTimeout;
67
    private boolean disableEagerExecution;
68
    private int maxEagerActivityReservationsPerWorkflowTask = Config.EAGER_ACTIVITIES_LIMIT;
1✔
69
    private String buildId;
70
    private boolean useBuildIdForVersioning;
71
    private Duration stickyTaskQueueDrainTimeout;
72
    private WorkerTuner workerTuner;
73
    private boolean usingVirtualThreadsOnWorkflowWorker;
74
    private boolean usingVirtualThreadsOnActivityWorker;
75
    private boolean usingVirtualThreadsOnLocalActivityWorker;
76
    private boolean usingVirtualThreadsOnNexusWorker;
77
    private String identity;
78
    private WorkerDeploymentOptions deploymentOptions;
79
    private PollerBehavior workflowTaskPollersBehavior;
80
    private PollerBehavior activityTaskPollersBehavior;
81
    private PollerBehavior nexusTaskPollersBehavior;
82
    private boolean allowActivityHeartbeatDuringShutdown;
83
    private PreferredVersionProvider preferredVersionProvider;
84
    // Track whether the user explicitly configured the pollers for a task type (called either the
85
    // max-concurrent-pollers or the poller-behavior setter). A type left unconfigured is eligible
86
    // for poller-autoscaling auto-enrollment. This must reflect the user's intent, not the resolved
87
    // value, since defaulting fills in a non-zero count that would otherwise look explicit.
88
    private boolean workflowTaskPollersConfigured;
89
    private boolean activityTaskPollersConfigured;
90
    private boolean nexusTaskPollersConfigured;
91

92
    private Builder() {}
1✔
93

94
    private Builder(WorkerOptions o) {
1✔
95
      if (o == null) {
1✔
96
        return;
1✔
97
      }
98
      this.maxWorkerActivitiesPerSecond = o.maxWorkerActivitiesPerSecond;
1✔
99
      this.maxConcurrentActivityExecutionSize = o.maxConcurrentActivityExecutionSize;
1✔
100
      this.maxConcurrentWorkflowTaskExecutionSize = o.maxConcurrentWorkflowTaskExecutionSize;
1✔
101
      this.maxConcurrentLocalActivityExecutionSize = o.maxConcurrentLocalActivityExecutionSize;
1✔
102
      this.maxConcurrentNexusExecutionSize = o.maxConcurrentNexusExecutionSize;
1✔
103
      this.workerTuner = o.workerTuner;
1✔
104
      this.maxTaskQueueActivitiesPerSecond = o.maxTaskQueueActivitiesPerSecond;
1✔
105
      this.maxConcurrentWorkflowTaskPollers = o.maxConcurrentWorkflowTaskPollers;
1✔
106
      this.maxConcurrentNexusTaskPollers = o.maxConcurrentNexusTaskPollers;
1✔
107
      this.maxConcurrentActivityTaskPollers = o.maxConcurrentActivityTaskPollers;
1✔
108
      this.localActivityWorkerOnly = o.localActivityWorkerOnly;
1✔
109
      this.defaultDeadlockDetectionTimeout = o.defaultDeadlockDetectionTimeout;
1✔
110
      this.maxHeartbeatThrottleInterval = o.maxHeartbeatThrottleInterval;
1✔
111
      this.defaultHeartbeatThrottleInterval = o.defaultHeartbeatThrottleInterval;
1✔
112
      this.stickyQueueScheduleToStartTimeout = o.stickyQueueScheduleToStartTimeout;
1✔
113
      this.disableEagerExecution = o.disableEagerExecution;
1✔
114
      this.maxEagerActivityReservationsPerWorkflowTask =
1✔
115
          o.maxEagerActivityReservationsPerWorkflowTask;
1✔
116
      this.useBuildIdForVersioning = o.useBuildIdForVersioning;
1✔
117
      this.buildId = o.buildId;
1✔
118
      this.stickyTaskQueueDrainTimeout = o.stickyTaskQueueDrainTimeout;
1✔
119
      this.identity = o.identity;
1✔
120
      this.usingVirtualThreadsOnActivityWorker = o.usingVirtualThreadsOnActivityWorker;
1✔
121
      this.usingVirtualThreadsOnWorkflowWorker = o.usingVirtualThreadsOnWorkflowWorker;
1✔
122
      this.usingVirtualThreadsOnLocalActivityWorker = o.usingVirtualThreadsOnLocalActivityWorker;
1✔
123
      this.usingVirtualThreadsOnNexusWorker = o.usingVirtualThreadsOnNexusWorker;
1✔
124
      this.deploymentOptions = o.deploymentOptions;
1✔
125
      this.workflowTaskPollersBehavior = o.workflowTaskPollersBehavior;
1✔
126
      this.activityTaskPollersBehavior = o.activityTaskPollersBehavior;
1✔
127
      this.nexusTaskPollersBehavior = o.nexusTaskPollersBehavior;
1✔
128
      this.allowActivityHeartbeatDuringShutdown = o.allowActivityHeartbeatDuringShutdown;
1✔
129
      this.preferredVersionProvider = o.preferredVersionProvider;
1✔
130
      this.workflowTaskPollersConfigured = o.workflowTaskPollersConfigured;
1✔
131
      this.activityTaskPollersConfigured = o.activityTaskPollersConfigured;
1✔
132
      this.nexusTaskPollersConfigured = o.nexusTaskPollersConfigured;
1✔
133
    }
1✔
134

135
    /**
136
     * @param maxWorkerActivitiesPerSecond Maximum number of activities started per second by this
137
     *     worker. Default is 0 which means unlimited.
138
     * @return {@code this}
139
     *     <p>If worker is not fully loaded while tasks are backing up on the service consider
140
     *     increasing {@link #setMaxConcurrentActivityTaskPollers(int)}.
141
     *     <p>Note that this is a per worker limit. Use {@link
142
     *     #setMaxTaskQueueActivitiesPerSecond(double)} to set per task queue limit across multiple
143
     *     workers.
144
     */
145
    public Builder setMaxWorkerActivitiesPerSecond(double maxWorkerActivitiesPerSecond) {
146
      if (maxWorkerActivitiesPerSecond < 0) {
1!
147
        throw new IllegalArgumentException(
×
148
            "Negative maxWorkerActivitiesPerSecond value: " + maxWorkerActivitiesPerSecond);
149
      }
150
      this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
151
      return this;
1✔
152
    }
153

154
    /**
155
     * @param maxConcurrentActivityExecutionSize Maximum number of activities executed in parallel.
156
     *     Default is 200, which is chosen if set to zero.
157
     * @return {@code this}
158
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
159
     */
160
    public Builder setMaxConcurrentActivityExecutionSize(int maxConcurrentActivityExecutionSize) {
161
      if (maxConcurrentActivityExecutionSize < 0) {
1!
162
        throw new IllegalArgumentException(
×
163
            "Negative maxConcurrentActivityExecutionSize value: "
164
                + maxConcurrentActivityExecutionSize);
165
      }
166
      this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
167
      return this;
1✔
168
    }
169

170
    /**
171
     * @param maxConcurrentWorkflowTaskExecutionSize Maximum number of simultaneously executed
172
     *     workflow tasks. Default is 200, which is chosen if set to zero.
173
     * @return {@code this}
174
     *     <p>Note that this is not related to the total number of open workflows which do not need
175
     *     to be loaded in a worker when they are not making state transitions.
176
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
177
     */
178
    public Builder setMaxConcurrentWorkflowTaskExecutionSize(
179
        int maxConcurrentWorkflowTaskExecutionSize) {
180
      if (maxConcurrentWorkflowTaskExecutionSize < 0) {
1!
181
        throw new IllegalArgumentException(
×
182
            "Negative maxConcurrentWorkflowTaskExecutionSize value: "
183
                + maxConcurrentWorkflowTaskExecutionSize);
184
      }
185
      this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
186
      return this;
1✔
187
    }
188

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

206
    /**
207
     * @param maxConcurrentNexusExecutionSize Maximum number of nexus tasks executed in parallel.
208
     *     Default is 200, which is chosen if set to zero.
209
     * @return {@code this}
210
     *     <p>Note setting is mutually exclusive with {@link #setWorkerTuner(WorkerTuner)}
211
     */
212
    @Experimental
213
    public Builder setMaxConcurrentNexusExecutionSize(int maxConcurrentNexusExecutionSize) {
214
      if (maxConcurrentNexusExecutionSize < 0) {
1!
215
        throw new IllegalArgumentException(
×
216
            "Negative maxConcurrentNexusExecutionSize value: " + maxConcurrentNexusExecutionSize);
217
      }
218
      this.maxConcurrentNexusExecutionSize = maxConcurrentNexusExecutionSize;
1✔
219
      return this;
1✔
220
    }
221

222
    /**
223
     * Optional: Sets the rate limiting on number of activities that can be executed per second.
224
     * This is managed by the server and controls activities per second for the entire task queue
225
     * across all the workers. Notice that the number is represented in double, so that you can set
226
     * it to less than 1 if needed. For example, set the number to 0.1 means you want your activity
227
     * to be executed once every 10 seconds. This can be used to protect down stream services from
228
     * flooding. The zero value of this uses the default value. Default is unlimited.
229
     *
230
     * <p>Setting this value to a non-zero value will disable eager execution for activities.
231
     */
232
    public Builder setMaxTaskQueueActivitiesPerSecond(double maxTaskQueueActivitiesPerSecond) {
233
      this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
234
      return this;
1✔
235
    }
236

237
    /**
238
     * Sets the maximum number of simultaneous long poll requests to the Temporal Server to retrieve
239
     * workflow tasks. Changing this value will affect the rate at which the worker is able to
240
     * consume tasks from a task queue.
241
     *
242
     * <p>Due to internal logic where pollers alternate between sticky and non-sticky queues, this
243
     * value cannot be 1 and will be adjusted to 2 if set to that value.
244
     *
245
     * <p>Default is 5, which is chosen if set to zero.
246
     *
247
     * <p>NOTE: If neither this nor {@link #setWorkflowTaskPollersBehavior} is set and the worker's
248
     * namespace is configured to auto-enroll workers into poller autoscaling, the worker will
249
     * automatically use poller autoscaling for workflow tasks instead of a fixed number of pollers.
250
     */
251
    public Builder setMaxConcurrentWorkflowTaskPollers(int maxConcurrentWorkflowTaskPollers) {
252
      this.maxConcurrentWorkflowTaskPollers = maxConcurrentWorkflowTaskPollers;
1✔
253
      this.workflowTaskPollersConfigured = true;
1✔
254
      return this;
1✔
255
    }
256

257
    /**
258
     * Sets the maximum number of simultaneous long poll requests to the Temporal Server to retrieve
259
     * nexus tasks. Changing this value will affect the rate at which the worker is able to consume
260
     * tasks from a task queue.
261
     *
262
     * <p>Default is 5, which is chosen if set to zero.
263
     *
264
     * <p>NOTE: If neither this nor {@link #setNexusTaskPollersBehavior} is set and the worker's
265
     * namespace is configured to auto-enroll workers into poller autoscaling, the worker will
266
     * automatically use poller autoscaling for nexus tasks instead of a fixed number of pollers.
267
     */
268
    @Experimental
269
    public Builder setMaxConcurrentNexusTaskPollers(int maxConcurrentNexusTaskPollers) {
270
      this.maxConcurrentNexusTaskPollers = maxConcurrentNexusTaskPollers;
1✔
271
      this.nexusTaskPollersConfigured = true;
1✔
272
      return this;
1✔
273
    }
274

275
    /**
276
     * Number of simultaneous poll requests on workflow task queue. Note that the majority of the
277
     * workflow tasks will be using host local task queue due to caching. So try incrementing {@link
278
     * WorkerFactoryOptions.Builder#setWorkflowHostLocalPollThreadCount(int)} before this one.
279
     *
280
     * <p>Default is 5, which is chosen if set to zero.
281
     *
282
     * @deprecated Use {@link #setMaxConcurrentWorkflowTaskPollers}
283
     */
284
    @Deprecated
285
    public Builder setWorkflowPollThreadCount(int workflowPollThreadCount) {
286
      return setMaxConcurrentWorkflowTaskPollers(workflowPollThreadCount);
×
287
    }
288

289
    /**
290
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
291
     * worker is not throttled due to `MaxActivitiesPerSecond` or
292
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
293
     *
294
     * <p>Default is 5, which is chosen if set to zero.
295
     *
296
     * <p>NOTE: If neither this nor {@link #setActivityTaskPollersBehavior} is set and the worker's
297
     * namespace is configured to auto-enroll workers into poller autoscaling, the worker will
298
     * automatically use poller autoscaling for activity tasks instead of a fixed number of pollers.
299
     */
300
    public Builder setMaxConcurrentActivityTaskPollers(int maxConcurrentActivityTaskPollers) {
301
      this.maxConcurrentActivityTaskPollers = maxConcurrentActivityTaskPollers;
1✔
302
      this.activityTaskPollersConfigured = true;
1✔
303
      return this;
1✔
304
    }
305

306
    /**
307
     * Number of simultaneous poll requests on activity task queue. Consider incrementing if the
308
     * worker is not throttled due to `MaxActivitiesPerSecond` or
309
     * `MaxConcurrentActivityExecutionSize` options and still cannot keep up with the request rate.
310
     *
311
     * <p>Default is 5, which is chosen if set to zero.
312
     *
313
     * @deprecated Use {@link #setMaxConcurrentActivityTaskPollers}
314
     */
315
    @Deprecated
316
    public Builder setActivityPollThreadCount(int activityPollThreadCount) {
317
      return setMaxConcurrentActivityTaskPollers(activityPollThreadCount);
×
318
    }
319

320
    /**
321
     * If set to true worker would only handle workflow tasks and local activities. Non-local
322
     * activities will not be executed by this worker.
323
     *
324
     * <p>Default is false.
325
     */
326
    public Builder setLocalActivityWorkerOnly(boolean localActivityWorkerOnly) {
327
      this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
328
      return this;
1✔
329
    }
330

331
    /**
332
     * @param defaultDeadlockDetectionTimeoutMs time period in ms that will be used to detect
333
     *     workflows deadlock. Default is 1000ms, which is chosen if set to zero.
334
     *     <p>Specifies a time interval in milliseconds within which a workflow task must yield
335
     *     (like calling an Activity) or complete. If a workflow task runs longer than the specified
336
     *     interval or takes too long to begin running, it will fail automatically.
337
     * @return {@code this}
338
     * @see io.temporal.internal.sync.PotentialDeadlockException
339
     */
340
    public Builder setDefaultDeadlockDetectionTimeout(long defaultDeadlockDetectionTimeoutMs) {
341
      if (defaultDeadlockDetectionTimeoutMs < 0) {
1!
342
        throw new IllegalArgumentException(
×
343
            "Negative defaultDeadlockDetectionTimeout value: " + defaultDeadlockDetectionTimeoutMs);
344
      }
345
      this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeoutMs;
1✔
346
      return this;
1✔
347
    }
348

349
    /**
350
     * @param interval the maximum amount of time between sending each pending heartbeat to the
351
     *     server. Regardless of heartbeat timeout, no pending heartbeat will wait longer than this
352
     *     amount of time to send. Default is 60s, which is chosen if set to null or 0.
353
     * @return {@code this}
354
     */
355
    public Builder setMaxHeartbeatThrottleInterval(@Nullable Duration interval) {
356
      Preconditions.checkArgument(
1!
357
          interval == null || !interval.isNegative(),
1!
358
          "Negative maxHeartbeatThrottleInterval value: %s",
359
          interval);
360
      this.maxHeartbeatThrottleInterval = interval;
1✔
361
      return this;
1✔
362
    }
363

364
    /**
365
     * @param interval the default amount of time between sending each pending heartbeat to the
366
     *     server. This is used if the ActivityOptions do not provide a HeartbeatTimeout. Otherwise,
367
     *     the interval becomes a value a bit smaller than the given HeartbeatTimeout. Default is
368
     *     30s, which is chosen if set to null or 0.
369
     * @return {@code this}
370
     */
371
    public Builder setDefaultHeartbeatThrottleInterval(@Nullable Duration interval) {
372
      Preconditions.checkArgument(
1!
373
          interval == null || !interval.isNegative(),
1!
374
          "Negative defaultHeartbeatThrottleInterval value: %s",
375
          interval);
376
      this.defaultHeartbeatThrottleInterval = interval;
1✔
377
      return this;
1✔
378
    }
379

380
    /**
381
     * Timeout for a workflow task routed to the "sticky worker" - host that has the workflow
382
     * instance cached in memory. Once it times out, then it can be picked up by any worker.
383
     *
384
     * <p>Default value is 5 seconds.
385
     */
386
    public Builder setStickyQueueScheduleToStartTimeout(Duration timeout) {
387
      this.stickyQueueScheduleToStartTimeout = timeout;
1✔
388
      return this;
1✔
389
    }
390

391
    /**
392
     * Disable eager activities. If set to true, eager execution will not be requested for
393
     * activities requested from workflows bound to this Worker.
394
     *
395
     * <p>Eager activity execution means the server returns requested eager activities directly from
396
     * the workflow task back to this worker which is faster than non-eager which may be dispatched
397
     * to a separate worker.
398
     *
399
     * <p>Defaults to false, meaning that eager activity execution is permitted. Unless you set
400
     * MaxTaskQueueActivitiesPerSecond, then eager execution is disabled.
401
     */
402
    public Builder setDisableEagerExecution(boolean disableEagerExecution) {
403
      this.disableEagerExecution = disableEagerExecution;
1✔
404
      return this;
1✔
405
    }
406

407
    /**
408
     * Sets the maximum number of activity slots that may be reserved for eager execution when
409
     * completing a workflow task.
410
     *
411
     * <p>The default is 3. The value must be positive. To disable eager activity execution, use
412
     * {@link #setDisableEagerExecution(boolean)}.
413
     */
414
    public Builder setMaxEagerActivityReservationsPerWorkflowTask(
415
        int maxEagerActivityReservationsPerWorkflowTask) {
416
      this.maxEagerActivityReservationsPerWorkflowTask =
1✔
417
          maxEagerActivityReservationsPerWorkflowTask;
418
      return this;
1✔
419
    }
420

421
    /**
422
     * Opts the worker in to the Build-ID-based versioning feature. This ensures that the worker
423
     * will only receive tasks which it is compatible with.
424
     *
425
     * <p>Defaults to false
426
     *
427
     * @deprecated Worker Versioning is now deprecated please migrate to the <a
428
     *     href="https://docs.temporal.io/worker-deployments">Worker Deployment API</a>.
429
     */
430
    @Experimental
431
    @Deprecated
432
    public Builder setUseBuildIdForVersioning(boolean useBuildIdForVersioning) {
433
      this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
434
      return this;
1✔
435
    }
436

437
    /**
438
     * Set a unique identifier for this worker. The identifier should be stable with respect to the
439
     * code the worker uses for workflows, activities, and interceptors.
440
     *
441
     * <p>A Build Id must be set if {@link #setUseBuildIdForVersioning(boolean)} is set true.
442
     *
443
     * @deprecated Worker Versioning is now deprecated please migrate to the <a
444
     *     href="https://docs.temporal.io/worker-deployments">Worker Deployment API</a>.
445
     */
446
    @Experimental
447
    @Deprecated
448
    public Builder setBuildId(String buildId) {
449
      this.buildId = buildId;
1✔
450
      return this;
1✔
451
    }
452

453
    /**
454
     * During graceful shutdown, as when calling {@link WorkerFactory#shutdown()}, if the workflow
455
     * cache is enabled, this timeout controls how long to wait for the sticky task queue to drain
456
     * before shutting down the worker. If set the worker will stop making new poll requests on the
457
     * normal task queue, but will continue to poll the sticky task queue until the timeout is
458
     * reached. This value should always be greater than clients rpc long poll timeout, which can be
459
     * set via {@link WorkflowServiceStubsOptions.Builder#setRpcLongPollTimeout(Duration)}.
460
     *
461
     * <p>Default is not to wait.
462
     */
463
    @Experimental
464
    public Builder setStickyTaskQueueDrainTimeout(Duration stickyTaskQueueDrainTimeout) {
465
      this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
466
      return this;
1✔
467
    }
468

469
    /**
470
     * Set a {@link WorkerTuner} to determine how slots will be allocated for different types of
471
     * tasks.
472
     */
473
    public Builder setWorkerTuner(WorkerTuner workerTuner) {
474
      this.workerTuner = workerTuner;
1✔
475
      return this;
1✔
476
    }
477

478
    /**
479
     * Use Virtual Threads for all the task executors created by this worker. This option is only
480
     * supported for JDK >= 21. Individual options for different types of workers can be set using
481
     * the respective methods.
482
     */
483
    public Builder setUsingVirtualThreads(boolean enable) {
484
      this.usingVirtualThreadsOnWorkflowWorker = enable;
1✔
485
      this.usingVirtualThreadsOnLocalActivityWorker = enable;
1✔
486
      this.usingVirtualThreadsOnActivityWorker = enable;
1✔
487
      this.usingVirtualThreadsOnNexusWorker = enable;
1✔
488
      return this;
1✔
489
    }
490

491
    /**
492
     * Use Virtual Threads for the Workflow task executors created by this worker. This option is
493
     * only supported for JDK >= 21.
494
     */
495
    public Builder setUsingVirtualThreadsOnWorkflowWorker(boolean enable) {
496
      this.usingVirtualThreadsOnWorkflowWorker = enable;
1✔
497
      return this;
1✔
498
    }
499

500
    /**
501
     * Use Virtual Threads for the Local Activity task executors created by this worker. This option
502
     * is only supported for JDK >= 21.
503
     */
504
    public Builder setUsingVirtualThreadsOnLocalActivityWorker(boolean enable) {
505
      this.usingVirtualThreadsOnLocalActivityWorker = enable;
1✔
506
      return this;
1✔
507
    }
508

509
    /**
510
     * Use Virtual Threads for the Activity task executors created by this worker. This option is
511
     * only supported for JDK >= 21.
512
     */
513
    public Builder setUsingVirtualThreadsOnActivityWorker(boolean enable) {
514
      this.usingVirtualThreadsOnActivityWorker = enable;
1✔
515
      return this;
1✔
516
    }
517

518
    /**
519
     * Use Virtual Threads for the Nexus task executors created by this worker. This option is only
520
     * supported for JDK >= 21.
521
     */
522
    public Builder setUsingVirtualThreadsOnNexusWorker(boolean enable) {
523
      this.usingVirtualThreadsOnNexusWorker = enable;
1✔
524
      return this;
1✔
525
    }
526

527
    /** Override identity of the worker primary specified in a WorkflowClient options. */
528
    public Builder setIdentity(String identity) {
529
      this.identity = identity;
1✔
530
      return this;
1✔
531
    }
532

533
    /**
534
     * Set deployment options for the worker. Exclusive with {@link #setUseBuildIdForVersioning} and
535
     * {@link #setBuildId(String)}.
536
     */
537
    public Builder setDeploymentOptions(WorkerDeploymentOptions deploymentOptions) {
538
      this.deploymentOptions = deploymentOptions;
1✔
539
      return this;
1✔
540
    }
541

542
    /**
543
     * Set the poller behavior for workflow task pollers.
544
     *
545
     * <p>Note: If the poller behavior is set to {@link PollerBehaviorSimpleMaximum}, the maximum
546
     * number of concurrent workflow task pollers must be at least 2 to account for the sticky and
547
     * non-sticky task poller. If it is set to 1 it will be automatically adjusted to 2.
548
     *
549
     * <p>If the sticky queue is enabled, the poller behavior will be used for the sticky queue as
550
     * well.
551
     *
552
     * <p>NOTE: If neither this nor {@link #setMaxConcurrentWorkflowTaskPollers} is set and the
553
     * worker's namespace is configured to auto-enroll workers into poller autoscaling, the worker
554
     * will automatically use poller autoscaling for workflow tasks instead of a fixed number of
555
     * pollers.
556
     */
557
    public Builder setWorkflowTaskPollersBehavior(PollerBehavior pollerBehavior) {
558
      this.workflowTaskPollersBehavior = pollerBehavior;
1✔
559
      this.workflowTaskPollersConfigured = true;
1✔
560
      return this;
1✔
561
    }
562

563
    /**
564
     * Set the poller behavior for activity task pollers.
565
     *
566
     * <p>NOTE: If neither this nor {@link #setMaxConcurrentActivityTaskPollers} is set and the
567
     * worker's namespace is configured to auto-enroll workers into poller autoscaling, the worker
568
     * will automatically use poller autoscaling for activity tasks instead of a fixed number of
569
     * pollers.
570
     */
571
    public Builder setActivityTaskPollersBehavior(PollerBehavior pollerBehavior) {
572
      this.activityTaskPollersBehavior = pollerBehavior;
1✔
573
      this.activityTaskPollersConfigured = true;
1✔
574
      return this;
1✔
575
    }
576

577
    /**
578
     * Set the poller behavior for nexus task pollers.
579
     *
580
     * <p>NOTE: If neither this nor {@link #setMaxConcurrentNexusTaskPollers} is set and the
581
     * worker's namespace is configured to auto-enroll workers into poller autoscaling, the worker
582
     * will automatically use poller autoscaling for nexus tasks instead of a fixed number of
583
     * pollers.
584
     */
585
    public Builder setNexusTaskPollersBehavior(PollerBehavior pollerBehavior) {
586
      this.nexusTaskPollersBehavior = pollerBehavior;
1✔
587
      this.nexusTaskPollersConfigured = true;
1✔
588
      return this;
1✔
589
    }
590

591
    /**
592
     * If true, activities can keep heartbeating during graceful worker shutdown (see {@link
593
     * io.temporal.worker.WorkerFactory#shutdown WorkerFactory.shutdown}). Defaults to false, which
594
     * means that after graceful shutdown is requested, calling {@link
595
     * io.temporal.activity.ActivityExecutionContext#heartbeat ActivityExecutionContext.heartbeat}
596
     * does not send a heartbeat and instead throws {@link
597
     * io.temporal.client.ActivityWorkerShutdownException ActivityWorkerShutdownException}. This
598
     * option is ignored by non-graceful shutdown (see {@link
599
     * io.temporal.worker.WorkerFactory#shutdownNow WorkerFactory.shutdownNow}).
600
     *
601
     * <p>Note that with this option enabled, activities are no longer notified of the worker
602
     * shutdown by the {@link io.temporal.client.ActivityWorkerShutdownException
603
     * ActivityWorkerShutdownException} exception, so they are expected to complete within the
604
     * termination grace period on their own.
605
     */
606
    @Experimental
607
    public Builder setAllowActivityHeartbeatDuringShutdown(
608
        boolean allowActivityHeartbeatDuringShutdown) {
609
      this.allowActivityHeartbeatDuringShutdown = allowActivityHeartbeatDuringShutdown;
1✔
610
      return this;
1✔
611
    }
612

613
    /**
614
     * Sets a provider that can choose the version recorded by the first non-replay {@link
615
     * io.temporal.workflow.Workflow#getVersion(String, int, int)} call for a change ID.
616
     *
617
     * <p>If unset, or if the provider returns {@link java.util.Optional#empty()}, the SDK keeps the
618
     * existing behavior of recording {@code maxSupported}.
619
     */
620
    @Experimental
621
    public Builder setPreferredVersionProvider(PreferredVersionProvider preferredVersionProvider) {
622
      this.preferredVersionProvider = preferredVersionProvider;
1✔
623
      return this;
1✔
624
    }
625

626
    public WorkerOptions build() {
627
      return new WorkerOptions(
1✔
628
          maxWorkerActivitiesPerSecond,
629
          maxConcurrentActivityExecutionSize,
630
          maxConcurrentWorkflowTaskExecutionSize,
631
          maxConcurrentLocalActivityExecutionSize,
632
          maxConcurrentNexusExecutionSize,
633
          workerTuner,
634
          maxTaskQueueActivitiesPerSecond,
635
          maxConcurrentWorkflowTaskPollers,
636
          maxConcurrentActivityTaskPollers,
637
          maxConcurrentNexusTaskPollers,
638
          localActivityWorkerOnly,
639
          defaultDeadlockDetectionTimeout,
640
          maxHeartbeatThrottleInterval,
641
          defaultHeartbeatThrottleInterval,
642
          stickyQueueScheduleToStartTimeout,
643
          disableEagerExecution,
644
          maxEagerActivityReservationsPerWorkflowTask,
645
          useBuildIdForVersioning,
646
          buildId,
647
          stickyTaskQueueDrainTimeout,
648
          identity,
649
          usingVirtualThreadsOnWorkflowWorker,
650
          usingVirtualThreadsOnActivityWorker,
651
          usingVirtualThreadsOnLocalActivityWorker,
652
          usingVirtualThreadsOnNexusWorker,
653
          deploymentOptions,
654
          workflowTaskPollersBehavior,
655
          activityTaskPollersBehavior,
656
          nexusTaskPollersBehavior,
657
          allowActivityHeartbeatDuringShutdown,
658
          preferredVersionProvider,
659
          workflowTaskPollersConfigured,
660
          activityTaskPollersConfigured,
661
          nexusTaskPollersConfigured);
662
    }
663

664
    public WorkerOptions validateAndBuildWithDefaults() {
665
      Preconditions.checkState(
1!
666
          maxWorkerActivitiesPerSecond >= 0, "negative maxActivitiesPerSecond");
667
      Preconditions.checkState(
1!
668
          maxConcurrentActivityExecutionSize >= 0, "negative maxConcurrentActivityExecutionSize");
669
      Preconditions.checkState(
1✔
670
          maxEagerActivityReservationsPerWorkflowTask > 0,
671
          "maxEagerActivityReservationsPerWorkflowTask must be positive; use "
672
              + "setDisableEagerExecution(true) to disable eager activity execution");
673
      Preconditions.checkState(
1!
674
          maxConcurrentWorkflowTaskExecutionSize >= 0,
675
          "negative maxConcurrentWorkflowTaskExecutionSize");
676
      Preconditions.checkState(
1!
677
          maxConcurrentLocalActivityExecutionSize >= 0,
678
          "negative maxConcurrentLocalActivityExecutionSize");
679
      if (workerTuner != null) {
1✔
680
        Preconditions.checkState(
1!
681
            maxConcurrentActivityExecutionSize == 0,
682
            "maxConcurrentActivityExecutionSize must not be set if workerTuner is set");
683
      }
684
      if (workerTuner != null) {
1✔
685
        Preconditions.checkState(
1!
686
            maxConcurrentWorkflowTaskExecutionSize == 0,
687
            "maxConcurrentWorkflowTaskExecutionSize must not be set if workerTuner is set");
688
      }
689
      if (workerTuner != null) {
1✔
690
        Preconditions.checkState(
1!
691
            maxConcurrentLocalActivityExecutionSize == 0,
692
            "maxConcurrentLocalActivityExecutionSize must not be set if workerTuner is set");
693
      }
694
      Preconditions.checkState(
1!
695
          maxTaskQueueActivitiesPerSecond >= 0, "negative taskQueueActivitiesPerSecond");
696
      Preconditions.checkState(
1!
697
          maxConcurrentWorkflowTaskPollers >= 0, "negative maxConcurrentWorkflowTaskPollers");
698
      Preconditions.checkState(
1!
699
          maxConcurrentActivityTaskPollers >= 0, "negative maxConcurrentActivityTaskPollers");
700
      Preconditions.checkState(
1!
701
          defaultDeadlockDetectionTimeout >= 0, "negative defaultDeadlockDetectionTimeout");
702
      Preconditions.checkState(
1✔
703
          stickyQueueScheduleToStartTimeout == null
704
              || !stickyQueueScheduleToStartTimeout.isNegative(),
1!
705
          "negative stickyQueueScheduleToStartTimeout");
706
      if (useBuildIdForVersioning) {
1✔
707
        Preconditions.checkState(
1!
708
            buildId != null && !buildId.isEmpty(),
1!
709
            "buildId must be set non-empty if useBuildIdForVersioning is set true");
710
        Preconditions.checkState(
1!
711
            deploymentOptions == null,
712
            "deploymentOptions must not be set if useBuildIdForVersioning is set true");
713
      }
714
      if (buildId != null) {
1✔
715
        Preconditions.checkState(
1!
716
            deploymentOptions == null,
717
            "deploymentOptions must not be set if buildId is set, prefer using deploymentOptions");
718
      }
719
      Preconditions.checkState(
1✔
720
          stickyTaskQueueDrainTimeout == null || !stickyTaskQueueDrainTimeout.isNegative(),
1!
721
          "negative stickyTaskQueueDrainTimeout");
722
      Preconditions.checkState(
1!
723
          maxConcurrentNexusTaskPollers >= 0, "negative maxConcurrentNexusTaskPollers");
724

725
      if (workflowTaskPollersBehavior != null) {
1✔
726
        Preconditions.checkState(
1!
727
            maxConcurrentWorkflowTaskPollers == 0,
728
            "workflowTaskPollersBehavior and maxConcurrentWorkflowTaskPollers are mutually exclusive");
729
      }
730
      if (activityTaskPollersBehavior != null) {
1✔
731
        Preconditions.checkState(
1!
732
            maxConcurrentActivityTaskPollers == 0,
733
            "activityTaskPollersBehavior and maxConcurrentActivityTaskPollers are mutually exclusive");
734
      }
735
      if (nexusTaskPollersBehavior != null) {
1✔
736
        Preconditions.checkState(
1!
737
            maxConcurrentNexusTaskPollers == 0,
738
            "nexusTaskPollersBehavior and maxConcurrentNexusTaskPollers are mutually exclusive");
739
      }
740

741
      return new WorkerOptions(
1✔
742
          maxWorkerActivitiesPerSecond,
743
          maxConcurrentActivityExecutionSize == 0
1✔
744
              ? DEFAULT_MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE
1✔
745
              : maxConcurrentActivityExecutionSize,
1✔
746
          maxConcurrentWorkflowTaskExecutionSize == 0
1✔
747
              ? DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE
1✔
748
              : maxConcurrentWorkflowTaskExecutionSize,
1✔
749
          maxConcurrentLocalActivityExecutionSize == 0
1✔
750
              ? DEFAULT_MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE
1✔
751
              : maxConcurrentLocalActivityExecutionSize,
1✔
752
          maxConcurrentNexusExecutionSize == 0
1✔
753
              ? DEFAULT_MAX_CONCURRENT_NEXUS_EXECUTION_SIZE
1✔
754
              : maxConcurrentNexusExecutionSize,
1✔
755
          workerTuner,
756
          maxTaskQueueActivitiesPerSecond,
757
          maxConcurrentWorkflowTaskPollers == 0
1✔
758
              ? (workflowTaskPollersBehavior != null
1✔
759
                  ? 0
1✔
760
                  : DEFAULT_MAX_CONCURRENT_WORKFLOW_TASK_POLLERS)
1✔
761
              : maxConcurrentWorkflowTaskPollers,
1✔
762
          maxConcurrentActivityTaskPollers == 0
1✔
763
              ? (activityTaskPollersBehavior != null
1✔
764
                  ? 0
1✔
765
                  : DEFAULT_MAX_CONCURRENT_ACTIVITY_TASK_POLLERS)
1✔
766
              : maxConcurrentActivityTaskPollers,
1✔
767
          maxConcurrentNexusTaskPollers == 0
1✔
768
              ? (nexusTaskPollersBehavior != null ? 0 : DEFAULT_MAX_CONCURRENT_NEXUS_TASK_POLLERS)
1✔
769
              : maxConcurrentNexusTaskPollers,
1✔
770
          localActivityWorkerOnly,
771
          defaultDeadlockDetectionTimeout == 0
1✔
772
              ? DEFAULT_DEADLOCK_DETECTION_TIMEOUT
1✔
773
              : defaultDeadlockDetectionTimeout,
1✔
774
          maxHeartbeatThrottleInterval == null || maxHeartbeatThrottleInterval.isZero()
1!
775
              ? DEFAULT_MAX_HEARTBEAT_THROTTLE_INTERVAL
1✔
776
              : maxHeartbeatThrottleInterval,
1✔
777
          defaultHeartbeatThrottleInterval == null || defaultHeartbeatThrottleInterval.isZero()
1!
778
              ? DEFAULT_DEFAULT_HEARTBEAT_THROTTLE_INTERVAL
1✔
779
              : defaultHeartbeatThrottleInterval,
1✔
780
          stickyQueueScheduleToStartTimeout == null
1✔
781
              ? DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT
1✔
782
              : stickyQueueScheduleToStartTimeout,
1✔
783
          disableEagerExecution,
784
          maxEagerActivityReservationsPerWorkflowTask,
785
          useBuildIdForVersioning,
786
          buildId,
787
          stickyTaskQueueDrainTimeout == null
1✔
788
              ? DEFAULT_STICKY_TASK_QUEUE_DRAIN_TIMEOUT
1✔
789
              : stickyTaskQueueDrainTimeout,
1✔
790
          identity,
791
          usingVirtualThreadsOnWorkflowWorker,
792
          usingVirtualThreadsOnActivityWorker,
793
          usingVirtualThreadsOnLocalActivityWorker,
794
          usingVirtualThreadsOnNexusWorker,
795
          deploymentOptions,
796
          workflowTaskPollersBehavior,
797
          activityTaskPollersBehavior,
798
          nexusTaskPollersBehavior,
799
          allowActivityHeartbeatDuringShutdown,
800
          preferredVersionProvider,
801
          workflowTaskPollersConfigured,
802
          activityTaskPollersConfigured,
803
          nexusTaskPollersConfigured);
804
    }
805
  }
806

807
  private final double maxWorkerActivitiesPerSecond;
808
  private final int maxConcurrentActivityExecutionSize;
809
  private final int maxConcurrentWorkflowTaskExecutionSize;
810
  private final int maxConcurrentLocalActivityExecutionSize;
811
  private final int maxConcurrentNexusExecutionSize;
812
  private final WorkerTuner workerTuner;
813
  private final double maxTaskQueueActivitiesPerSecond;
814
  private final int maxConcurrentWorkflowTaskPollers;
815
  private final int maxConcurrentActivityTaskPollers;
816
  private final int maxConcurrentNexusTaskPollers;
817
  private final boolean localActivityWorkerOnly;
818
  private final long defaultDeadlockDetectionTimeout;
819
  private final Duration maxHeartbeatThrottleInterval;
820
  private final Duration defaultHeartbeatThrottleInterval;
821
  private final @Nonnull Duration stickyQueueScheduleToStartTimeout;
822
  private final boolean disableEagerExecution;
823
  private final int maxEagerActivityReservationsPerWorkflowTask;
824
  private final boolean useBuildIdForVersioning;
825
  private final String buildId;
826
  private final Duration stickyTaskQueueDrainTimeout;
827
  private final String identity;
828
  private final boolean usingVirtualThreadsOnWorkflowWorker;
829
  private final boolean usingVirtualThreadsOnActivityWorker;
830
  private final boolean usingVirtualThreadsOnLocalActivityWorker;
831
  private final boolean usingVirtualThreadsOnNexusWorker;
832
  private final WorkerDeploymentOptions deploymentOptions;
833
  private final PollerBehavior workflowTaskPollersBehavior;
834
  private final PollerBehavior activityTaskPollersBehavior;
835
  private final PollerBehavior nexusTaskPollersBehavior;
836
  private final boolean allowActivityHeartbeatDuringShutdown;
837
  private final PreferredVersionProvider preferredVersionProvider;
838
  private final boolean workflowTaskPollersConfigured;
839
  private final boolean activityTaskPollersConfigured;
840
  private final boolean nexusTaskPollersConfigured;
841

842
  private WorkerOptions(
843
      double maxWorkerActivitiesPerSecond,
844
      int maxConcurrentActivityExecutionSize,
845
      int maxConcurrentWorkflowTaskExecutionSize,
846
      int maxConcurrentLocalActivityExecutionSize,
847
      int maxConcurrentNexusExecutionSize,
848
      WorkerTuner workerTuner,
849
      double maxTaskQueueActivitiesPerSecond,
850
      int workflowPollThreadCount,
851
      int activityPollThreadCount,
852
      int nexusPollThreadCount,
853
      boolean localActivityWorkerOnly,
854
      long defaultDeadlockDetectionTimeout,
855
      Duration maxHeartbeatThrottleInterval,
856
      Duration defaultHeartbeatThrottleInterval,
857
      @Nonnull Duration stickyQueueScheduleToStartTimeout,
858
      boolean disableEagerExecution,
859
      int maxEagerActivityReservationsPerWorkflowTask,
860
      boolean useBuildIdForVersioning,
861
      String buildId,
862
      Duration stickyTaskQueueDrainTimeout,
863
      String identity,
864
      boolean useThreadsEnabledOnWorkflowWorker,
865
      boolean useThreadsEnabledOnActivityWorker,
866
      boolean virtualThreadsEnabledOnLocalActivityWorker,
867
      boolean virtualThreadsEnabledOnNexusWorker,
868
      WorkerDeploymentOptions deploymentOptions,
869
      PollerBehavior workflowTaskPollersBehavior,
870
      PollerBehavior activityTaskPollersBehavior,
871
      PollerBehavior nexusTaskPollersBehavior,
872
      boolean allowActivityHeartbeatDuringShutdown,
873
      PreferredVersionProvider preferredVersionProvider,
874
      boolean workflowTaskPollersConfigured,
875
      boolean activityTaskPollersConfigured,
876
      boolean nexusTaskPollersConfigured) {
1✔
877
    this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond;
1✔
878
    this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize;
1✔
879
    this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize;
1✔
880
    this.maxConcurrentLocalActivityExecutionSize = maxConcurrentLocalActivityExecutionSize;
1✔
881
    this.maxConcurrentNexusExecutionSize = maxConcurrentNexusExecutionSize;
1✔
882
    this.workerTuner = workerTuner;
1✔
883
    this.maxTaskQueueActivitiesPerSecond = maxTaskQueueActivitiesPerSecond;
1✔
884
    this.maxConcurrentWorkflowTaskPollers = workflowPollThreadCount;
1✔
885
    this.maxConcurrentActivityTaskPollers = activityPollThreadCount;
1✔
886
    this.maxConcurrentNexusTaskPollers = nexusPollThreadCount;
1✔
887
    this.localActivityWorkerOnly = localActivityWorkerOnly;
1✔
888
    this.defaultDeadlockDetectionTimeout = defaultDeadlockDetectionTimeout;
1✔
889
    this.maxHeartbeatThrottleInterval = maxHeartbeatThrottleInterval;
1✔
890
    this.defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval;
1✔
891
    this.stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout;
1✔
892
    this.disableEagerExecution = maxTaskQueueActivitiesPerSecond > 0 ? true : disableEagerExecution;
1✔
893
    this.maxEagerActivityReservationsPerWorkflowTask = maxEagerActivityReservationsPerWorkflowTask;
1✔
894
    this.useBuildIdForVersioning = useBuildIdForVersioning;
1✔
895
    this.buildId = buildId;
1✔
896
    this.stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout;
1✔
897
    this.identity = identity;
1✔
898
    this.usingVirtualThreadsOnWorkflowWorker = useThreadsEnabledOnWorkflowWorker;
1✔
899
    this.usingVirtualThreadsOnActivityWorker = useThreadsEnabledOnActivityWorker;
1✔
900
    this.usingVirtualThreadsOnLocalActivityWorker = virtualThreadsEnabledOnLocalActivityWorker;
1✔
901
    this.usingVirtualThreadsOnNexusWorker = virtualThreadsEnabledOnNexusWorker;
1✔
902
    this.deploymentOptions = deploymentOptions;
1✔
903
    this.workflowTaskPollersBehavior = workflowTaskPollersBehavior;
1✔
904
    this.activityTaskPollersBehavior = activityTaskPollersBehavior;
1✔
905
    this.nexusTaskPollersBehavior = nexusTaskPollersBehavior;
1✔
906
    this.allowActivityHeartbeatDuringShutdown = allowActivityHeartbeatDuringShutdown;
1✔
907
    this.preferredVersionProvider = preferredVersionProvider;
1✔
908
    this.workflowTaskPollersConfigured = workflowTaskPollersConfigured;
1✔
909
    this.activityTaskPollersConfigured = activityTaskPollersConfigured;
1✔
910
    this.nexusTaskPollersConfigured = nexusTaskPollersConfigured;
1✔
911
  }
1✔
912

913
  /**
914
   * Whether the workflow task pollers were left at their default (the user called neither {@link
915
   * Builder#setMaxConcurrentWorkflowTaskPollers} nor {@link
916
   * Builder#setWorkflowTaskPollersBehavior}), which makes them eligible for poller-autoscaling
917
   * auto-enrollment.
918
   */
919
  boolean isWorkflowTaskPollerAutoEnrollEligible() {
920
    return !workflowTaskPollersConfigured;
1✔
921
  }
922

923
  /**
924
   * Whether the activity task pollers were left at their default (the user called neither {@link
925
   * Builder#setMaxConcurrentActivityTaskPollers} nor {@link
926
   * Builder#setActivityTaskPollersBehavior}), which makes them eligible for poller-autoscaling
927
   * auto-enrollment.
928
   */
929
  boolean isActivityTaskPollerAutoEnrollEligible() {
930
    return !activityTaskPollersConfigured;
1✔
931
  }
932

933
  /**
934
   * Whether the nexus task pollers were left at their default (the user called neither {@link
935
   * Builder#setMaxConcurrentNexusTaskPollers} nor {@link Builder#setNexusTaskPollersBehavior}),
936
   * which makes them eligible for poller-autoscaling auto-enrollment.
937
   */
938
  boolean isNexusTaskPollerAutoEnrollEligible() {
939
    return !nexusTaskPollersConfigured;
1✔
940
  }
941

942
  public double getMaxWorkerActivitiesPerSecond() {
943
    return maxWorkerActivitiesPerSecond;
1✔
944
  }
945

946
  public int getMaxConcurrentActivityExecutionSize() {
947
    return maxConcurrentActivityExecutionSize;
1✔
948
  }
949

950
  public int getMaxConcurrentWorkflowTaskExecutionSize() {
951
    return maxConcurrentWorkflowTaskExecutionSize;
1✔
952
  }
953

954
  public int getMaxConcurrentLocalActivityExecutionSize() {
955
    return maxConcurrentLocalActivityExecutionSize;
1✔
956
  }
957

958
  public int getMaxConcurrentNexusExecutionSize() {
959
    return maxConcurrentNexusExecutionSize;
1✔
960
  }
961

962
  public double getMaxTaskQueueActivitiesPerSecond() {
963
    return maxTaskQueueActivitiesPerSecond;
1✔
964
  }
965

966
  /**
967
   * @deprecated use {@link #getMaxConcurrentWorkflowTaskPollers}
968
   */
969
  @Deprecated
970
  public int getWorkflowPollThreadCount() {
971
    return getMaxConcurrentWorkflowTaskPollers();
×
972
  }
973

974
  public int getMaxConcurrentWorkflowTaskPollers() {
975
    return maxConcurrentWorkflowTaskPollers;
1✔
976
  }
977

978
  /**
979
   * @deprecated use {@link #getMaxConcurrentActivityTaskPollers}
980
   */
981
  @Deprecated
982
  public int getActivityPollThreadCount() {
983
    return getMaxConcurrentActivityTaskPollers();
×
984
  }
985

986
  public int getMaxConcurrentActivityTaskPollers() {
987
    return maxConcurrentActivityTaskPollers;
1✔
988
  }
989

990
  public int getMaxConcurrentNexusTaskPollers() {
991
    return maxConcurrentNexusTaskPollers;
1✔
992
  }
993

994
  public long getDefaultDeadlockDetectionTimeout() {
995
    return defaultDeadlockDetectionTimeout;
1✔
996
  }
997

998
  public boolean isLocalActivityWorkerOnly() {
999
    return localActivityWorkerOnly;
1✔
1000
  }
1001

1002
  public Duration getMaxHeartbeatThrottleInterval() {
1003
    return maxHeartbeatThrottleInterval;
1✔
1004
  }
1005

1006
  public Duration getDefaultHeartbeatThrottleInterval() {
1007
    return defaultHeartbeatThrottleInterval;
1✔
1008
  }
1009

1010
  @Nonnull
1011
  public Duration getStickyQueueScheduleToStartTimeout() {
1012
    return stickyQueueScheduleToStartTimeout;
1✔
1013
  }
1014

1015
  public boolean isEagerExecutionDisabled() {
1016
    return disableEagerExecution;
1✔
1017
  }
1018

1019
  public int getMaxEagerActivityReservationsPerWorkflowTask() {
1020
    return maxEagerActivityReservationsPerWorkflowTask;
1✔
1021
  }
1022

1023
  public boolean isUsingBuildIdForVersioning() {
1024
    return useBuildIdForVersioning;
1✔
1025
  }
1026

1027
  public String getBuildId() {
1028
    return buildId;
1✔
1029
  }
1030

1031
  public Duration getStickyTaskQueueDrainTimeout() {
1032
    return stickyTaskQueueDrainTimeout;
1✔
1033
  }
1034

1035
  public WorkerTuner getWorkerTuner() {
1036
    return workerTuner;
1✔
1037
  }
1038

1039
  @Nullable
1040
  public String getIdentity() {
1041
    return identity;
1✔
1042
  }
1043

1044
  public boolean isUsingVirtualThreadsOnWorkflowWorker() {
1045
    return usingVirtualThreadsOnWorkflowWorker;
1✔
1046
  }
1047

1048
  public boolean isUsingVirtualThreadsOnActivityWorker() {
1049
    return usingVirtualThreadsOnActivityWorker;
1✔
1050
  }
1051

1052
  public boolean isUsingVirtualThreadsOnLocalActivityWorker() {
1053
    return usingVirtualThreadsOnLocalActivityWorker;
1✔
1054
  }
1055

1056
  public boolean isUsingVirtualThreadsOnNexusWorker() {
1057
    return usingVirtualThreadsOnNexusWorker;
1✔
1058
  }
1059

1060
  @Experimental
1061
  public WorkerDeploymentOptions getDeploymentOptions() {
1062
    return deploymentOptions;
1✔
1063
  }
1064

1065
  public PollerBehavior getWorkflowTaskPollersBehavior() {
1066
    return workflowTaskPollersBehavior;
1✔
1067
  }
1068

1069
  public PollerBehavior getActivityTaskPollersBehavior() {
1070
    return activityTaskPollersBehavior;
1✔
1071
  }
1072

1073
  public PollerBehavior getNexusTaskPollersBehavior() {
1074
    return nexusTaskPollersBehavior;
1✔
1075
  }
1076

1077
  @Experimental
1078
  public boolean getAllowActivityHeartbeatDuringShutdown() {
1079
    return allowActivityHeartbeatDuringShutdown;
1✔
1080
  }
1081

1082
  @Experimental
1083
  public PreferredVersionProvider getPreferredVersionProvider() {
1084
    return preferredVersionProvider;
1✔
1085
  }
1086

1087
  @Override
1088
  public boolean equals(Object o) {
1089
    if (this == o) return true;
1!
1090
    if (o == null || getClass() != o.getClass()) return false;
1!
1091
    WorkerOptions that = (WorkerOptions) o;
1✔
1092
    return compare(maxWorkerActivitiesPerSecond, that.maxWorkerActivitiesPerSecond) == 0
1!
1093
        && maxConcurrentActivityExecutionSize == that.maxConcurrentActivityExecutionSize
1094
        && maxConcurrentWorkflowTaskExecutionSize == that.maxConcurrentWorkflowTaskExecutionSize
1095
        && maxConcurrentLocalActivityExecutionSize == that.maxConcurrentLocalActivityExecutionSize
1096
        && maxConcurrentNexusExecutionSize == that.maxConcurrentNexusExecutionSize
1097
        && compare(maxTaskQueueActivitiesPerSecond, that.maxTaskQueueActivitiesPerSecond) == 0
1!
1098
        && maxConcurrentWorkflowTaskPollers == that.maxConcurrentWorkflowTaskPollers
1099
        && maxConcurrentActivityTaskPollers == that.maxConcurrentActivityTaskPollers
1100
        && maxConcurrentNexusTaskPollers == that.maxConcurrentNexusTaskPollers
1101
        && localActivityWorkerOnly == that.localActivityWorkerOnly
1102
        && defaultDeadlockDetectionTimeout == that.defaultDeadlockDetectionTimeout
1103
        && disableEagerExecution == that.disableEagerExecution
1104
        && maxEagerActivityReservationsPerWorkflowTask
1105
            == that.maxEagerActivityReservationsPerWorkflowTask
1106
        && useBuildIdForVersioning == that.useBuildIdForVersioning
1107
        && Objects.equals(workerTuner, that.workerTuner)
1!
1108
        && Objects.equals(maxHeartbeatThrottleInterval, that.maxHeartbeatThrottleInterval)
1!
1109
        && Objects.equals(defaultHeartbeatThrottleInterval, that.defaultHeartbeatThrottleInterval)
1!
1110
        && Objects.equals(stickyQueueScheduleToStartTimeout, that.stickyQueueScheduleToStartTimeout)
1!
1111
        && Objects.equals(buildId, that.buildId)
1!
1112
        && Objects.equals(stickyTaskQueueDrainTimeout, that.stickyTaskQueueDrainTimeout)
1!
1113
        && Objects.equals(identity, that.identity)
1!
1114
        && usingVirtualThreadsOnWorkflowWorker == that.usingVirtualThreadsOnWorkflowWorker
1115
        && usingVirtualThreadsOnActivityWorker == that.usingVirtualThreadsOnActivityWorker
1116
        && usingVirtualThreadsOnLocalActivityWorker == that.usingVirtualThreadsOnLocalActivityWorker
1117
        && usingVirtualThreadsOnNexusWorker == that.usingVirtualThreadsOnNexusWorker
1118
        && Objects.equals(deploymentOptions, that.deploymentOptions)
1!
1119
        && Objects.equals(workflowTaskPollersBehavior, that.workflowTaskPollersBehavior)
1!
1120
        && Objects.equals(activityTaskPollersBehavior, that.activityTaskPollersBehavior)
1!
1121
        && Objects.equals(nexusTaskPollersBehavior, that.nexusTaskPollersBehavior)
1!
1122
        && allowActivityHeartbeatDuringShutdown == that.allowActivityHeartbeatDuringShutdown
1123
        && Objects.equals(preferredVersionProvider, that.preferredVersionProvider);
1!
1124
  }
1125

1126
  @Override
1127
  public int hashCode() {
1128
    return Objects.hash(
×
1129
        maxWorkerActivitiesPerSecond,
×
1130
        maxConcurrentActivityExecutionSize,
×
1131
        maxConcurrentWorkflowTaskExecutionSize,
×
1132
        maxConcurrentLocalActivityExecutionSize,
×
1133
        maxConcurrentNexusExecutionSize,
×
1134
        workerTuner,
1135
        maxTaskQueueActivitiesPerSecond,
×
1136
        maxConcurrentWorkflowTaskPollers,
×
1137
        maxConcurrentActivityTaskPollers,
×
1138
        maxConcurrentNexusTaskPollers,
×
1139
        localActivityWorkerOnly,
×
1140
        defaultDeadlockDetectionTimeout,
×
1141
        maxHeartbeatThrottleInterval,
1142
        defaultHeartbeatThrottleInterval,
1143
        stickyQueueScheduleToStartTimeout,
1144
        disableEagerExecution,
×
NEW
1145
        maxEagerActivityReservationsPerWorkflowTask,
×
1146
        useBuildIdForVersioning,
×
1147
        buildId,
1148
        stickyTaskQueueDrainTimeout,
1149
        identity,
1150
        usingVirtualThreadsOnWorkflowWorker,
×
1151
        usingVirtualThreadsOnActivityWorker,
×
1152
        usingVirtualThreadsOnLocalActivityWorker,
×
1153
        usingVirtualThreadsOnNexusWorker,
×
1154
        deploymentOptions,
1155
        workflowTaskPollersBehavior,
1156
        activityTaskPollersBehavior,
1157
        nexusTaskPollersBehavior,
1158
        allowActivityHeartbeatDuringShutdown,
×
1159
        preferredVersionProvider);
1160
  }
1161

1162
  @Override
1163
  public String toString() {
1164
    return "WorkerOptions{"
×
1165
        + "maxWorkerActivitiesPerSecond="
1166
        + maxWorkerActivitiesPerSecond
1167
        + ", maxConcurrentActivityExecutionSize="
1168
        + maxConcurrentActivityExecutionSize
1169
        + ", maxConcurrentWorkflowTaskExecutionSize="
1170
        + maxConcurrentWorkflowTaskExecutionSize
1171
        + ", maxConcurrentLocalActivityExecutionSize="
1172
        + maxConcurrentLocalActivityExecutionSize
1173
        + ", maxConcurrentNexusExecutionSize="
1174
        + maxConcurrentNexusExecutionSize
1175
        + ", workerTuner="
1176
        + workerTuner
1177
        + ", maxTaskQueueActivitiesPerSecond="
1178
        + maxTaskQueueActivitiesPerSecond
1179
        + ", maxConcurrentWorkflowTaskPollers="
1180
        + maxConcurrentWorkflowTaskPollers
1181
        + ", maxConcurrentActivityTaskPollers="
1182
        + maxConcurrentActivityTaskPollers
1183
        + ", maxConcurrentNexusTaskPollers="
1184
        + maxConcurrentNexusTaskPollers
1185
        + ", localActivityWorkerOnly="
1186
        + localActivityWorkerOnly
1187
        + ", defaultDeadlockDetectionTimeout="
1188
        + defaultDeadlockDetectionTimeout
1189
        + ", maxHeartbeatThrottleInterval="
1190
        + maxHeartbeatThrottleInterval
1191
        + ", defaultHeartbeatThrottleInterval="
1192
        + defaultHeartbeatThrottleInterval
1193
        + ", stickyQueueScheduleToStartTimeout="
1194
        + stickyQueueScheduleToStartTimeout
1195
        + ", disableEagerExecution="
1196
        + disableEagerExecution
1197
        + ", maxEagerActivityReservationsPerWorkflowTask="
1198
        + maxEagerActivityReservationsPerWorkflowTask
1199
        + ", useBuildIdForVersioning="
1200
        + useBuildIdForVersioning
1201
        + ", buildId='"
1202
        + buildId
1203
        + '\''
1204
        + ", stickyTaskQueueDrainTimeout="
1205
        + stickyTaskQueueDrainTimeout
1206
        + ", identity="
1207
        + identity
1208
        + ", usingVirtualThreadsOnWorkflowWorker="
1209
        + usingVirtualThreadsOnWorkflowWorker
1210
        + ", usingVirtualThreadsOnActivityWorker="
1211
        + usingVirtualThreadsOnActivityWorker
1212
        + ", usingVirtualThreadsOnLocalActivityWorker="
1213
        + usingVirtualThreadsOnLocalActivityWorker
1214
        + ", usingVirtualThreadsOnNexusWorker="
1215
        + usingVirtualThreadsOnNexusWorker
1216
        + ", deploymentOptions="
1217
        + deploymentOptions
1218
        + ", workflowTaskPollersBehavior="
1219
        + workflowTaskPollersBehavior
1220
        + ", activityTaskPollersBehavior="
1221
        + activityTaskPollersBehavior
1222
        + ", nexusTaskPollersBehavior="
1223
        + nexusTaskPollersBehavior
1224
        + ", allowActivityHeartbeatDuringShutdown="
1225
        + allowActivityHeartbeatDuringShutdown
1226
        + ", preferredVersionProvider="
1227
        + preferredVersionProvider
1228
        + '}';
1229
  }
1230
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc