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 Details

  • 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 channels
      interceptorsConfigurer - configures the client interceptors on the created channels
  • Method Details

    • setInterceptorFilter

      public void setInterceptorFilter(@Nullable ClientInterceptorFilter interceptorFilter)
    • supports

      public boolean supports(String target)
      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:
      supports in interface GrpcChannelFactory
      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: GrpcChannelFactory
      Whether this factory supports the given global ClientInterceptor.
      Specified by:
      supports in interface GrpcChannelFactory
      Parameters:
      interceptor - the client interceptor to check support for
      Returns:
      whether this factory supports the given interceptor
    • setVirtualTargets

      public void setVirtualTargets(VirtualTargets targets)
    • setCredentialsProvider

      public void setCredentialsProvider(ChannelCredentialsProvider credentials)
    • createChannel

      public io.grpc.ManagedChannel createChannel(String target, ChannelBuilderOptions options)
      Description copied from interface: GrpcChannelFactory
      Creates a ManagedChannel for the given target string. The target can be

      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').

      The returned channel is configured to use all globally registered interceptors and any user-provided interceptor if specified in the options.

      Specified by:
      createChannel in interface GrpcChannelFactory
      Parameters:
      target - the target string as described in method javadocs
      options - the options for building the created channel, or ChannelBuilderOptions.defaults() to use default options
      Returns:
      a channel for the given target
    • newChannelBuilder

      protected T newChannelBuilder(String target, io.grpc.ChannelCredentials credentials)
      Creates a new ManagedChannelBuilder instance for the given target and credentials. The target is a valid nameresolver-compliant URI or an authority string as described in Grpc.newChannelBuilder(String, ChannelCredentials).
      Parameters:
      target - the target of the channel
      credentials - 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 shutdown is initiated on each channel.
      • Next the channels are ordered by smallest to largest grace period, and in serial fashion each channel is sent an awaitTermination with the channel's remaining grace period.
      • Finally, any channel not terminated is sent a forceful shutdown.
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean