Class InProcessOrAlternativeChannelFactory
java.lang.Object
net.devh.boot.grpc.client.channelfactory.InProcessOrAlternativeChannelFactory
- All Implemented Interfaces:
AutoCloseable
,GrpcChannelFactory
This channel factory is a switch between the
InProcessChannelFactory
and an alternative implementation. All
channels that are configured with the in-process
scheme will be handled by the in-process-channel-factory,
the other channels will be handled by the alternative implementation.
The following examples show how the configured address will be mapped to an actual channel:
in-process:foobar
-> will use thefoobar
in-process-channel.in-process:foo/bar
-> will use thefoo/bar
in-process-channel.static://127.0.0.1
-> will be handled by the alternative grpc channel factory.
Using this class does not incur any additional performance or resource costs, as the actual channels (in-process or other) are only created on demand.
-
Constructor Summary
ConstructorsConstructorDescriptionInProcessOrAlternativeChannelFactory
(GrpcChannelsProperties properties, InProcessChannelFactory inProcessChannelFactory, GrpcChannelFactory alternativeChannelFactory) Creates a new InProcessOrAlternativeChannelFactory with the given properties and channel factories. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
createChannel
(String name, List<ClientInterceptor> interceptors, boolean sortInterceptors) Creates a new channel for the given service name.Gets an unmodifiable map that contains the names of the created channel with their currentConnectivityState
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.devh.boot.grpc.client.channelfactory.GrpcChannelFactory
createChannel, createChannel
-
Constructor Details
-
InProcessOrAlternativeChannelFactory
public InProcessOrAlternativeChannelFactory(GrpcChannelsProperties properties, InProcessChannelFactory inProcessChannelFactory, GrpcChannelFactory alternativeChannelFactory) Creates a new InProcessOrAlternativeChannelFactory with the given properties and channel factories.- Parameters:
properties
- The properties used to resolved the target schemeinProcessChannelFactory
- The in process channel factory implementation to use.alternativeChannelFactory
- The alternative channel factory implementation to use.
-
-
Method Details
-
createChannel
public Channel createChannel(String name, List<ClientInterceptor> interceptors, boolean sortInterceptors) Description copied from interface:GrpcChannelFactory
Creates a new channel for the given service name. The returned channel will use all globally registeredClientInterceptor
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...)
.- Specified by:
createChannel
in interfaceGrpcChannelFactory
- Parameters:
name
- The name of the service.interceptors
- 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.
-
getConnectivityState
Description copied from interface:GrpcChannelFactory
Gets an unmodifiable map that contains the names of the created channel with their currentConnectivityState
. This method will return an empty map, if the feature is not supported.- Specified by:
getConnectivityState
in interfaceGrpcChannelFactory
- Returns:
- A map with the channel names and their connectivity state.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceGrpcChannelFactory
-