@@ -266,6 +266,7 @@ public abstract static class Builder<
266
266
@ Nonnull private ApiTracerFactory tracerFactory ;
267
267
private boolean deprecatedExecutorProviderSet ;
268
268
private String universeDomain ;
269
+ private final EndpointContext endpointContext ;
269
270
270
271
/**
271
272
* Indicate when creating transport whether it is allowed to use mTLS endpoint instead of the
@@ -300,6 +301,9 @@ protected Builder(StubSettings settings) {
300
301
this .switchToMtlsEndpointAllowed =
301
302
settings .getEndpointContext ().switchToMtlsEndpointAllowed ();
302
303
this .universeDomain = settings .getEndpointContext ().universeDomain ();
304
+ // Store the EndpointContext that was already created. This is used to return the state
305
+ // of the EndpointContext prior to any new modifications
306
+ this .endpointContext = settings .getEndpointContext ();
303
307
}
304
308
305
309
/** Get Quota Project ID from Client Context * */
@@ -327,16 +331,22 @@ protected Builder(ClientContext clientContext) {
327
331
this .headerProvider = new NoHeaderProvider ();
328
332
this .internalHeaderProvider = new NoHeaderProvider ();
329
333
this .clock = NanoClock .getDefaultClock ();
330
- this .clientSettingsEndpoint = null ;
331
- this .transportChannelProviderEndpoint = null ;
332
- this .mtlsEndpoint = null ;
333
334
this .quotaProjectId = null ;
334
335
this .streamWatchdogProvider = InstantiatingWatchdogProvider .create ();
335
336
this .streamWatchdogCheckInterval = Duration .ofSeconds (10 );
336
337
this .tracerFactory = BaseApiTracerFactory .getInstance ();
337
338
this .deprecatedExecutorProviderSet = false ;
338
339
this .gdchApiAudience = null ;
340
+
341
+ this .clientSettingsEndpoint = null ;
342
+ this .transportChannelProviderEndpoint = null ;
343
+ this .mtlsEndpoint = null ;
344
+ this .switchToMtlsEndpointAllowed = false ;
339
345
this .universeDomain = null ;
346
+ // Attempt to create an empty, non-functioning EndpointContext by default. The client will
347
+ // have
348
+ // a valid EndpointContext with user configurations after the client has been initialized.
349
+ this .endpointContext = EndpointContext .getDefaultInstance ();
340
350
} else {
341
351
ExecutorProvider fixedExecutorProvider =
342
352
FixedExecutorProvider .create (clientContext .getExecutor ());
@@ -365,6 +375,9 @@ protected Builder(ClientContext clientContext) {
365
375
this .switchToMtlsEndpointAllowed =
366
376
clientContext .getEndpointContext ().switchToMtlsEndpointAllowed ();
367
377
this .universeDomain = clientContext .getEndpointContext ().universeDomain ();
378
+ // Store the EndpointContext that was already created. This is used to return the state
379
+ // of the EndpointContext prior to any new modifications
380
+ this .endpointContext = clientContext .getEndpointContext ();
368
381
}
369
382
}
370
383
@@ -584,8 +597,19 @@ public ApiClock getClock() {
584
597
return clock ;
585
598
}
586
599
600
+ /**
601
+ * @return the resolved endpoint when the Builder was created. If invoked after
602
+ * `StubSettings.newBuilder()` is called, it will return the clientSettingsEndpoint value.
603
+ * If other parameters are then set in the builder, the resolved endpoint is not
604
+ * automatically updated. The resolved endpoint will only be recomputed when the
605
+ * StubSettings is built again.
606
+ */
587
607
public String getEndpoint () {
588
- return clientSettingsEndpoint ;
608
+ // For the `StubSettings.newBuilder()` case
609
+ if (endpointContext .equals (EndpointContext .getDefaultInstance ())) {
610
+ return clientSettingsEndpoint ;
611
+ }
612
+ return endpointContext .resolvedEndpoint ();
589
613
}
590
614
591
615
public String getMtlsEndpoint () {
0 commit comments