T
- The type of builder used by this channel factory.public abstract class AbstractChannelFactory<T extends io.grpc.ManagedChannelBuilder<T>> extends java.lang.Object implements GrpcChannelFactory
GrpcChannelFactory
s. This class utilizes
connection pooling and thus needs to be closed
after usage.Modifier and Type | Field and Description |
---|---|
protected java.util.List<GrpcChannelConfigurer> |
channelConfigurers |
protected GlobalClientInterceptorRegistry |
globalClientInterceptorRegistry |
Constructor and Description |
---|
AbstractChannelFactory(GrpcChannelsProperties properties,
GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
java.util.List<GrpcChannelConfigurer> channelConfigurers)
Creates a new AbstractChannelFactory with eager initialized references.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this channel factory and the channels created by this instance.
|
protected void |
configure(T builder,
java.lang.String name)
Configures the given netty channel builder.
|
protected void |
configureCompression(T builder,
java.lang.String name)
Configures the compression options that should be used by the channel.
|
protected void |
configureKeepAlive(T builder,
java.lang.String name)
Configures the keep alive options that should be used by the channel.
|
protected void |
configureLimits(T builder,
java.lang.String name)
Configures limits such as max message sizes that should be used by the channel.
|
protected void |
configureSecurity(T builder,
java.lang.String name)
Configures the security options that should be used by the channel.
|
io.grpc.Channel |
createChannel(java.lang.String name)
Creates a new channel for the given service name.
|
io.grpc.Channel |
createChannel(java.lang.String name,
java.util.List<io.grpc.ClientInterceptor> customInterceptors)
Creates a new channel for the given service name.
|
protected GrpcChannelProperties |
getPropertiesFor(java.lang.String name)
Gets the channel properties for the given client name.
|
protected boolean |
isNonNullAndNonBlank(java.lang.String value) |
protected abstract T |
newChannelBuilder(java.lang.String name)
Creates a new
ManagedChannelBuilder for the given client name. |
protected io.grpc.ManagedChannel |
newManagedChannel(java.lang.String name)
Creates a new
ManagedChannel for the given client name. |
protected java.io.File |
toCheckedFile(java.lang.String context,
java.lang.String path)
Converts the given path to a file.
|
protected final GlobalClientInterceptorRegistry globalClientInterceptorRegistry
protected final java.util.List<GrpcChannelConfigurer> channelConfigurers
public AbstractChannelFactory(GrpcChannelsProperties properties, GlobalClientInterceptorRegistry globalClientInterceptorRegistry, java.util.List<GrpcChannelConfigurer> channelConfigurers)
properties
- The properties for the channels to create.globalClientInterceptorRegistry
- The interceptor registry to use.channelConfigurers
- The channel configurers to use. Can be empty.public final io.grpc.Channel createChannel(java.lang.String name)
GrpcChannelFactory
ClientInterceptor
s.
Note: The underlying implementation might reuse existing ManagedChannel
s allow connection reuse.
createChannel
in interface GrpcChannelFactory
name
- The name of the service.public io.grpc.Channel createChannel(java.lang.String name, java.util.List<io.grpc.ClientInterceptor> customInterceptors)
GrpcChannelFactory
ClientInterceptor
s.
Note: The underlying implementation might reuse existing ManagedChannel
s allow connection reuse.
Note: The given interceptors will be applied after the global interceptors. But the interceptors that were applied last, will be called first.
createChannel
in interface GrpcChannelFactory
name
- The name of the service.customInterceptors
- A list of additional client interceptors that should be added to the channel.protected abstract T newChannelBuilder(java.lang.String name)
ManagedChannelBuilder
for the given client name.name
- The name to create the channel builder for.protected io.grpc.ManagedChannel newManagedChannel(java.lang.String name)
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.name
- The name to create the channel for.newChannelBuilder(String)
,
configure(ManagedChannelBuilder, String)
protected final GrpcChannelProperties getPropertiesFor(java.lang.String name)
name
- The client name to use.protected void configure(T builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureKeepAlive(T builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureSecurity(T builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected java.io.File toCheckedFile(java.lang.String context, java.lang.String path)
context
- The context for what the file is used. This value will be used in case of exceptions.path
- The path of the file to use.protected boolean isNonNullAndNonBlank(java.lang.String value)
protected void configureLimits(T builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureCompression(T builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.@PreDestroy public void close()
close
in interface java.lang.AutoCloseable
close
in interface GrpcChannelFactory