17
17
18
18
package com .uber .cadence .client ;
19
19
20
+ import com .uber .cadence .context .ContextPropagator ;
20
21
import com .uber .cadence .converter .DataConverter ;
21
22
import com .uber .cadence .converter .JsonDataConverter ;
23
+ import com .uber .cadence .internal .metrics .MetricsTag ;
22
24
import com .uber .cadence .internal .metrics .NoopScope ;
23
25
import 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 ;
24
30
import java .util .Objects ;
25
31
26
32
/** Options for WorkflowClient configuration. */
@@ -29,6 +35,7 @@ public final class WorkflowClientOptions {
29
35
private static final WorkflowClientOptions DEFAULT_INSTANCE ;
30
36
private static final WorkflowClientInterceptor [] EMPTY_INTERCEPTOR_ARRAY =
31
37
new WorkflowClientInterceptor [0 ];
38
+ private static final List <ContextPropagator > EMPTY_CONTEXT_PROPAGATORS = Arrays .asList ();
32
39
33
40
static {
34
41
DEFAULT_INSTANCE = new Builder ().build ();
@@ -51,6 +58,8 @@ public static final class Builder {
51
58
private DataConverter dataConverter = JsonDataConverter .getInstance ();
52
59
private WorkflowClientInterceptor [] interceptors = EMPTY_INTERCEPTOR_ARRAY ;
53
60
private Scope metricsScope = NoopScope .getInstance ();
61
+ private String identity = ManagementFactory .getRuntimeMXBean ().getName ();;
62
+ private List <ContextPropagator > contextPropagators = EMPTY_CONTEXT_PROPAGATORS ;
54
63
55
64
private Builder () {}
56
65
@@ -59,6 +68,7 @@ private Builder(WorkflowClientOptions options) {
59
68
dataConverter = options .getDataConverter ();
60
69
interceptors = options .getInterceptors ();
61
70
metricsScope = options .getMetricsScope ();
71
+ identity = options .getIdentity ();
62
72
}
63
73
64
74
public Builder setDomain (String domain ) {
@@ -97,25 +107,49 @@ public Builder setMetricsScope(Scope metricsScope) {
97
107
return this ;
98
108
}
99
109
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
+
100
126
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 );
102
130
}
103
131
}
104
132
105
133
private final String domain ;
106
134
private final DataConverter dataConverter ;
107
135
private final WorkflowClientInterceptor [] interceptors ;
108
136
private final Scope metricsScope ;
137
+ private String identity ;
138
+ private List <ContextPropagator > contextPropagators ;
109
139
110
140
private WorkflowClientOptions (
111
141
String domain ,
112
142
DataConverter dataConverter ,
113
143
WorkflowClientInterceptor [] interceptors ,
114
- Scope metricsScope ) {
144
+ Scope metricsScope ,
145
+ String identity ,
146
+ List <ContextPropagator > contextPropagators ) {
115
147
this .domain = domain ;
116
148
this .dataConverter = dataConverter ;
117
149
this .interceptors = interceptors ;
118
150
this .metricsScope = metricsScope ;
151
+ this .identity = identity ;
152
+ this .contextPropagators = contextPropagators ;
119
153
}
120
154
121
155
public String getDomain () {
@@ -133,4 +167,12 @@ public WorkflowClientInterceptor[] getInterceptors() {
133
167
public Scope getMetricsScope () {
134
168
return metricsScope ;
135
169
}
170
+
171
+ public String getIdentity () {
172
+ return identity ;
173
+ }
174
+
175
+ public List <ContextPropagator > getContextPropagators () {
176
+ return contextPropagators ;
177
+ }
136
178
}
0 commit comments