21
21
22
22
import com .google .common .annotations .VisibleForTesting ;
23
23
import com .google .common .collect .ImmutableList ;
24
- import com .sun .javafx .UnmodifiableArrayList ;
25
24
import io .grpc .internal .ExponentialBackoffPolicy ;
26
25
import io .grpc .internal .GrpcUtil ;
27
26
import io .grpc .internal .ObjectPool ;
33
32
import io .grpc .xds .client .XdsClientImpl ;
34
33
import io .grpc .xds .client .XdsInitializationException ;
35
34
import io .grpc .xds .internal .security .TlsContextManagerImpl ;
36
- import java .util .List ;
37
35
import java .util .Map ;
38
36
import java .util .concurrent .ConcurrentHashMap ;
39
37
import java .util .concurrent .ScheduledExecutorService ;
@@ -57,8 +55,7 @@ final class SharedXdsClientPoolProvider implements XdsClientPoolFactory {
57
55
private final Bootstrapper bootstrapper ;
58
56
private final Object lock = new Object ();
59
57
private final AtomicReference <Map <String , ?>> bootstrapOverride = new AtomicReference <>();
60
- // private volatile ObjectPool<XdsClient> xdsClientPool;
61
- private Map <String , ObjectPool <XdsClient >> targetToXdsClientMap = new ConcurrentHashMap <>();
58
+ private final Map <String , ObjectPool <XdsClient >> targetToXdsClientMap = new ConcurrentHashMap <>();
62
59
63
60
SharedXdsClientPoolProvider () {
64
61
this (new GrpcBootstrapperImpl ());
@@ -101,7 +98,7 @@ public ObjectPool<XdsClient> getOrCreate(String target) throws XdsInitialization
101
98
if (bootstrapInfo .servers ().isEmpty ()) {
102
99
throw new XdsInitializationException ("No xDS server provided" );
103
100
}
104
- ref = new RefCountedXdsClientObjectPool (bootstrapInfo );
101
+ ref = new RefCountedXdsClientObjectPool (bootstrapInfo , target );
105
102
targetToXdsClientMap .put (target , ref );
106
103
}
107
104
}
@@ -122,7 +119,11 @@ private static class SharedXdsClientPoolProviderHolder {
122
119
@ ThreadSafe
123
120
@ VisibleForTesting
124
121
static class RefCountedXdsClientObjectPool implements ObjectPool <XdsClient > {
122
+
123
+ private static final ExponentialBackoffPolicy .Provider BACKOFF_POLICY_PROVIDER =
124
+ new ExponentialBackoffPolicy .Provider ();
125
125
private final BootstrapInfo bootstrapInfo ;
126
+ private final String target ; // The target associated with the xDS client.
126
127
private final Object lock = new Object ();
127
128
@ GuardedBy ("lock" )
128
129
private ScheduledExecutorService scheduler ;
@@ -132,8 +133,9 @@ static class RefCountedXdsClientObjectPool implements ObjectPool<XdsClient> {
132
133
private int refCount ;
133
134
134
135
@ VisibleForTesting
135
- RefCountedXdsClientObjectPool (BootstrapInfo bootstrapInfo ) {
136
+ RefCountedXdsClientObjectPool (BootstrapInfo bootstrapInfo , String target ) {
136
137
this .bootstrapInfo = checkNotNull (bootstrapInfo );
138
+ this .target = target ;
137
139
}
138
140
139
141
@ Override
@@ -144,15 +146,19 @@ public XdsClient getObject() {
144
146
log .log (Level .INFO , "xDS node ID: {0}" , bootstrapInfo .node ().getId ());
145
147
}
146
148
scheduler = SharedResourceHolder .get (GrpcUtil .TIMER_SERVICE );
147
- xdsClient = new XdsClientImpl (
148
- DEFAULT_XDS_TRANSPORT_FACTORY ,
149
- bootstrapInfo ,
150
- scheduler ,
151
- new ExponentialBackoffPolicy .Provider (),
152
- GrpcUtil .STOPWATCH_SUPPLIER ,
153
- TimeProvider .SYSTEM_TIME_PROVIDER ,
154
- MessagePrinter .INSTANCE ,
155
- new TlsContextManagerImpl (bootstrapInfo ));
149
+ try {
150
+ xdsClient = new XdsClientImpl (
151
+ DEFAULT_XDS_TRANSPORT_FACTORY ,
152
+ bootstrapInfo ,
153
+ scheduler ,
154
+ BACKOFF_POLICY_PROVIDER ,
155
+ GrpcUtil .STOPWATCH_SUPPLIER ,
156
+ TimeProvider .SYSTEM_TIME_PROVIDER ,
157
+ MessagePrinter .INSTANCE ,
158
+ new TlsContextManagerImpl (bootstrapInfo ));
159
+ } catch (Exception e ) {
160
+ throw new RuntimeException (e );
161
+ }
156
162
}
157
163
refCount ++;
158
164
return xdsClient ;
@@ -179,5 +185,10 @@ XdsClient getXdsClientForTest() {
179
185
return xdsClient ;
180
186
}
181
187
}
188
+
189
+ public String getTarget () {
190
+ return target ;
191
+ }
182
192
}
193
+
183
194
}
0 commit comments