Package io.grpc.xds.client
Class XdsClientImpl
java.lang.Object
io.grpc.xds.client.XdsClient
io.grpc.xds.client.XdsClientImpl
- All Implemented Interfaces:
XdsClient.ResourceStore
,XdsClient.XdsResponseHandler
@Internal
public final class XdsClientImpl
extends XdsClient
implements XdsClient.XdsResponseHandler, XdsClient.ResourceStore
XdsClient implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
Tracks a single subscribed resource.Nested classes/interfaces inherited from class io.grpc.xds.client.XdsClient
XdsClient.ProcessingTracker, XdsClient.ResourceMetadata, XdsClient.ResourceStore, XdsClient.ResourceUpdate, XdsClient.ResourceWatcher<T extends XdsClient.ResourceUpdate>, XdsClient.XdsResponseHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final io.grpc.internal.BackoffPolicy.Provider
private final Bootstrapper.BootstrapInfo
static final int
private boolean
private final Map
<Bootstrapper.ServerInfo, LoadStatsManager2> private final XdsLogger
private final io.grpc.InternalLogId
private final MessagePrettyPrinter
private final Map
<XdsResourceType<? extends XdsClient.ResourceUpdate>, Map<String, XdsClientImpl.ResourceSubscriber<? extends XdsClient.ResourceUpdate>>> private final Object
private final Map
<Bootstrapper.ServerInfo, ControlPlaneClient> (package private) final Map
<Bootstrapper.ServerInfo, LoadReportClient> private final com.google.common.base.Supplier
<com.google.common.base.Stopwatch> private final Map
<String, XdsResourceType<?>> private final io.grpc.SynchronizationContext
private final io.grpc.internal.TimeProvider
private final ScheduledExecutorService
private final XdsTransportFactory
-
Constructor Summary
ConstructorsConstructorDescriptionXdsClientImpl
(XdsTransportFactory xdsTransportFactory, Bootstrapper.BootstrapInfo bootstrapInfo, ScheduledExecutorService timeService, io.grpc.internal.BackoffPolicy.Provider backoffPolicyProvider, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier, io.grpc.internal.TimeProvider timeProvider, MessagePrettyPrinter messagePrinter, Object securityConfig) -
Method Summary
Modifier and TypeMethodDescriptionaddClusterDropStats
(Bootstrapper.ServerInfo serverInfo, String clusterName, String edsServiceName) Adds drop stats for the specified cluster with edsServiceName by using the returned object to record dropped requests.addClusterLocalityStats
(Bootstrapper.ServerInfo serverInfo, String clusterName, String edsServiceName, Locality locality) Adds load stats for the specified locality (in the specified cluster with edsServiceName) by using the returned object to record RPCs.<T extends XdsClient.ResourceUpdate>
voidcancelXdsResourceWatch
(XdsResourceType<T> type, String resourceName, XdsClient.ResourceWatcher<T> watcher) Unregisters the given resource watcher.private void
Returns the config used to bootstrap this XdsClientBootstrapper.BootstrapInfo
.getOrCreateControlPlaneClient
(Bootstrapper.ServerInfo serverInfo) getResourceKeys
(XdsResourceType<?> xdsResourceType) Returns the implementation specific security configuration used in this XdsClient.private Bootstrapper.ServerInfo
getServerInfo
(String resource) Returns a map of control plane server info objects to the LoadReportClients that are responsible for sending load reports to the control plane servers.getSubscribedResources
(Bootstrapper.ServerInfo serverInfo, XdsResourceType<? extends XdsClient.ResourceUpdate> type) Returns the collection of resources currently subscribing to ornull
if not subscribing to any resources for the given type.com.google.common.util.concurrent.ListenableFuture
<Map<XdsResourceType<?>, Map<String, XdsClient.ResourceMetadata>>> Returns aListenableFuture
to the snapshot of the subscribed resources as they are at the moment of the call.Map
<String, XdsResourceType<?>> void
handleResourceResponse
(XdsResourceType<?> xdsResourceType, Bootstrapper.ServerInfo serverInfo, String versionInfo, List<com.google.protobuf.Any> resources, String nonce, XdsClient.ProcessingTracker processingTracker) Called when a xds response is received.private <T extends XdsClient.ResourceUpdate>
voidhandleResourceUpdate
(XdsResourceType.Args args, List<com.google.protobuf.Any> resources, XdsResourceType<T> xdsResourceType, XdsClient.ProcessingTracker processingTracker) void
handleStreamClosed
(io.grpc.Status error) Called when the ADS stream is closed passively.void
handleStreamRestarted
(Bootstrapper.ServerInfo serverInfo) Called when the ADS stream has been recreated.boolean
Returnstrue
ifXdsClient.shutdown()
has been called.void
shutdown()
Shutdown thisXdsClient
and release resources.protected void
startSubscriberTimersIfNeeded
(Bootstrapper.ServerInfo serverInfo) For all subscriber's for the specified server, if the resource hasn't yet been resolved then start a timer for it.toString()
<T extends XdsClient.ResourceUpdate>
voidwatchXdsResource
(XdsResourceType<T> type, String resourceName, XdsClient.ResourceWatcher<T> watcher, Executor watcherExecutor) Registers a data watcher for the given Xds resource.Methods inherited from class io.grpc.xds.client.XdsClient
canonifyResourceName, isResourceNameValid, percentEncodePath, watchXdsResource
-
Field Details
-
INITIAL_RESOURCE_FETCH_TIMEOUT_SEC
public static final int INITIAL_RESOURCE_FETCH_TIMEOUT_SEC- See Also:
-
syncContext
private final io.grpc.SynchronizationContext syncContext -
loadStatsManagerMap
-
serverLrsClientMap
-
serverCpClientMap
-
resourceSubscribers
private final Map<XdsResourceType<? extends XdsClient.ResourceUpdate>,Map<String, resourceSubscribersXdsClientImpl.ResourceSubscriber<? extends XdsClient.ResourceUpdate>>> -
subscribedResourceTypeUrls
-
xdsTransportFactory
-
bootstrapInfo
-
timeService
-
backoffPolicyProvider
private final io.grpc.internal.BackoffPolicy.Provider backoffPolicyProvider -
stopwatchSupplier
private final com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier -
timeProvider
private final io.grpc.internal.TimeProvider timeProvider -
securityConfig
-
logId
private final io.grpc.InternalLogId logId -
logger
-
isShutdown
private volatile boolean isShutdown -
messagePrinter
-
-
Constructor Details
-
XdsClientImpl
public XdsClientImpl(XdsTransportFactory xdsTransportFactory, Bootstrapper.BootstrapInfo bootstrapInfo, ScheduledExecutorService timeService, io.grpc.internal.BackoffPolicy.Provider backoffPolicyProvider, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier, io.grpc.internal.TimeProvider timeProvider, MessagePrettyPrinter messagePrinter, Object securityConfig)
-
-
Method Details
-
handleResourceResponse
public void handleResourceResponse(XdsResourceType<?> xdsResourceType, Bootstrapper.ServerInfo serverInfo, String versionInfo, List<com.google.protobuf.Any> resources, String nonce, XdsClient.ProcessingTracker processingTracker) Description copied from interface:XdsClient.XdsResponseHandler
Called when a xds response is received.- Specified by:
handleResourceResponse
in interfaceXdsClient.XdsResponseHandler
-
handleStreamClosed
public void handleStreamClosed(io.grpc.Status error) Description copied from interface:XdsClient.XdsResponseHandler
Called when the ADS stream is closed passively.- Specified by:
handleStreamClosed
in interfaceXdsClient.XdsResponseHandler
-
handleStreamRestarted
Description copied from interface:XdsClient.XdsResponseHandler
Called when the ADS stream has been recreated.- Specified by:
handleStreamRestarted
in interfaceXdsClient.XdsResponseHandler
-
shutdown
public void shutdown()Description copied from class:XdsClient
Shutdown thisXdsClient
and release resources. -
isShutDown
public boolean isShutDown()Description copied from class:XdsClient
Returnstrue
ifXdsClient.shutdown()
has been called.- Overrides:
isShutDown
in classXdsClient
-
getSubscribedResourceTypesWithTypeUrl
- Specified by:
getSubscribedResourceTypesWithTypeUrl
in interfaceXdsClient.ResourceStore
-
getSubscribedResources
@Nullable public Collection<String> getSubscribedResources(Bootstrapper.ServerInfo serverInfo, XdsResourceType<? extends XdsClient.ResourceUpdate> type) Description copied from interface:XdsClient.ResourceStore
Returns the collection of resources currently subscribing to ornull
if not subscribing to any resources for the given type.Note an empty collection indicates subscribing to resources of the given type with wildcard mode.
- Specified by:
getSubscribedResources
in interfaceXdsClient.ResourceStore
-
getSubscribedResourcesMetadataSnapshot
public com.google.common.util.concurrent.ListenableFuture<Map<XdsResourceType<?>,Map<String, getSubscribedResourcesMetadataSnapshot()XdsClient.ResourceMetadata>>> Description copied from class:XdsClient
Returns aListenableFuture
to the snapshot of the subscribed resources as they are at the moment of the call.The snapshot is a map from the "resource type" to a map ("resource name": "resource metadata").
- Overrides:
getSubscribedResourcesMetadataSnapshot
in classXdsClient
-
getSecurityConfig
Description copied from class:XdsClient
Returns the implementation specific security configuration used in this XdsClient.- Overrides:
getSecurityConfig
in classXdsClient
-
watchXdsResource
public <T extends XdsClient.ResourceUpdate> void watchXdsResource(XdsResourceType<T> type, String resourceName, XdsClient.ResourceWatcher<T> watcher, Executor watcherExecutor) Description copied from class:XdsClient
Registers a data watcher for the given Xds resource.- Overrides:
watchXdsResource
in classXdsClient
-
cancelXdsResourceWatch
public <T extends XdsClient.ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, String resourceName, XdsClient.ResourceWatcher<T> watcher) Description copied from class:XdsClient
Unregisters the given resource watcher.- Overrides:
cancelXdsResourceWatch
in classXdsClient
-
addClusterDropStats
public LoadStatsManager2.ClusterDropStats addClusterDropStats(Bootstrapper.ServerInfo serverInfo, String clusterName, @Nullable String edsServiceName) Description copied from class:XdsClient
Adds drop stats for the specified cluster with edsServiceName by using the returned object to record dropped requests. Drop stats recorded with the returned object will be reported to the load reporting server. The returned object is reference counted and the caller should useLoadStatsManager2.ClusterDropStats.release()
to release its hard reference when it is safe to stop reporting dropped RPCs for the specified cluster in the future.- Overrides:
addClusterDropStats
in classXdsClient
-
addClusterLocalityStats
public LoadStatsManager2.ClusterLocalityStats addClusterLocalityStats(Bootstrapper.ServerInfo serverInfo, String clusterName, @Nullable String edsServiceName, Locality locality) Description copied from class:XdsClient
Adds load stats for the specified locality (in the specified cluster with edsServiceName) by using the returned object to record RPCs. Load stats recorded with the returned object will be reported to the load reporting server. The returned object is reference counted and the caller should useLoadStatsManager2.ClusterLocalityStats.release()
to release its hard reference when it is safe to stop reporting RPC loads for the specified locality in the future.- Overrides:
addClusterLocalityStats
in classXdsClient
-
getBootstrapInfo
Description copied from class:XdsClient
Returns the config used to bootstrap this XdsClientBootstrapper.BootstrapInfo
.- Overrides:
getBootstrapInfo
in classXdsClient
-
toString
-
startSubscriberTimersIfNeeded
Description copied from class:XdsClient
For all subscriber's for the specified server, if the resource hasn't yet been resolved then start a timer for it.- Overrides:
startSubscriberTimersIfNeeded
in classXdsClient
-
getResourceKeys
-
cleanUpResourceTimers
private void cleanUpResourceTimers() -
getOrCreateControlPlaneClient
-
getServerLrsClientMap
Description copied from class:XdsClient
Returns a map of control plane server info objects to the LoadReportClients that are responsible for sending load reports to the control plane servers.- Overrides:
getServerLrsClientMap
in classXdsClient
-
getServerInfo
-
handleResourceUpdate
private <T extends XdsClient.ResourceUpdate> void handleResourceUpdate(XdsResourceType.Args args, List<com.google.protobuf.Any> resources, XdsResourceType<T> xdsResourceType, XdsClient.ProcessingTracker processingTracker)
-