public abstract class AbstractChannelFactory extends java.lang.Object implements GrpcChannelFactory
GrpcChannelFactory
s. This class utilizes
connection pooling and thus needs to be closed
after usage.Constructor and Description |
---|
AbstractChannelFactory(GrpcChannelsProperties properties,
io.grpc.LoadBalancer.Factory loadBalancerFactory,
java.util.function.Function<T,io.grpc.NameResolver.Factory> nameResolverFactoryCreator,
GlobalClientInterceptorRegistry globalClientInterceptorRegistry)
Creates a new AbstractChannelFactory with partially lazy initialized references.
|
AbstractChannelFactory(GrpcChannelsProperties properties,
io.grpc.LoadBalancer.Factory loadBalancerFactory,
io.grpc.NameResolver.Factory nameResolverFactory,
GlobalClientInterceptorRegistry globalClientInterceptorRegistry)
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(io.grpc.netty.NettyChannelBuilder builder,
java.lang.String name)
Configures the given netty channel builder.
|
protected void |
configureCompression(io.grpc.netty.NettyChannelBuilder builder,
java.lang.String name)
Configures the compression options that should be used by the channel.
|
protected void |
configureKeepAlive(io.grpc.netty.NettyChannelBuilder builder,
java.lang.String name)
Configures the keep alive options that should be used by the channel.
|
protected void |
configureLimits(io.grpc.netty.NettyChannelBuilder builder,
java.lang.String name)
Configures limits such as max message sizes that should be used by the channel.
|
protected void |
configureSecurity(io.grpc.netty.NettyChannelBuilder 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> interceptors)
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 io.grpc.ManagedChannel |
newManagedChannel(java.lang.String name)
Creates a new
ManagedChannel for the given client name. |
public AbstractChannelFactory(GrpcChannelsProperties properties, io.grpc.LoadBalancer.Factory loadBalancerFactory, io.grpc.NameResolver.Factory nameResolverFactory, GlobalClientInterceptorRegistry globalClientInterceptorRegistry)
properties
- The properties for the channels to create.loadBalancerFactory
- The load balancer factory to use.nameResolverFactory
- The name resolver factory to use.globalClientInterceptorRegistry
- The interceptor registry to use.public AbstractChannelFactory(GrpcChannelsProperties properties, io.grpc.LoadBalancer.Factory loadBalancerFactory, java.util.function.Function<T,io.grpc.NameResolver.Factory> nameResolverFactoryCreator, GlobalClientInterceptorRegistry globalClientInterceptorRegistry)
T
- The type of the actual factory class or one of its super classes.properties
- The properties for the channels to create.loadBalancerFactory
- The load balancer factory to use.nameResolverFactoryCreator
- The function that creates the name resolver factory.globalClientInterceptorRegistry
- The interceptor registry to use.public 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> interceptors)
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.interceptors
- A list of additional client interceptors that should be added to the channel.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.configure(NettyChannelBuilder, String)
protected final GrpcChannelProperties getPropertiesFor(java.lang.String name)
name
- The client name to use.protected void configure(io.grpc.netty.NettyChannelBuilder builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureKeepAlive(io.grpc.netty.NettyChannelBuilder builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureSecurity(io.grpc.netty.NettyChannelBuilder builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureLimits(io.grpc.netty.NettyChannelBuilder builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureCompression(io.grpc.netty.NettyChannelBuilder builder, java.lang.String name)
builder
- The channel builder to configure.name
- The name of the client to configure.@PreDestroy public void close() throws java.lang.InterruptedException
close
in interface java.lang.AutoCloseable
java.lang.InterruptedException