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 Classes Modifier and Type Class Description private class
XdsClientImpl.ResourceSubscriber<T extends XdsClient.ResourceUpdate>
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
Fields Modifier and Type Field Description private io.grpc.internal.BackoffPolicy.Provider
backoffPolicyProvider
private Bootstrapper.BootstrapInfo
bootstrapInfo
static int
INITIAL_RESOURCE_FETCH_TIMEOUT_SEC
private boolean
isShutdown
private java.util.Map<Bootstrapper.ServerInfo,LoadStatsManager2>
loadStatsManagerMap
private XdsLogger
logger
private io.grpc.InternalLogId
logId
private MessagePrettyPrinter
messagePrinter
private java.util.Map<XdsResourceType<? extends XdsClient.ResourceUpdate>,java.util.Map<java.lang.String,XdsClientImpl.ResourceSubscriber<? extends XdsClient.ResourceUpdate>>>
resourceSubscribers
private java.lang.Object
securityConfig
private java.util.Map<Bootstrapper.ServerInfo,ControlPlaneClient>
serverCpClientMap
(package private) java.util.Map<Bootstrapper.ServerInfo,LoadReportClient>
serverLrsClientMap
private com.google.common.base.Supplier<com.google.common.base.Stopwatch>
stopwatchSupplier
private java.util.Map<java.lang.String,XdsResourceType<?>>
subscribedResourceTypeUrls
private io.grpc.SynchronizationContext
syncContext
private io.grpc.internal.TimeProvider
timeProvider
private java.util.concurrent.ScheduledExecutorService
timeService
private XdsTransportFactory
xdsTransportFactory
-
Constructor Summary
Constructors Constructor Description XdsClientImpl(XdsTransportFactory xdsTransportFactory, Bootstrapper.BootstrapInfo bootstrapInfo, java.util.concurrent.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, java.lang.Object securityConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LoadStatsManager2.ClusterDropStats
addClusterDropStats(Bootstrapper.ServerInfo serverInfo, java.lang.String clusterName, java.lang.String edsServiceName)
Adds drop stats for the specified cluster with edsServiceName by using the returned object to record dropped requests.LoadStatsManager2.ClusterLocalityStats
addClusterLocalityStats(Bootstrapper.ServerInfo serverInfo, java.lang.String clusterName, java.lang.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, java.lang.String resourceName, XdsClient.ResourceWatcher<T> watcher)
Unregisters the given resource watcher.private void
cleanUpResourceTimers()
Bootstrapper.BootstrapInfo
getBootstrapInfo()
Returns the config used to bootstrap this XdsClientBootstrapper.BootstrapInfo
.ControlPlaneClient
getOrCreateControlPlaneClient(Bootstrapper.ServerInfo serverInfo)
private java.util.Set<java.lang.String>
getResourceKeys(XdsResourceType<?> xdsResourceType)
java.lang.Object
getSecurityConfig()
Returns the implementation specific security configuration used in this XdsClient.private Bootstrapper.ServerInfo
getServerInfo(java.lang.String resource)
java.util.Map<Bootstrapper.ServerInfo,LoadReportClient>
getServerLrsClientMap()
Returns a map of control plane server info objects to the LoadReportClients that are responsible for sending load reports to the control plane servers.java.util.Collection<java.lang.String>
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<java.util.Map<XdsResourceType<?>,java.util.Map<java.lang.String,XdsClient.ResourceMetadata>>>
getSubscribedResourcesMetadataSnapshot()
Returns aListenableFuture
to the snapshot of the subscribed resources as they are at the moment of the call.java.util.Map<java.lang.String,XdsResourceType<?>>
getSubscribedResourceTypesWithTypeUrl()
void
handleResourceResponse(XdsResourceType<?> xdsResourceType, Bootstrapper.ServerInfo serverInfo, java.lang.String versionInfo, java.util.List<com.google.protobuf.Any> resources, java.lang.String nonce, XdsClient.ProcessingTracker processingTracker)
Called when a xds response is received.private <T extends XdsClient.ResourceUpdate>
voidhandleResourceUpdate(XdsResourceType.Args args, java.util.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
isShutDown()
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.java.lang.String
toString()
<T extends XdsClient.ResourceUpdate>
voidwatchXdsResource(XdsResourceType<T> type, java.lang.String resourceName, XdsClient.ResourceWatcher<T> watcher, java.util.concurrent.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 Detail
-
INITIAL_RESOURCE_FETCH_TIMEOUT_SEC
public static final int INITIAL_RESOURCE_FETCH_TIMEOUT_SEC
- See Also:
- Constant Field Values
-
syncContext
private final io.grpc.SynchronizationContext syncContext
-
loadStatsManagerMap
private final java.util.Map<Bootstrapper.ServerInfo,LoadStatsManager2> loadStatsManagerMap
-
serverLrsClientMap
final java.util.Map<Bootstrapper.ServerInfo,LoadReportClient> serverLrsClientMap
-
serverCpClientMap
private final java.util.Map<Bootstrapper.ServerInfo,ControlPlaneClient> serverCpClientMap
-
resourceSubscribers
private final java.util.Map<XdsResourceType<? extends XdsClient.ResourceUpdate>,java.util.Map<java.lang.String,XdsClientImpl.ResourceSubscriber<? extends XdsClient.ResourceUpdate>>> resourceSubscribers
-
subscribedResourceTypeUrls
private final java.util.Map<java.lang.String,XdsResourceType<?>> subscribedResourceTypeUrls
-
xdsTransportFactory
private final XdsTransportFactory xdsTransportFactory
-
bootstrapInfo
private final Bootstrapper.BootstrapInfo bootstrapInfo
-
timeService
private final java.util.concurrent.ScheduledExecutorService 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
private final java.lang.Object securityConfig
-
logId
private final io.grpc.InternalLogId logId
-
logger
private final XdsLogger logger
-
isShutdown
private volatile boolean isShutdown
-
messagePrinter
private final MessagePrettyPrinter messagePrinter
-
-
Constructor Detail
-
XdsClientImpl
public XdsClientImpl(XdsTransportFactory xdsTransportFactory, Bootstrapper.BootstrapInfo bootstrapInfo, java.util.concurrent.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, java.lang.Object securityConfig)
-
-
Method Detail
-
handleResourceResponse
public void handleResourceResponse(XdsResourceType<?> xdsResourceType, Bootstrapper.ServerInfo serverInfo, java.lang.String versionInfo, java.util.List<com.google.protobuf.Any> resources, java.lang.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
public void handleStreamRestarted(Bootstrapper.ServerInfo serverInfo)
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
public java.util.Map<java.lang.String,XdsResourceType<?>> getSubscribedResourceTypesWithTypeUrl()
- Specified by:
getSubscribedResourceTypesWithTypeUrl
in interfaceXdsClient.ResourceStore
-
getSubscribedResources
@Nullable public java.util.Collection<java.lang.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<java.util.Map<XdsResourceType<?>,java.util.Map<java.lang.String,XdsClient.ResourceMetadata>>> getSubscribedResourcesMetadataSnapshot()
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
public java.lang.Object 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, java.lang.String resourceName, XdsClient.ResourceWatcher<T> watcher, java.util.concurrent.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, java.lang.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, java.lang.String clusterName, @Nullable java.lang.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, java.lang.String clusterName, @Nullable java.lang.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
public Bootstrapper.BootstrapInfo getBootstrapInfo()
Description copied from class:XdsClient
Returns the config used to bootstrap this XdsClientBootstrapper.BootstrapInfo
.- Overrides:
getBootstrapInfo
in classXdsClient
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
startSubscriberTimersIfNeeded
protected void startSubscriberTimersIfNeeded(Bootstrapper.ServerInfo serverInfo)
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
private java.util.Set<java.lang.String> getResourceKeys(XdsResourceType<?> xdsResourceType)
-
cleanUpResourceTimers
private void cleanUpResourceTimers()
-
getOrCreateControlPlaneClient
public ControlPlaneClient getOrCreateControlPlaneClient(Bootstrapper.ServerInfo serverInfo)
-
getServerLrsClientMap
public java.util.Map<Bootstrapper.ServerInfo,LoadReportClient> 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
@Nullable private Bootstrapper.ServerInfo getServerInfo(java.lang.String resource)
-
handleResourceUpdate
private <T extends XdsClient.ResourceUpdate> void handleResourceUpdate(XdsResourceType.Args args, java.util.List<com.google.protobuf.Any> resources, XdsResourceType<T> xdsResourceType, XdsClient.ProcessingTracker processingTracker)
-
-