T
- The type of builder used by this channel factory.public abstract class AbstractChannelFactory<T extends ManagedChannelBuilder<T>> extends 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 List<GrpcChannelConfigurer> |
channelConfigurers |
protected GlobalClientInterceptorRegistry |
globalClientInterceptorRegistry |
Modifier | Constructor and Description |
---|---|
protected |
AbstractChannelFactory(GrpcChannelsProperties properties,
GlobalClientInterceptorRegistry globalClientInterceptorRegistry,
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,
String name)
Configures the given channel builder.
|
protected void |
configureCompression(T builder,
String name)
Configures the compression options that should be used by the channel.
|
protected void |
configureKeepAlive(T builder,
String name)
Configures the keep alive options that should be used by the channel.
|
protected void |
configureLimits(T builder,
String name)
Configures limits such as max message sizes that should be used by the channel.
|
protected void |
configureSecurity(T builder,
String name)
Configures the security options that should be used by the channel.
|
Channel |
createChannel(String name)
Creates a new channel for the given service name.
|
Channel |
createChannel(String name,
List<ClientInterceptor> customInterceptors,
boolean sortInterceptors)
Creates a new channel for the given service name.
|
Map<String,ConnectivityState> |
getConnectivityState()
Gets an unmodifiable map that contains the names of the created channel with their current
ConnectivityState . |
protected 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.
|
protected GrpcChannelProperties |
getPropertiesFor(String name)
Gets the channel properties for the given client name.
|
protected boolean |
isNonNullAndNonBlank(String value)
Checks whether the given value is non null and non blank.
|
protected abstract T |
newChannelBuilder(String name)
Creates a new
ManagedChannelBuilder for the given client name. |
protected ManagedChannel |
newManagedChannel(String name)
Creates a new
ManagedChannel for the given client name. |
protected void |
watchConnectivityState(String name,
ManagedChannel channel)
Watch the given channel for connectivity changes.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createChannel
protected final GlobalClientInterceptorRegistry globalClientInterceptorRegistry
protected final List<GrpcChannelConfigurer> channelConfigurers
protected AbstractChannelFactory(GrpcChannelsProperties properties, GlobalClientInterceptorRegistry globalClientInterceptorRegistry, 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 Channel createChannel(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 Channel createChannel(String name, List<ClientInterceptor> customInterceptors, boolean sortInterceptors)
GrpcChannelFactory
ClientInterceptor
s.
Note: The underlying implementation might reuse existing ManagedChannel
s allow connection reuse.
Note: The given interceptors will be appended to the global interceptors and applied using
ClientInterceptors.interceptForward(Channel, ClientInterceptor...)
.
createChannel
in interface GrpcChannelFactory
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.protected abstract T newChannelBuilder(String name)
ManagedChannelBuilder
for the given client name.name
- The name to create the channel builder for.protected ManagedChannel newManagedChannel(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(String name)
name
- The client name to use.protected final String getDefaultScheme()
GrpcChannelsProperties
.protected void configure(T builder, String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureKeepAlive(T builder, String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureSecurity(T builder, String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected boolean isNonNullAndNonBlank(String value)
value
- The value to check.protected void configureLimits(T builder, String name)
builder
- The channel builder to configure.name
- The name of the client to configure.protected void configureCompression(T builder, String name)
builder
- The channel builder to configure.name
- The name of the client to configure.public Map<String,ConnectivityState> getConnectivityState()
GrpcChannelFactory
ConnectivityState
. This method will return an empty map, if the feature is not supported.getConnectivityState
in interface GrpcChannelFactory
protected void watchConnectivityState(String name, ManagedChannel channel)
name
- The name of the channel in the state overview.channel
- The channel to watch the state of.@PreDestroy public void close()
close
in interface AutoCloseable
close
in interface GrpcChannelFactory