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 classXdsClientImpl.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.ProviderbackoffPolicyProviderprivate Bootstrapper.BootstrapInfobootstrapInfostatic intINITIAL_RESOURCE_FETCH_TIMEOUT_SECprivate booleanisShutdownprivate java.util.Map<Bootstrapper.ServerInfo,LoadStatsManager2>loadStatsManagerMapprivate XdsLoggerloggerprivate io.grpc.InternalLogIdlogIdprivate MessagePrettyPrintermessagePrinterprivate java.util.Map<XdsResourceType<? extends XdsClient.ResourceUpdate>,java.util.Map<java.lang.String,XdsClientImpl.ResourceSubscriber<? extends XdsClient.ResourceUpdate>>>resourceSubscribersprivate java.lang.ObjectsecurityConfigprivate java.util.Map<Bootstrapper.ServerInfo,ControlPlaneClient>serverCpClientMap(package private) java.util.Map<Bootstrapper.ServerInfo,LoadReportClient>serverLrsClientMapprivate com.google.common.base.Supplier<com.google.common.base.Stopwatch>stopwatchSupplierprivate java.util.Map<java.lang.String,XdsResourceType<?>>subscribedResourceTypeUrlsprivate io.grpc.SynchronizationContextsyncContextprivate io.grpc.internal.TimeProvidertimeProviderprivate java.util.concurrent.ScheduledExecutorServicetimeServiceprivate XdsTransportFactoryxdsTransportFactory
-
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.ClusterDropStatsaddClusterDropStats(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.ClusterLocalityStatsaddClusterLocalityStats(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 voidcleanUpResourceTimers()Bootstrapper.BootstrapInfogetBootstrapInfo()Returns the config used to bootstrap this XdsClientBootstrapper.BootstrapInfo.ControlPlaneClientgetOrCreateControlPlaneClient(Bootstrapper.ServerInfo serverInfo)private java.util.Set<java.lang.String>getResourceKeys(XdsResourceType<?> xdsResourceType)java.lang.ObjectgetSecurityConfig()Returns the implementation specific security configuration used in this XdsClient.private Bootstrapper.ServerInfogetServerInfo(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 ornullif 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 aListenableFutureto the snapshot of the subscribed resources as they are at the moment of the call.java.util.Map<java.lang.String,XdsResourceType<?>>getSubscribedResourceTypesWithTypeUrl()voidhandleResourceResponse(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)voidhandleStreamClosed(io.grpc.Status error)Called when the ADS stream is closed passively.voidhandleStreamRestarted(Bootstrapper.ServerInfo serverInfo)Called when the ADS stream has been recreated.booleanisShutDown()ReturnstrueifXdsClient.shutdown()has been called.voidshutdown()Shutdown thisXdsClientand release resources.protected voidstartSubscriberTimersIfNeeded(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.StringtoString()<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.XdsResponseHandlerCalled when a xds response is received.- Specified by:
handleResourceResponsein interfaceXdsClient.XdsResponseHandler
-
handleStreamClosed
public void handleStreamClosed(io.grpc.Status error)
Description copied from interface:XdsClient.XdsResponseHandlerCalled when the ADS stream is closed passively.- Specified by:
handleStreamClosedin interfaceXdsClient.XdsResponseHandler
-
handleStreamRestarted
public void handleStreamRestarted(Bootstrapper.ServerInfo serverInfo)
Description copied from interface:XdsClient.XdsResponseHandlerCalled when the ADS stream has been recreated.- Specified by:
handleStreamRestartedin interfaceXdsClient.XdsResponseHandler
-
shutdown
public void shutdown()
Description copied from class:XdsClientShutdown thisXdsClientand release resources.
-
isShutDown
public boolean isShutDown()
Description copied from class:XdsClientReturnstrueifXdsClient.shutdown()has been called.- Overrides:
isShutDownin classXdsClient
-
getSubscribedResourceTypesWithTypeUrl
public java.util.Map<java.lang.String,XdsResourceType<?>> getSubscribedResourceTypesWithTypeUrl()
- Specified by:
getSubscribedResourceTypesWithTypeUrlin 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.ResourceStoreReturns the collection of resources currently subscribing to ornullif 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:
getSubscribedResourcesin 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:XdsClientReturns aListenableFutureto 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:
getSubscribedResourcesMetadataSnapshotin classXdsClient
-
getSecurityConfig
public java.lang.Object getSecurityConfig()
Description copied from class:XdsClientReturns the implementation specific security configuration used in this XdsClient.- Overrides:
getSecurityConfigin 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:XdsClientRegisters a data watcher for the given Xds resource.- Overrides:
watchXdsResourcein classXdsClient
-
cancelXdsResourceWatch
public <T extends XdsClient.ResourceUpdate> void cancelXdsResourceWatch(XdsResourceType<T> type, java.lang.String resourceName, XdsClient.ResourceWatcher<T> watcher)
Description copied from class:XdsClientUnregisters the given resource watcher.- Overrides:
cancelXdsResourceWatchin classXdsClient
-
addClusterDropStats
public LoadStatsManager2.ClusterDropStats addClusterDropStats(Bootstrapper.ServerInfo serverInfo, java.lang.String clusterName, @Nullable java.lang.String edsServiceName)
Description copied from class:XdsClientAdds 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:
addClusterDropStatsin classXdsClient
-
addClusterLocalityStats
public LoadStatsManager2.ClusterLocalityStats addClusterLocalityStats(Bootstrapper.ServerInfo serverInfo, java.lang.String clusterName, @Nullable java.lang.String edsServiceName, Locality locality)
Description copied from class:XdsClientAdds 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:
addClusterLocalityStatsin classXdsClient
-
getBootstrapInfo
public Bootstrapper.BootstrapInfo getBootstrapInfo()
Description copied from class:XdsClientReturns the config used to bootstrap this XdsClientBootstrapper.BootstrapInfo.- Overrides:
getBootstrapInfoin classXdsClient
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
startSubscriberTimersIfNeeded
protected void startSubscriberTimersIfNeeded(Bootstrapper.ServerInfo serverInfo)
Description copied from class:XdsClientFor all subscriber's for the specified server, if the resource hasn't yet been resolved then start a timer for it.- Overrides:
startSubscriberTimersIfNeededin 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:XdsClientReturns a map of control plane server info objects to the LoadReportClients that are responsible for sending load reports to the control plane servers.- Overrides:
getServerLrsClientMapin 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)
-
-