@@ -10,7 +10,9 @@ namespace Microsoft.DurableTask.Worker;
1010/// </summary>
1111public class DurableTaskWorkerOptions
1212{
13- DataConverter dataConverter = JsonDataConverter . Default ;
13+ DataConverter ? dataConverter ;
14+ bool ? enableEntitySupport ;
15+ TimeSpan ? maximumTimerInterval ;
1416
1517 /// <summary>
1618 /// Gets or sets the data converter. Default value is <see cref="JsonDataConverter.Default" />.
@@ -28,27 +30,19 @@ public class DurableTaskWorkerOptions
2830 /// </remarks>
2931 public DataConverter DataConverter
3032 {
31- get => this . dataConverter ;
32- set
33- {
34- if ( value is null )
35- {
36- this . dataConverter = JsonDataConverter . Default ;
37- this . DataConverterExplicitlySet = false ;
38- }
39- else
40- {
41- this . dataConverter = value ;
42- this . DataConverterExplicitlySet = true ;
43- }
44- }
33+ get => this . dataConverter ?? JsonDataConverter . Default ;
34+ set => this . dataConverter = value ;
4535 }
4636
4737 /// <summary>
4838 /// Gets or sets a value indicating whether this client should support entities. If true, all instance ids starting
4939 /// with '@' are reserved for entities, and validation checks are performed where appropriate.
5040 /// </summary>
51- public bool EnableEntitySupport { get ; set ; }
41+ public bool EnableEntitySupport
42+ {
43+ get => this . enableEntitySupport ?? false ;
44+ set => this . enableEntitySupport = value ;
45+ }
5246
5347 /// <summary>
5448 /// Gets or sets the maximum timer interval for the
@@ -81,7 +75,11 @@ public DataConverter DataConverter
8175 /// orchestrations.
8276 /// </para>
8377 /// </remarks>
84- public TimeSpan MaximumTimerInterval { get ; set ; } = TimeSpan . FromDays ( 3 ) ;
78+ public TimeSpan MaximumTimerInterval
79+ {
80+ get => this . maximumTimerInterval ?? TimeSpan . FromDays ( 3 ) ;
81+ set => this . maximumTimerInterval = value ;
82+ }
8583
8684 /// <summary>
8785 /// Gets options for the Durable Task worker concurrency.
@@ -102,7 +100,7 @@ public DataConverter DataConverter
102100 /// will <b>not</b> resolve it. If not set, we will attempt to resolve it. This is so the
103101 /// behavior is consistently irrespective of option configuration ordering.
104102 /// </remarks>
105- internal bool DataConverterExplicitlySet { get ; private set ; }
103+ internal bool DataConverterExplicitlySet => this . dataConverter is not null ;
106104
107105 /// <summary>
108106 /// Applies these option values to another.
@@ -113,9 +111,18 @@ internal void ApplyTo(DurableTaskWorkerOptions other)
113111 if ( other is not null )
114112 {
115113 // Make sure to keep this up to date as values are added.
116- other . DataConverter = this . DataConverter ;
117- other . MaximumTimerInterval = this . MaximumTimerInterval ;
118- other . EnableEntitySupport = this . EnableEntitySupport ;
114+ ApplyIfSet ( this . dataConverter , ref other . dataConverter ) ;
115+ ApplyIfSet ( this . enableEntitySupport , ref other . enableEntitySupport ) ;
116+ ApplyIfSet ( this . maximumTimerInterval , ref other . maximumTimerInterval ) ;
117+ this . Concurrency . ApplyTo ( other . Concurrency ) ;
118+ }
119+ }
120+
121+ static void ApplyIfSet < T > ( T ? value , ref T ? target )
122+ {
123+ if ( value is not null && target is null )
124+ {
125+ target = value ;
119126 }
120127 }
121128
@@ -124,19 +131,51 @@ internal void ApplyTo(DurableTaskWorkerOptions other)
124131 /// </summary>
125132 public class ConcurrencyOptions
126133 {
134+ static readonly int DefaultMaxConcurrency = 100 * Environment . ProcessorCount ;
135+
136+ int ? maxActivity ;
137+ int ? maxOrchestration ;
138+ int ? maxEntity ;
139+
127140 /// <summary>
128141 /// Gets or sets the maximum number of concurrent activity work items that can be processed by the worker.
129142 /// </summary>
130- public int MaximumConcurrentActivityWorkItems { get ; set ; } = 100 * Environment . ProcessorCount ;
143+ public int MaximumConcurrentActivityWorkItems
144+ {
145+ get => this . maxActivity ?? DefaultMaxConcurrency ;
146+ set => this . maxActivity = value ;
147+ }
131148
132149 /// <summary>
133150 /// Gets or sets the maximum number of concurrent orchestration work items that can be processed by the worker.
134151 /// </summary>
135- public int MaximumConcurrentOrchestrationWorkItems { get ; set ; } = 100 * Environment . ProcessorCount ;
152+ public int MaximumConcurrentOrchestrationWorkItems
153+ {
154+ get => this . maxOrchestration ?? DefaultMaxConcurrency ;
155+ set => this . maxOrchestration = value ;
156+ }
136157
137158 /// <summary>
138159 /// Gets or sets the maximum number of concurrent entity work items that can be processed by the worker.
139160 /// </summary>
140- public int MaximumConcurrentEntityWorkItems { get ; set ; } = 100 * Environment . ProcessorCount ;
161+ public int MaximumConcurrentEntityWorkItems
162+ {
163+ get => this . maxEntity ?? DefaultMaxConcurrency ;
164+ set => this . maxEntity = value ;
165+ }
166+
167+ /// <summary>
168+ /// Applies these option values to another.
169+ /// </summary>
170+ /// <param name="other">The options to apply this options values to.</param>
171+ internal void ApplyTo ( ConcurrencyOptions other )
172+ {
173+ if ( other is not null )
174+ {
175+ ApplyIfSet ( this . maxActivity , ref other . maxActivity ) ;
176+ ApplyIfSet ( this . maxOrchestration , ref other . maxOrchestration ) ;
177+ ApplyIfSet ( this . maxEntity , ref other . maxEntity ) ;
178+ }
179+ }
141180 }
142181}
0 commit comments