44
55import com .google .common .base .Preconditions ;
66import io .temporal .common .Experimental ;
7+ import io .temporal .internal .Config ;
78import io .temporal .serviceclient .WorkflowServiceStubsOptions ;
89import io .temporal .worker .tuning .*;
910import java .time .Duration ;
@@ -64,6 +65,7 @@ public static final class Builder {
6465 private Duration defaultHeartbeatThrottleInterval ;
6566 private Duration stickyQueueScheduleToStartTimeout ;
6667 private boolean disableEagerExecution ;
68+ private int maxEagerActivityReservationsPerWorkflowTask = Config .EAGER_ACTIVITIES_LIMIT ;
6769 private String buildId ;
6870 private boolean useBuildIdForVersioning ;
6971 private Duration stickyTaskQueueDrainTimeout ;
@@ -109,6 +111,8 @@ private Builder(WorkerOptions o) {
109111 this .defaultHeartbeatThrottleInterval = o .defaultHeartbeatThrottleInterval ;
110112 this .stickyQueueScheduleToStartTimeout = o .stickyQueueScheduleToStartTimeout ;
111113 this .disableEagerExecution = o .disableEagerExecution ;
114+ this .maxEagerActivityReservationsPerWorkflowTask =
115+ o .maxEagerActivityReservationsPerWorkflowTask ;
112116 this .useBuildIdForVersioning = o .useBuildIdForVersioning ;
113117 this .buildId = o .buildId ;
114118 this .stickyTaskQueueDrainTimeout = o .stickyTaskQueueDrainTimeout ;
@@ -400,6 +404,20 @@ public Builder setDisableEagerExecution(boolean disableEagerExecution) {
400404 return this ;
401405 }
402406
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 =
417+ maxEagerActivityReservationsPerWorkflowTask ;
418+ return this ;
419+ }
420+
403421 /**
404422 * Opts the worker in to the Build-ID-based versioning feature. This ensures that the worker
405423 * will only receive tasks which it is compatible with.
@@ -623,6 +641,7 @@ public WorkerOptions build() {
623641 defaultHeartbeatThrottleInterval ,
624642 stickyQueueScheduleToStartTimeout ,
625643 disableEagerExecution ,
644+ maxEagerActivityReservationsPerWorkflowTask ,
626645 useBuildIdForVersioning ,
627646 buildId ,
628647 stickyTaskQueueDrainTimeout ,
@@ -647,6 +666,10 @@ public WorkerOptions validateAndBuildWithDefaults() {
647666 maxWorkerActivitiesPerSecond >= 0 , "negative maxActivitiesPerSecond" );
648667 Preconditions .checkState (
649668 maxConcurrentActivityExecutionSize >= 0 , "negative maxConcurrentActivityExecutionSize" );
669+ Preconditions .checkState (
670+ maxEagerActivityReservationsPerWorkflowTask > 0 ,
671+ "maxEagerActivityReservationsPerWorkflowTask must be positive; use "
672+ + "setDisableEagerExecution(true) to disable eager activity execution" );
650673 Preconditions .checkState (
651674 maxConcurrentWorkflowTaskExecutionSize >= 0 ,
652675 "negative maxConcurrentWorkflowTaskExecutionSize" );
@@ -758,6 +781,7 @@ public WorkerOptions validateAndBuildWithDefaults() {
758781 ? DEFAULT_STICKY_SCHEDULE_TO_START_TIMEOUT
759782 : stickyQueueScheduleToStartTimeout ,
760783 disableEagerExecution ,
784+ maxEagerActivityReservationsPerWorkflowTask ,
761785 useBuildIdForVersioning ,
762786 buildId ,
763787 stickyTaskQueueDrainTimeout == null
@@ -796,6 +820,7 @@ public WorkerOptions validateAndBuildWithDefaults() {
796820 private final Duration defaultHeartbeatThrottleInterval ;
797821 private final @ Nonnull Duration stickyQueueScheduleToStartTimeout ;
798822 private final boolean disableEagerExecution ;
823+ private final int maxEagerActivityReservationsPerWorkflowTask ;
799824 private final boolean useBuildIdForVersioning ;
800825 private final String buildId ;
801826 private final Duration stickyTaskQueueDrainTimeout ;
@@ -831,6 +856,7 @@ private WorkerOptions(
831856 Duration defaultHeartbeatThrottleInterval ,
832857 @ Nonnull Duration stickyQueueScheduleToStartTimeout ,
833858 boolean disableEagerExecution ,
859+ int maxEagerActivityReservationsPerWorkflowTask ,
834860 boolean useBuildIdForVersioning ,
835861 String buildId ,
836862 Duration stickyTaskQueueDrainTimeout ,
@@ -864,6 +890,7 @@ private WorkerOptions(
864890 this .defaultHeartbeatThrottleInterval = defaultHeartbeatThrottleInterval ;
865891 this .stickyQueueScheduleToStartTimeout = stickyQueueScheduleToStartTimeout ;
866892 this .disableEagerExecution = maxTaskQueueActivitiesPerSecond > 0 ? true : disableEagerExecution ;
893+ this .maxEagerActivityReservationsPerWorkflowTask = maxEagerActivityReservationsPerWorkflowTask ;
867894 this .useBuildIdForVersioning = useBuildIdForVersioning ;
868895 this .buildId = buildId ;
869896 this .stickyTaskQueueDrainTimeout = stickyTaskQueueDrainTimeout ;
@@ -989,6 +1016,10 @@ public boolean isEagerExecutionDisabled() {
9891016 return disableEagerExecution ;
9901017 }
9911018
1019+ public int getMaxEagerActivityReservationsPerWorkflowTask () {
1020+ return maxEagerActivityReservationsPerWorkflowTask ;
1021+ }
1022+
9921023 public boolean isUsingBuildIdForVersioning () {
9931024 return useBuildIdForVersioning ;
9941025 }
@@ -1070,6 +1101,8 @@ && compare(maxTaskQueueActivitiesPerSecond, that.maxTaskQueueActivitiesPerSecond
10701101 && localActivityWorkerOnly == that .localActivityWorkerOnly
10711102 && defaultDeadlockDetectionTimeout == that .defaultDeadlockDetectionTimeout
10721103 && disableEagerExecution == that .disableEagerExecution
1104+ && maxEagerActivityReservationsPerWorkflowTask
1105+ == that .maxEagerActivityReservationsPerWorkflowTask
10731106 && useBuildIdForVersioning == that .useBuildIdForVersioning
10741107 && Objects .equals (workerTuner , that .workerTuner )
10751108 && Objects .equals (maxHeartbeatThrottleInterval , that .maxHeartbeatThrottleInterval )
@@ -1109,6 +1142,7 @@ public int hashCode() {
11091142 defaultHeartbeatThrottleInterval ,
11101143 stickyQueueScheduleToStartTimeout ,
11111144 disableEagerExecution ,
1145+ maxEagerActivityReservationsPerWorkflowTask ,
11121146 useBuildIdForVersioning ,
11131147 buildId ,
11141148 stickyTaskQueueDrainTimeout ,
@@ -1160,6 +1194,8 @@ public String toString() {
11601194 + stickyQueueScheduleToStartTimeout
11611195 + ", disableEagerExecution="
11621196 + disableEagerExecution
1197+ + ", maxEagerActivityReservationsPerWorkflowTask="
1198+ + maxEagerActivityReservationsPerWorkflowTask
11631199 + ", useBuildIdForVersioning="
11641200 + useBuildIdForVersioning
11651201 + ", buildId='"
0 commit comments