1717
1818package com .uber .cadence .client ;
1919
20+ import com .uber .cadence .context .ContextPropagator ;
2021import com .uber .cadence .converter .DataConverter ;
2122import com .uber .cadence .converter .JsonDataConverter ;
23+ import com .uber .cadence .internal .metrics .MetricsTag ;
2224import com .uber .cadence .internal .metrics .NoopScope ;
2325import com .uber .m3 .tally .Scope ;
26+ import com .uber .m3 .util .ImmutableMap ;
27+ import java .lang .management .ManagementFactory ;
28+ import java .util .Arrays ;
29+ import java .util .List ;
2430import java .util .Objects ;
2531
2632/** Options for WorkflowClient configuration. */
@@ -29,6 +35,7 @@ public final class WorkflowClientOptions {
2935 private static final WorkflowClientOptions DEFAULT_INSTANCE ;
3036 private static final WorkflowClientInterceptor [] EMPTY_INTERCEPTOR_ARRAY =
3137 new WorkflowClientInterceptor [0 ];
38+ private static final List <ContextPropagator > EMPTY_CONTEXT_PROPAGATORS = Arrays .asList ();
3239
3340 static {
3441 DEFAULT_INSTANCE = new Builder ().build ();
@@ -51,6 +58,8 @@ public static final class Builder {
5158 private DataConverter dataConverter = JsonDataConverter .getInstance ();
5259 private WorkflowClientInterceptor [] interceptors = EMPTY_INTERCEPTOR_ARRAY ;
5360 private Scope metricsScope = NoopScope .getInstance ();
61+ private String identity = ManagementFactory .getRuntimeMXBean ().getName ();;
62+ private List <ContextPropagator > contextPropagators = EMPTY_CONTEXT_PROPAGATORS ;
5463
5564 private Builder () {}
5665
@@ -59,6 +68,7 @@ private Builder(WorkflowClientOptions options) {
5968 dataConverter = options .getDataConverter ();
6069 interceptors = options .getInterceptors ();
6170 metricsScope = options .getMetricsScope ();
71+ identity = options .getIdentity ();
6272 }
6373
6474 public Builder setDomain (String domain ) {
@@ -97,25 +107,49 @@ public Builder setMetricsScope(Scope metricsScope) {
97107 return this ;
98108 }
99109
110+ /**
111+ * Override human readable identity of the worker. Identity is used to identify a worker and is
112+ * recorded in the workflow history events. For example when a worker gets an activity task the
113+ * correspondent ActivityTaskStarted event contains the worker identity as a field. Default is
114+ * whatever <code>(ManagementFactory.getRuntimeMXBean().getName()</code> returns.
115+ */
116+ public Builder setIdentity (String identity ) {
117+ this .identity = Objects .requireNonNull (identity );
118+ return this ;
119+ }
120+
121+ public Builder setContextPropagators (List <ContextPropagator > contextPropagators ) {
122+ this .contextPropagators = contextPropagators ;
123+ return this ;
124+ }
125+
100126 public WorkflowClientOptions build () {
101- return new WorkflowClientOptions (domain , dataConverter , interceptors , metricsScope );
127+ metricsScope = metricsScope .tagged (ImmutableMap .of (MetricsTag .DOMAIN , domain ));
128+ return new WorkflowClientOptions (
129+ domain , dataConverter , interceptors , metricsScope , identity , contextPropagators );
102130 }
103131 }
104132
105133 private final String domain ;
106134 private final DataConverter dataConverter ;
107135 private final WorkflowClientInterceptor [] interceptors ;
108136 private final Scope metricsScope ;
137+ private String identity ;
138+ private List <ContextPropagator > contextPropagators ;
109139
110140 private WorkflowClientOptions (
111141 String domain ,
112142 DataConverter dataConverter ,
113143 WorkflowClientInterceptor [] interceptors ,
114- Scope metricsScope ) {
144+ Scope metricsScope ,
145+ String identity ,
146+ List <ContextPropagator > contextPropagators ) {
115147 this .domain = domain ;
116148 this .dataConverter = dataConverter ;
117149 this .interceptors = interceptors ;
118150 this .metricsScope = metricsScope ;
151+ this .identity = identity ;
152+ this .contextPropagators = contextPropagators ;
119153 }
120154
121155 public String getDomain () {
@@ -133,4 +167,12 @@ public WorkflowClientInterceptor[] getInterceptors() {
133167 public Scope getMetricsScope () {
134168 return metricsScope ;
135169 }
170+
171+ public String getIdentity () {
172+ return identity ;
173+ }
174+
175+ public List <ContextPropagator > getContextPropagators () {
176+ return contextPropagators ;
177+ }
136178}
0 commit comments