23
23
import com .uber .cadence .internal .metrics .NoopScope ;
24
24
import com .uber .cadence .serviceclient .auth .IAuthorizationProvider ;
25
25
import com .uber .m3 .tally .Scope ;
26
+ import io .grpc .ManagedChannel ;
26
27
import java .util .Map ;
27
28
28
29
public class ClientOptions {
30
+
29
31
private static final int DEFAULT_LOCAL_CADENCE_SERVER_PORT = 7933 ;
30
32
31
33
private static final String LOCALHOST = "127.0.0.1" ;
32
34
33
- /** Default RPC timeout used for all non long poll calls. */
35
+ /**
36
+ * Default RPC timeout used for all non long poll calls.
37
+ */
34
38
private static final long DEFAULT_RPC_TIMEOUT_MILLIS = 3 * 1000 ;
35
- /** Default RPC timeout used for all long poll calls. */
39
+ /**
40
+ * Default RPC timeout used for all long poll calls.
41
+ */
36
42
private static final long DEFAULT_POLL_RPC_TIMEOUT_MILLIS = 30 * 1000 ;
37
43
38
- /** Default RPC timeout for QueryWorkflow */
44
+ /**
45
+ * Default RPC timeout for QueryWorkflow
46
+ */
39
47
private static final long DEFAULT_QUERY_RPC_TIMEOUT_MILLIS = 10 * 1000 ;
40
48
41
- /** Default RPC timeout for ListArchivedWorkflow */
49
+ /**
50
+ * Default RPC timeout for ListArchivedWorkflow
51
+ */
42
52
private static final long DEFAULT_LIST_ARCHIVED_WORKFLOW_TIMEOUT_MILLIS = 180 * 1000 ;
43
53
44
54
private static final String DEFAULT_CLIENT_APP_NAME = "cadence-client" ;
45
55
46
- /** Name of the Cadence service front end as required by TChannel. */
56
+ /**
57
+ * Name of the Cadence service front end as required by TChannel.
58
+ */
47
59
private static final String DEFAULT_SERVICE_NAME = "cadence-frontend" ;
60
+ private static final ClientOptions DEFAULT_INSTANCE ;
61
+
62
+ static {
63
+ DEFAULT_INSTANCE = new Builder ().build ();
64
+ }
48
65
49
66
private final String host ;
50
67
private final int port ;
51
-
52
- /** The tChannel timeout in milliseconds */
68
+ private final ManagedChannel gRPCChannel ;
69
+ /**
70
+ * The tChannel timeout in milliseconds
71
+ */
53
72
private final long rpcTimeoutMillis ;
54
-
55
- /** The tChannel timeout for long poll calls in milliseconds */
73
+ /**
74
+ * The tChannel timeout for long poll calls in milliseconds
75
+ */
56
76
private final long rpcLongPollTimeoutMillis ;
57
-
58
- /** The tChannel timeout for query workflow call in milliseconds */
77
+ /**
78
+ * The tChannel timeout for query workflow call in milliseconds
79
+ */
59
80
private final long rpcQueryTimeoutMillis ;
60
-
61
- /** The tChannel timeout for list archived workflow call in milliseconds */
81
+ /**
82
+ * The tChannel timeout for list archived workflow call in milliseconds
83
+ */
62
84
private final long rpcListArchivedWorkflowTimeoutMillis ;
63
-
64
- /** TChannel service name that the Cadence service was started with. */
85
+ /**
86
+ * TChannel service name that the Cadence service was started with.
87
+ */
65
88
private final String serviceName ;
66
-
67
- /** Name of the service using the cadence-client. */
89
+ /**
90
+ * Name of the service using the cadence-client.
91
+ */
68
92
private final String clientAppName ;
69
-
70
- /** Client for metrics reporting. */
93
+ /**
94
+ * Client for metrics reporting.
95
+ */
71
96
private final Scope metricsScope ;
72
-
73
- /** Optional TChannel transport headers */
97
+ /**
98
+ * Optional TChannel transport headers
99
+ */
74
100
private final Map <String , String > transportHeaders ;
75
-
76
- /** Optional TChannel headers */
101
+ /**
102
+ * Optional TChannel headers
103
+ */
77
104
private final Map <String , String > headers ;
78
-
79
- /** Optional authorization provider */
105
+ /**
106
+ * Optional authorization provider
107
+ */
80
108
private final IAuthorizationProvider authProvider ;
81
-
82
- private static final ClientOptions DEFAULT_INSTANCE ;
83
-
84
- /** Optional Feature flags to turn on/off some Cadence features */
109
+ /**
110
+ * Optional Feature flags to turn on/off some Cadence features
111
+ */
85
112
private final FeatureFlags featureFlags ;
86
113
87
- static {
88
- DEFAULT_INSTANCE = new Builder ().build ();
89
- }
90
-
91
- public static ClientOptions defaultInstance () {
92
- return DEFAULT_INSTANCE ;
93
- }
94
-
95
- public static Builder newBuilder () {
96
- return new Builder ();
97
- }
98
-
99
114
private ClientOptions (Builder builder ) {
100
115
if (Strings .isNullOrEmpty (builder .host )) {
101
116
host =
@@ -105,8 +120,8 @@ private ClientOptions(Builder builder) {
105
120
} else {
106
121
host = builder .host ;
107
122
}
108
-
109
123
this .port = builder .port ;
124
+ this .gRPCChannel = builder .gRPCChannel ;
110
125
this .rpcTimeoutMillis = builder .rpcTimeoutMillis ;
111
126
if (builder .clientAppName == null ) {
112
127
this .clientAppName = DEFAULT_CLIENT_APP_NAME ;
@@ -141,6 +156,14 @@ private ClientOptions(Builder builder) {
141
156
this .authProvider = builder .authProvider ;
142
157
}
143
158
159
+ public static ClientOptions defaultInstance () {
160
+ return DEFAULT_INSTANCE ;
161
+ }
162
+
163
+ public static Builder newBuilder () {
164
+ return new Builder ();
165
+ }
166
+
144
167
public String getHost () {
145
168
return host ;
146
169
}
@@ -149,27 +172,41 @@ public int getPort() {
149
172
return port ;
150
173
}
151
174
152
- /** @return Returns the rpc timeout value in millis. */
175
+ public ManagedChannel getGRPCChannel () {
176
+ return gRPCChannel ;
177
+ }
178
+
179
+ /**
180
+ * @return Returns the rpc timeout value in millis.
181
+ */
153
182
public long getRpcTimeoutMillis () {
154
183
return rpcTimeoutMillis ;
155
184
}
156
185
157
- /** @return Returns the rpc timout for long poll requests in millis. */
186
+ /**
187
+ * @return Returns the rpc timout for long poll requests in millis.
188
+ */
158
189
public long getRpcLongPollTimeoutMillis () {
159
190
return rpcLongPollTimeoutMillis ;
160
191
}
161
192
162
- /** @return Returns the rpc timout for query workflow requests in millis. */
193
+ /**
194
+ * @return Returns the rpc timout for query workflow requests in millis.
195
+ */
163
196
public long getRpcQueryTimeoutMillis () {
164
197
return rpcQueryTimeoutMillis ;
165
198
}
166
199
167
- /** @return Returns the rpc timout for list archived workflow requests in millis. */
200
+ /**
201
+ * @return Returns the rpc timout for list archived workflow requests in millis.
202
+ */
168
203
public long getRpcListArchivedWorkflowTimeoutMillis () {
169
204
return rpcListArchivedWorkflowTimeoutMillis ;
170
205
}
171
206
172
- /** Returns the client application name. */
207
+ /**
208
+ * Returns the client application name.
209
+ */
173
210
public String getClientAppName () {
174
211
return this .clientAppName ;
175
212
}
@@ -204,8 +241,10 @@ public FeatureFlags getFeatureFlags() {
204
241
* @author venkat
205
242
*/
206
243
public static class Builder {
244
+
207
245
private String host ;
208
246
private int port = DEFAULT_LOCAL_CADENCE_SERVER_PORT ;
247
+ private ManagedChannel gRPCChannel ;
209
248
private String clientAppName = DEFAULT_CLIENT_APP_NAME ;
210
249
private long rpcTimeoutMillis = DEFAULT_RPC_TIMEOUT_MILLIS ;
211
250
private long rpcLongPollTimeoutMillis = DEFAULT_POLL_RPC_TIMEOUT_MILLIS ;
@@ -219,7 +258,8 @@ public static class Builder {
219
258
private IAuthorizationProvider authProvider ;
220
259
private FeatureFlags featureFlags ;
221
260
222
- private Builder () {}
261
+ private Builder () {
262
+ }
223
263
224
264
public Builder setHost (String host ) {
225
265
this .host = host ;
@@ -236,6 +276,14 @@ public Builder setPort(int port) {
236
276
return this ;
237
277
}
238
278
279
+ /**
280
+ * Sets gRPC channel to use. Exclusive with host and port.
281
+ */
282
+ public Builder setGRPCChannel (ManagedChannel gRPCChannel ) {
283
+ this .gRPCChannel = gRPCChannel ;
284
+ return this ;
285
+ }
286
+
239
287
/**
240
288
* Sets the rpc timeout value for non query and non long poll calls. Default is 1000.
241
289
*
@@ -278,6 +326,13 @@ public Builder setListArchivedWorkflowRpcTimeout(long timeoutMillis) {
278
326
return this ;
279
327
}
280
328
329
+ /**
330
+ * Returns the feature flags defined in ClientOptions
331
+ */
332
+ public FeatureFlags getFeatureFlags () {
333
+ return this .featureFlags ;
334
+ }
335
+
281
336
/**
282
337
* Sets the feature flags to turn on/off some Cadence features By default, all features under
283
338
* FeatureFlags are turned off.
@@ -289,11 +344,6 @@ public Builder setFeatureFlags(FeatureFlags featureFlags) {
289
344
return this ;
290
345
}
291
346
292
- /** Returns the feature flags defined in ClientOptions */
293
- public FeatureFlags getFeatureFlags () {
294
- return this .featureFlags ;
295
- }
296
-
297
347
/**
298
348
* Sets the client application name.
299
349
*
0 commit comments