@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1771") public abstract class ForwardingLoadBalancerHelper extends LoadBalancer.Helper
Constructor and Description |
---|
ForwardingLoadBalancerHelper() |
Modifier and Type | Method and Description |
---|---|
ManagedChannel |
createOobChannel(EquivalentAddressGroup eag,
String authority)
Out-of-band channel for LoadBalancer’s own RPC needs, e.g., talking to an external
load-balancer service.
|
ManagedChannel |
createOobChannel(List<EquivalentAddressGroup> eag,
String authority)
Accept a list of EAG for multiple authorities: https://github.com/grpc/grpc-java/issues/4618
|
ManagedChannel |
createResolvingOobChannel(String target)
Creates an out-of-band channel for LoadBalancer's own RPC needs, e.g., talking to an external
load-balancer service, that is specified by a target string.
|
ManagedChannelBuilder<?> |
createResolvingOobChannelBuilder(String target)
Deprecated.
|
ManagedChannelBuilder<?> |
createResolvingOobChannelBuilder(String target,
ChannelCredentials creds)
Creates an out-of-band channel builder for LoadBalancer's own RPC needs, e.g., talking to an
external load-balancer service, that is specified by a target string and credentials.
|
LoadBalancer.Subchannel |
createSubchannel(LoadBalancer.CreateSubchannelArgs args)
Creates a Subchannel, which is a logical connection to the given group of addresses which are
considered equivalent.
|
protected abstract LoadBalancer.Helper |
delegate()
Returns the underlying helper.
|
String |
getAuthority()
Returns the authority string of the channel, which is derived from the DNS-style target name.
|
ChannelCredentials |
getChannelCredentials()
Returns the ChannelCredentials used to construct the channel, without bearer tokens.
|
ChannelLogger |
getChannelLogger()
Returns the
ChannelLogger for the Channel served by this LoadBalancer. |
NameResolver.Args |
getNameResolverArgs()
Returns the
NameResolver.Args that the Channel uses to create NameResolver s. |
NameResolverRegistry |
getNameResolverRegistry()
Returns the
NameResolverRegistry that the Channel uses to look for NameResolver s. |
ScheduledExecutorService |
getScheduledExecutorService()
Returns a
ScheduledExecutorService for scheduling delayed tasks. |
SynchronizationContext |
getSynchronizationContext()
Returns a
SynchronizationContext that runs tasks in the same Synchronization Context
as that the callback methods on the LoadBalancer interface are run in. |
ChannelCredentials |
getUnsafeChannelCredentials()
Returns the UNSAFE ChannelCredentials used to construct the channel,
including bearer tokens.
|
void |
ignoreRefreshNameResolutionCheck()
Historically the channel automatically refreshes name resolution if any subchannel
connection is broken.
|
void |
refreshNameResolution()
Call
NameResolver.refresh() on the channel's resolver. |
String |
toString() |
void |
updateBalancingState(ConnectivityState newState,
LoadBalancer.SubchannelPicker newPicker)
Set a new state with a new picker to the channel.
|
void |
updateOobChannelAddresses(ManagedChannel channel,
EquivalentAddressGroup eag)
Updates the addresses used for connections in the
Channel that was created by LoadBalancer.Helper.createOobChannel(EquivalentAddressGroup, String) . |
void |
updateOobChannelAddresses(ManagedChannel channel,
List<EquivalentAddressGroup> eag)
Updates the addresses with a new EAG list.
|
protected abstract LoadBalancer.Helper delegate()
public LoadBalancer.Subchannel createSubchannel(LoadBalancer.CreateSubchannelArgs args)
LoadBalancer.Helper
attrs
are custom attributes associated with this
Subchannel, and can be accessed later through Subchannel.getAttributes()
.
The LoadBalancer is responsible for closing unused Subchannels, and closing all
Subchannels within LoadBalancer.shutdown()
.
It must be called from the Synchronization Context
createSubchannel
in class LoadBalancer.Helper
public ManagedChannel createOobChannel(EquivalentAddressGroup eag, String authority)
LoadBalancer.Helper
The LoadBalancer is responsible for closing unused OOB channels, and closing all OOB
channels within LoadBalancer.shutdown()
.
createOobChannel
in class LoadBalancer.Helper
public ManagedChannel createOobChannel(List<EquivalentAddressGroup> eag, String authority)
LoadBalancer.Helper
createOobChannel
in class LoadBalancer.Helper
public void updateOobChannelAddresses(ManagedChannel channel, EquivalentAddressGroup eag)
LoadBalancer.Helper
Channel
that was created by LoadBalancer.Helper.createOobChannel(EquivalentAddressGroup, String)
. This is superior to LoadBalancer.Helper.createOobChannel(EquivalentAddressGroup, String)
when the old and new addresses overlap,
since the channel can continue using an existing connection.updateOobChannelAddresses
in class LoadBalancer.Helper
public void updateOobChannelAddresses(ManagedChannel channel, List<EquivalentAddressGroup> eag)
LoadBalancer.Helper
updateOobChannelAddresses
in class LoadBalancer.Helper
@Deprecated public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(String target)
LoadBalancer.Helper
ManagedChannelBuilder.forTarget(java.lang.String)
for the format of a target string.
The target string will be resolved by a NameResolver
created according to the
target string.
The returned oob-channel builder defaults to use the same authority and ChannelCredentials
(without bearer tokens) as the parent channel's for authentication. This is different from
LoadBalancer.Helper.createResolvingOobChannelBuilder(String, ChannelCredentials)
.
The LoadBalancer is responsible for closing unused OOB channels, and closing all OOB
channels within LoadBalancer.shutdown()
.
createResolvingOobChannelBuilder
in class LoadBalancer.Helper
public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(String target, ChannelCredentials creds)
LoadBalancer.Helper
Grpc.newChannelBuilder(java.lang.String, io.grpc.ChannelCredentials)
for the format of a target string.
The target string will be resolved by a NameResolver
created according to the
target string.
The LoadBalancer is responsible for closing unused OOB channels, and closing all OOB
channels within LoadBalancer.shutdown()
.
createResolvingOobChannelBuilder
in class LoadBalancer.Helper
public ManagedChannel createResolvingOobChannel(String target)
LoadBalancer.Helper
ManagedChannelBuilder.forTarget(java.lang.String)
for the format of a target string.
The target string will be resolved by a NameResolver
created according to the
target string.
The LoadBalancer is responsible for closing unused OOB channels, and closing all OOB
channels within LoadBalancer.shutdown()
.
createResolvingOobChannel
in class LoadBalancer.Helper
public void updateBalancingState(ConnectivityState newState, LoadBalancer.SubchannelPicker newPicker)
LoadBalancer.Helper
When a new picker is provided via updateBalancingState()
, the channel will apply
the picker on all buffered RPCs, by calling LoadBalancer.SubchannelPicker.pickSubchannel(
LoadBalancer.PickSubchannelArgs)
.
The channel will hold the picker and use it for all RPCs, until updateBalancingState()
is called again and a new picker replaces the old one. If updateBalancingState()
has never been called, the channel will buffer all RPCs until a
picker is provided.
It should be called from the Synchronization Context. Currently will log a warning if violated. It will become an exception eventually. See #5015 for the background.
The passed state will be the channel's new state. The SHUTDOWN state should not be passed and its behavior is undefined.
updateBalancingState
in class LoadBalancer.Helper
public void refreshNameResolution()
LoadBalancer.Helper
NameResolver.refresh()
on the channel's resolver.
It should be called from the Synchronization Context. Currently will log a warning if violated. It will become an exception eventually. See #5015 for the background.
refreshNameResolution
in class LoadBalancer.Helper
public void ignoreRefreshNameResolutionCheck()
LoadBalancer.Helper
LoadBalancer.Helper.refreshNameResolution()
is called
by the load balancer. If not, it will do it and log a warning. This will be removed in
the future and load balancers are completely responsible for triggering the refresh.
See #8088 for the background.
This should rarely be used, but sometimes the address for the subchannel wasn't provided by the name resolver and a refresh needs to be directed somewhere else instead. Then you can call this method to disable the short-tem check for detecting LoadBalancers that need to be updated for the new expected behavior.
ignoreRefreshNameResolutionCheck
in class LoadBalancer.Helper
public String getAuthority()
LoadBalancer.Helper
LoadBalancer.Helper.getUnsafeChannelCredentials()
must also be
overridden to call LoadBalancer.Helper.getChannelCredentials()
or provide appropriate credentials.getAuthority
in class LoadBalancer.Helper
public ChannelCredentials getChannelCredentials()
LoadBalancer.Helper
getChannelCredentials
in class LoadBalancer.Helper
public ChannelCredentials getUnsafeChannelCredentials()
LoadBalancer.Helper
getUnsafeChannelCredentials
in class LoadBalancer.Helper
public SynchronizationContext getSynchronizationContext()
LoadBalancer.Helper
SynchronizationContext
that runs tasks in the same Synchronization Context
as that the callback methods on the LoadBalancer
interface are run in.
Pro-tip: in order to call SynchronizationContext.schedule(java.lang.Runnable, long, java.util.concurrent.TimeUnit, java.util.concurrent.ScheduledExecutorService)
, you need to provide a
ScheduledExecutorService
. LoadBalancer.Helper.getScheduledExecutorService()
is provided for your
convenience.
getSynchronizationContext
in class LoadBalancer.Helper
public ScheduledExecutorService getScheduledExecutorService()
LoadBalancer.Helper
ScheduledExecutorService
for scheduling delayed tasks.
This service is a shared resource and is only meant for quick tasks. DO NOT block or run time-consuming tasks.
The returned service doesn't support shutdown()
and shutdownNow()
. They will throw if called.
getScheduledExecutorService
in class LoadBalancer.Helper
public ChannelLogger getChannelLogger()
LoadBalancer.Helper
ChannelLogger
for the Channel served by this LoadBalancer.getChannelLogger
in class LoadBalancer.Helper
public NameResolver.Args getNameResolverArgs()
LoadBalancer.Helper
NameResolver.Args
that the Channel uses to create NameResolver
s.getNameResolverArgs
in class LoadBalancer.Helper
public NameResolverRegistry getNameResolverRegistry()
LoadBalancer.Helper
NameResolverRegistry
that the Channel uses to look for NameResolver
s.getNameResolverRegistry
in class LoadBalancer.Helper