Class DefaultGrpcChannelFactory<T extends io.grpc.ManagedChannelBuilder<T>>
java.lang.Object
org.springframework.grpc.client.DefaultGrpcChannelFactory<T>
- Type Parameters:
T- concrete type of channel builder used to create the channels
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, GrpcChannelFactory
- Direct Known Subclasses:
InProcessGrpcChannelFactory, NettyGrpcChannelFactory, ShadedNettyGrpcChannelFactory
public class DefaultGrpcChannelFactory<T extends io.grpc.ManagedChannelBuilder<T>>
extends Object
implements GrpcChannelFactory, org.springframework.beans.factory.DisposableBean
Default implementation of
GrpcChannelFactory for creating and managing gRPC
channels.
Implements DisposableBean to shut down channels when no longer needed.
- Author:
- David Syer, Chris Bono
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultGrpcChannelFactory(List<GrpcChannelBuilderCustomizer<T>> globalCustomizers, ClientInterceptorsConfigurer interceptorsConfigurer) Construct a channel factory instance. -
Method Summary
Modifier and TypeMethodDescriptionio.grpc.ManagedChannelcreateChannel(String target, ChannelBuilderOptions options) Creates aManagedChannelfor the given target string.voiddestroy()Performs a shutdown on all created channels as follows: First anorderly shutdownis initiated on each channel.protected TnewChannelBuilder(String target, io.grpc.ChannelCredentials credentials) Creates a newManagedChannelBuilderinstance for the given target and credentials.voidsetCredentialsProvider(ChannelCredentialsProvider credentials) voidsetInterceptorFilter(@Nullable ClientInterceptorFilter interceptorFilter) voidsetVirtualTargets(VirtualTargets targets) booleansupports(io.grpc.ClientInterceptor interceptor) Whether this factory supports the given globalClientInterceptor.booleanWhether this factory supports the given target string.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GrpcChannelFactory
createChannel
-
Field Details
-
targets
-
-
Constructor Details
-
DefaultGrpcChannelFactory
public DefaultGrpcChannelFactory(List<GrpcChannelBuilderCustomizer<T>> globalCustomizers, ClientInterceptorsConfigurer interceptorsConfigurer) Construct a channel factory instance.- Parameters:
globalCustomizers- the global customizers to apply to all created channelsinterceptorsConfigurer- configures the client interceptors on the created channels
-
-
Method Details
-
setInterceptorFilter
-
supports
Whether this factory supports the given target string.The target can be either a valid nameresolver-compliant URI or an authority string as described in
Grpc.newChannelBuilder(String, ChannelCredentials), or the name of a user-configured channel (e.g. 'my-channel').- Specified by:
supportsin interfaceGrpcChannelFactory- Parameters:
target- the target string- Returns:
- true unless the target begins with 'in-process:'
-
supports
public boolean supports(io.grpc.ClientInterceptor interceptor) Description copied from interface:GrpcChannelFactoryWhether this factory supports the given globalClientInterceptor.- Specified by:
supportsin interfaceGrpcChannelFactory- Parameters:
interceptor- the client interceptor to check support for- Returns:
- whether this factory supports the given interceptor
-
setVirtualTargets
-
setCredentialsProvider
-
createChannel
Description copied from interface:GrpcChannelFactoryCreates aManagedChannelfor the given target string. The target can beThe target can be either a valid nameresolver-compliant URI or an authority string as described in
Grpc.newChannelBuilder(String, ChannelCredentials), or the name of a user-configured channel (e.g. 'my-channel').The returned channel is configured to use all globally registered
interceptorsand any user-provided interceptor if specified in theoptions.- Specified by:
createChannelin interfaceGrpcChannelFactory- Parameters:
target- the target string as described in method javadocsoptions- the options for building the created channel, orChannelBuilderOptions.defaults()to use default options- Returns:
- a channel for the given target
-
newChannelBuilder
Creates a newManagedChannelBuilderinstance for the given target and credentials. Thetargetis a valid nameresolver-compliant URI or an authority string as described inGrpc.newChannelBuilder(String, ChannelCredentials).- Parameters:
target- the target of the channelcredentials- the credentials for the channel- Returns:
- a new builder for the given target and credentials
-
destroy
public void destroy()Performs a shutdown on all created channels as follows:- First an
orderly shutdownis initiated on each channel. - Next the channels are ordered by smallest to largest grace period, and in
serial fashion each channel is sent an
awaitTerminationwith the channel's remaining grace period. - Finally, any channel not terminated is sent a
forceful shutdown.
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
- First an
-