Class AbstractChannelFactory<T extends ManagedChannelBuilder<T>>

java.lang.Object
net.devh.boot.grpc.client.channelfactory.AbstractChannelFactory<T>
Type Parameters:
T - The type of builder used by this channel factory.
All Implemented Interfaces:
AutoCloseable, GrpcChannelFactory
Direct Known Subclasses:
InProcessChannelFactory, NettyChannelFactory, ShadedNettyChannelFactory

public abstract class AbstractChannelFactory<T extends ManagedChannelBuilder<T>> extends Object implements GrpcChannelFactory
This abstract channel factory contains some shared code for other GrpcChannelFactorys. This class utilizes connection pooling and thus needs to be closed after usage.
Since:
5/17/16
  • Field Details

  • Constructor Details

    • AbstractChannelFactory

      protected AbstractChannelFactory(GrpcChannelsProperties properties, GlobalClientInterceptorRegistry globalClientInterceptorRegistry, List<GrpcChannelConfigurer> channelConfigurers)
      Creates a new AbstractChannelFactory with eager initialized references.
      Parameters:
      properties - The properties for the channels to create.
      globalClientInterceptorRegistry - The interceptor registry to use.
      channelConfigurers - The channel configurers to use. Can be empty.
  • Method Details

    • createChannel

      public final Channel createChannel(String name)
      Description copied from interface: GrpcChannelFactory
      Creates a new channel for the given service name. The returned channel will use all globally registered ClientInterceptors.

      Note: The underlying implementation might reuse existing ManagedChannels allow connection reuse.

      Specified by:
      createChannel in interface GrpcChannelFactory
      Parameters:
      name - The name of the service.
      Returns:
      The newly created channel for the given service.
    • createChannel

      public Channel createChannel(String name, List<ClientInterceptor> customInterceptors, boolean sortInterceptors)
      Description copied from interface: GrpcChannelFactory
      Creates a new channel for the given service name. The returned channel will use all globally registered ClientInterceptors.

      Note: The underlying implementation might reuse existing ManagedChannels allow connection reuse.

      Note: The given interceptors will be appended to the global interceptors and applied using ClientInterceptors.interceptForward(Channel, ClientInterceptor...).

      Specified by:
      createChannel in interface GrpcChannelFactory
      Parameters:
      name - The name of the service.
      customInterceptors - A list of additional client interceptors that should be added to the channel.
      sortInterceptors - Whether the interceptors (both global and custom) should be sorted before being applied.
      Returns:
      The newly created channel for the given service.
    • newChannelBuilder

      protected abstract T newChannelBuilder(String name)
      Creates a new ManagedChannelBuilder for the given client name.
      Parameters:
      name - The name to create the channel builder for.
      Returns:
      The newly created channel builder.
    • newManagedChannel

      protected ManagedChannel newManagedChannel(String name)
      Creates a new ManagedChannel for the given client name. The name will be used to determine the properties for the new channel. The calling method is responsible for lifecycle management of the created channel. ManagedChannels should be reused if possible to allow connection reuse.
      Parameters:
      name - The name to create the channel for.
      Returns:
      The newly created channel.
      See Also:
    • getPropertiesFor

      protected final GrpcChannelProperties getPropertiesFor(String name)
      Gets the channel properties for the given client name.
      Parameters:
      name - The client name to use.
      Returns:
      The properties for the given client name.
    • getDefaultScheme

      protected final String getDefaultScheme()
      Gets the default scheme that should be used for a client channel's target if no address is specified for a client's channel properties.
      Returns:
      The default scheme defined in GrpcChannelsProperties.
    • configure

      protected void configure(T builder, String name)
      Configures the given channel builder. This method can be overwritten to add features that are not yet supported by this library.
      Parameters:
      builder - The channel builder to configure.
      name - The name of the client to configure.
    • configureKeepAlive

      protected void configureKeepAlive(T builder, String name)
      Configures the keep alive options that should be used by the channel.
      Parameters:
      builder - The channel builder to configure.
      name - The name of the client to configure.
    • configureSecurity

      protected void configureSecurity(T builder, String name)
      Configures the security options that should be used by the channel.
      Parameters:
      builder - The channel builder to configure.
      name - The name of the client to configure.
    • isNonNullAndNonBlank

      protected boolean isNonNullAndNonBlank(String value)
      Checks whether the given value is non null and non blank.
      Parameters:
      value - The value to check.
      Returns:
      True, if the given value was neither null nor blank. False otherwise.
    • configureLimits

      protected void configureLimits(T builder, String name)
      Configures limits such as max message sizes that should be used by the channel.
      Parameters:
      builder - The channel builder to configure.
      name - The name of the client to configure.
    • configureCompression

      protected void configureCompression(T builder, String name)
      Configures the compression options that should be used by the channel.
      Parameters:
      builder - The channel builder to configure.
      name - The name of the client to configure.
    • configureUserAgent

      protected void configureUserAgent(T builder, String name)
      Configures custom User-Agent for the channel.
      Parameters:
      builder - The channel builder to configure.
      name - The name of the client to configure.
    • getConnectivityState

      public Map<String,ConnectivityState> getConnectivityState()
      Description copied from interface: GrpcChannelFactory
      Gets an unmodifiable map that contains the names of the created channel with their current ConnectivityState. This method will return an empty map, if the feature is not supported.
      Specified by:
      getConnectivityState in interface GrpcChannelFactory
      Returns:
      A map with the channel names and their connectivity state.
    • watchConnectivityState

      protected void watchConnectivityState(String name, ManagedChannel channel)
      Watch the given channel for connectivity changes.
      Parameters:
      name - The name of the channel in the state overview.
      channel - The channel to watch the state of.
    • close

      @PreDestroy public void close()
      Closes this channel factory and the channels created by this instance. The shutdown happens in two phases, first an orderly shutdown is initiated on all channels and then the method waits for all channels to terminate. If the channels don't have terminated after 60 seconds then they will be forcefully shutdown.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface GrpcChannelFactory