11package io .temporal .client ;
22
3+ import io .temporal .common .Experimental ;
34import io .temporal .common .context .ContextPropagator ;
45import io .temporal .common .converter .DataConverter ;
56import io .temporal .common .converter .GlobalDataConverter ;
67import io .temporal .common .interceptors .ActivityClientInterceptor ;
78import java .lang .management .ManagementFactory ;
9+ import java .util .Arrays ;
810import java .util .Collections ;
911import java .util .List ;
1012import java .util .Objects ;
@@ -40,12 +42,14 @@ public static final class Builder {
4042 Collections .emptyList ();
4143 private static final List <ActivityClientInterceptor > EMPTY_INTERCEPTORS =
4244 Collections .emptyList ();
45+ private static final ActivityClientPlugin [] EMPTY_PLUGINS = new ActivityClientPlugin [0 ];
4346
4447 private String namespace ;
4548 private DataConverter dataConverter ;
4649 private String identity ;
4750 private List <ContextPropagator > contextPropagators ;
4851 private List <ActivityClientInterceptor > interceptors ;
52+ private ActivityClientPlugin [] plugins ;
4953
5054 private Builder () {}
5155
@@ -58,6 +62,7 @@ private Builder(ActivityClientOptions options) {
5862 identity = options .identity ;
5963 contextPropagators = options .contextPropagators ;
6064 interceptors = options .interceptors ;
65+ plugins = options .plugins ;
6166 }
6267
6368 /** Set the namespace this client will operate on. */
@@ -102,14 +107,26 @@ public Builder setInterceptors(List<ActivityClientInterceptor> interceptors) {
102107 return this ;
103108 }
104109
110+ /**
111+ * Set the plugins for this client.
112+ *
113+ * @param plugins specifies the plugins to use with the client.
114+ */
115+ @ Experimental
116+ public Builder setPlugins (ActivityClientPlugin ... plugins ) {
117+ this .plugins = plugins ;
118+ return this ;
119+ }
120+
105121 public ActivityClientOptions build () {
106122 String name = identity == null ? ManagementFactory .getRuntimeMXBean ().getName () : identity ;
107123 return new ActivityClientOptions (
108124 namespace == null ? DEFAULT_NAMESPACE : namespace ,
109125 dataConverter == null ? GlobalDataConverter .get () : dataConverter ,
110126 name ,
111127 contextPropagators == null ? EMPTY_CONTEXT_PROPAGATORS : contextPropagators ,
112- interceptors == null ? EMPTY_INTERCEPTORS : interceptors );
128+ interceptors == null ? EMPTY_INTERCEPTORS : interceptors ,
129+ plugins == null ? EMPTY_PLUGINS : plugins );
113130 }
114131 }
115132
@@ -118,18 +135,21 @@ public ActivityClientOptions build() {
118135 private final String identity ;
119136 private final List <ContextPropagator > contextPropagators ;
120137 private final List <ActivityClientInterceptor > interceptors ;
138+ private final ActivityClientPlugin [] plugins ;
121139
122140 private ActivityClientOptions (
123141 String namespace ,
124142 DataConverter dataConverter ,
125143 String identity ,
126144 List <ContextPropagator > contextPropagators ,
127- List <ActivityClientInterceptor > interceptors ) {
145+ List <ActivityClientInterceptor > interceptors ,
146+ ActivityClientPlugin [] plugins ) {
128147 this .namespace = namespace ;
129148 this .dataConverter = dataConverter ;
130149 this .identity = identity ;
131150 this .contextPropagators = contextPropagators ;
132151 this .interceptors = interceptors ;
152+ this .plugins = plugins ;
133153 }
134154
135155 /**
@@ -177,6 +197,16 @@ public List<ActivityClientInterceptor> getInterceptors() {
177197 return interceptors ;
178198 }
179199
200+ /**
201+ * Get the plugins of this client.
202+ *
203+ * @return The plugins to use with the client.
204+ */
205+ @ Experimental
206+ public ActivityClientPlugin [] getPlugins () {
207+ return Arrays .copyOf (plugins , plugins .length );
208+ }
209+
180210 @ Override
181211 public boolean equals (Object o ) {
182212 if (this == o ) return true ;
@@ -186,12 +216,14 @@ public boolean equals(Object o) {
186216 && Objects .equals (dataConverter , that .dataConverter )
187217 && Objects .equals (identity , that .identity )
188218 && Objects .equals (contextPropagators , that .contextPropagators )
189- && Objects .equals (interceptors , that .interceptors );
219+ && Objects .equals (interceptors , that .interceptors )
220+ && Arrays .equals (plugins , that .plugins );
190221 }
191222
192223 @ Override
193224 public int hashCode () {
194- return Objects .hash (namespace , dataConverter , identity , contextPropagators , interceptors );
225+ return 31 * Objects .hash (namespace , dataConverter , identity , contextPropagators , interceptors )
226+ + Arrays .hashCode (plugins );
195227 }
196228
197229 @ Override
@@ -209,6 +241,8 @@ public String toString() {
209241 + contextPropagators
210242 + ", interceptors="
211243 + interceptors
244+ + ", plugins="
245+ + Arrays .toString (plugins )
212246 + '}' ;
213247 }
214248}
0 commit comments