11package io .temporal .client ;
22
33import io .temporal .api .enums .v1 .QueryRejectCondition ;
4+ import io .temporal .common .Experimental ;
45import io .temporal .common .context .ContextPropagator ;
56import io .temporal .common .converter .DataConverter ;
67import io .temporal .common .converter .GlobalDataConverter ;
@@ -47,6 +48,7 @@ public static final class Builder {
4748 private String binaryChecksum ;
4849 private List <ContextPropagator > contextPropagators ;
4950 private QueryRejectCondition queryRejectCondition ;
51+ private WorkflowClientPlugin [] plugins ;
5052
5153 private Builder () {}
5254
@@ -61,6 +63,7 @@ private Builder(WorkflowClientOptions options) {
6163 binaryChecksum = options .binaryChecksum ;
6264 contextPropagators = options .contextPropagators ;
6365 queryRejectCondition = options .queryRejectCondition ;
66+ plugins = options .plugins ;
6467 }
6568
6669 public Builder setNamespace (String namespace ) {
@@ -132,6 +135,24 @@ public Builder setQueryRejectCondition(QueryRejectCondition queryRejectCondition
132135 return this ;
133136 }
134137
138+ /**
139+ * Sets the workflow client plugins to use with this client. Plugins can modify client
140+ * configuration.
141+ *
142+ * <p>Plugins that also implement {@link io.temporal.worker.WorkerPlugin} are automatically
143+ * propagated to workers created from this client.
144+ *
145+ * @param plugins the workflow client plugins to use
146+ * @return this builder for chaining
147+ * @see WorkflowClientPlugin
148+ * @see io.temporal.worker.WorkerPlugin
149+ */
150+ @ Experimental
151+ public Builder setPlugins (WorkflowClientPlugin ... plugins ) {
152+ this .plugins = Objects .requireNonNull (plugins );
153+ return this ;
154+ }
155+
135156 public WorkflowClientOptions build () {
136157 return new WorkflowClientOptions (
137158 namespace ,
@@ -140,9 +161,21 @@ public WorkflowClientOptions build() {
140161 identity ,
141162 binaryChecksum ,
142163 contextPropagators ,
143- queryRejectCondition );
164+ queryRejectCondition ,
165+ plugins == null ? EMPTY_PLUGINS : plugins );
144166 }
145167
168+ /**
169+ * Validates options and builds with defaults applied.
170+ *
171+ * <p>Note: If plugins are configured via {@link #setPlugins(WorkflowClientPlugin...)}, they
172+ * will have an opportunity to modify options after this method is called, when the options are
173+ * passed to {@link WorkflowClient#newInstance}. This means validation performed here occurs
174+ * before plugin modifications. In most cases, users should simply call {@link #build()} and let
175+ * the client creation handle validation.
176+ *
177+ * @return validated options with defaults applied
178+ */
146179 public WorkflowClientOptions validateAndBuildWithDefaults () {
147180 String name = identity == null ? ManagementFactory .getRuntimeMXBean ().getName () : identity ;
148181 return new WorkflowClientOptions (
@@ -154,7 +187,8 @@ public WorkflowClientOptions validateAndBuildWithDefaults() {
154187 contextPropagators == null ? EMPTY_CONTEXT_PROPAGATORS : contextPropagators ,
155188 queryRejectCondition == null
156189 ? QueryRejectCondition .QUERY_REJECT_CONDITION_UNSPECIFIED
157- : queryRejectCondition );
190+ : queryRejectCondition ,
191+ plugins == null ? EMPTY_PLUGINS : plugins );
158192 }
159193 }
160194
@@ -163,6 +197,8 @@ public WorkflowClientOptions validateAndBuildWithDefaults() {
163197
164198 private static final List <ContextPropagator > EMPTY_CONTEXT_PROPAGATORS = Collections .emptyList ();
165199
200+ private static final WorkflowClientPlugin [] EMPTY_PLUGINS = new WorkflowClientPlugin [0 ];
201+
166202 private final String namespace ;
167203
168204 private final DataConverter dataConverter ;
@@ -177,21 +213,25 @@ public WorkflowClientOptions validateAndBuildWithDefaults() {
177213
178214 private final QueryRejectCondition queryRejectCondition ;
179215
216+ private final WorkflowClientPlugin [] plugins ;
217+
180218 private WorkflowClientOptions (
181219 String namespace ,
182220 DataConverter dataConverter ,
183221 WorkflowClientInterceptor [] interceptors ,
184222 String identity ,
185223 String binaryChecksum ,
186224 List <ContextPropagator > contextPropagators ,
187- QueryRejectCondition queryRejectCondition ) {
225+ QueryRejectCondition queryRejectCondition ,
226+ WorkflowClientPlugin [] plugins ) {
188227 this .namespace = namespace ;
189228 this .dataConverter = dataConverter ;
190229 this .interceptors = interceptors ;
191230 this .identity = identity ;
192231 this .binaryChecksum = binaryChecksum ;
193232 this .contextPropagators = contextPropagators ;
194233 this .queryRejectCondition = queryRejectCondition ;
234+ this .plugins = plugins ;
195235 }
196236
197237 /**
@@ -236,6 +276,19 @@ public QueryRejectCondition getQueryRejectCondition() {
236276 return queryRejectCondition ;
237277 }
238278
279+ /**
280+ * Returns the workflow client plugins configured for this client.
281+ *
282+ * <p>Plugins that also implement {@link io.temporal.worker.WorkerPlugin} are automatically
283+ * propagated to workers created from this client.
284+ *
285+ * @return the array of workflow client plugins, never null
286+ */
287+ @ Experimental
288+ public WorkflowClientPlugin [] getPlugins () {
289+ return plugins ;
290+ }
291+
239292 @ Override
240293 public String toString () {
241294 return "WorkflowClientOptions{"
@@ -256,6 +309,8 @@ public String toString() {
256309 + contextPropagators
257310 + ", queryRejectCondition="
258311 + queryRejectCondition
312+ + ", plugins="
313+ + Arrays .toString (plugins )
259314 + '}' ;
260315 }
261316
@@ -270,7 +325,8 @@ public boolean equals(Object o) {
270325 && com .google .common .base .Objects .equal (identity , that .identity )
271326 && com .google .common .base .Objects .equal (binaryChecksum , that .binaryChecksum )
272327 && com .google .common .base .Objects .equal (contextPropagators , that .contextPropagators )
273- && queryRejectCondition == that .queryRejectCondition ;
328+ && queryRejectCondition == that .queryRejectCondition
329+ && Arrays .equals (plugins , that .plugins );
274330 }
275331
276332 @ Override
@@ -282,6 +338,7 @@ public int hashCode() {
282338 identity ,
283339 binaryChecksum ,
284340 contextPropagators ,
285- queryRejectCondition );
341+ queryRejectCondition ,
342+ Arrays .hashCode (plugins ));
286343 }
287344}
0 commit comments