@ThreadSafe @ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1771") public abstract static class LoadBalancer.Helper extends Object
Constructor and Description |
---|
Helper() |
Modifier and Type | Method and Description |
---|---|
abstract 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 |
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.
|
LoadBalancer.Subchannel |
createSubchannel(EquivalentAddressGroup addrs,
Attributes attrs)
Deprecated.
Use
createSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)
instead. Note the new API must be called from the Synchronization Context . |
LoadBalancer.Subchannel |
createSubchannel(List<EquivalentAddressGroup> addrs,
Attributes attrs)
Deprecated.
Use
createSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)
instead. Note the new API must be called from the Synchronization Context . |
LoadBalancer.Subchannel |
createSubchannel(LoadBalancer.CreateSubchannelArgs args)
Creates a Subchannel, which is a logical connection to the given group of addresses which are
considered equivalent.
|
abstract String |
getAuthority()
Returns the authority string of the channel, which is derived from the DNS-style target name.
|
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. |
abstract NameResolver.Factory |
getNameResolverFactory()
Deprecated.
this method will be deleted in a future release. If you think it shouldn't be
deleted, please file an issue on github.
|
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. |
void |
refreshNameResolution()
Call
NameResolver.refresh() on the channel's resolver. |
void |
runSerialized(Runnable task)
Deprecated.
use/implement
getSynchronizationContext() instead |
abstract 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 createOobChannel(EquivalentAddressGroup, String) . |
void |
updateSubchannelAddresses(LoadBalancer.Subchannel subchannel,
EquivalentAddressGroup addrs)
Deprecated.
|
void |
updateSubchannelAddresses(LoadBalancer.Subchannel subchannel,
List<EquivalentAddressGroup> addrs)
Deprecated.
|
@Deprecated public final LoadBalancer.Subchannel createSubchannel(EquivalentAddressGroup addrs, Attributes attrs)
createSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)
instead. Note the new API must be called from the Synchronization Context
.createSubchannel(List, Attributes)
with the given single EquivalentAddressGroup
.@Deprecated public LoadBalancer.Subchannel createSubchannel(List<EquivalentAddressGroup> addrs, Attributes attrs)
createSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)
instead. Note the new API must be called from the Synchronization Context
.attrs
are custom attributes associated with this
Subchannel, and can be accessed later through Subchannel.getAttributes()
.
It is recommended you call this method from the Synchronization Context, otherwise your
logic around the creation may race with LoadBalancer.handleSubchannelState(io.grpc.LoadBalancer.Subchannel, io.grpc.ConnectivityStateInfo)
. See
#5015 for more discussions.
The LoadBalancer is responsible for closing unused Subchannels, and closing all
Subchannels within LoadBalancer.shutdown()
.
IllegalArgumentException
- if addrs
is emptypublic LoadBalancer.Subchannel createSubchannel(LoadBalancer.CreateSubchannelArgs args)
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
@Deprecated public final void updateSubchannelAddresses(LoadBalancer.Subchannel subchannel, EquivalentAddressGroup addrs)
LoadBalancer.Subchannel.updateAddresses(java.util.List<io.grpc.EquivalentAddressGroup>)
insteadupdateSubchannelAddresses(io.grpc.LoadBalancer.Subchannel, List)
with
the given single EquivalentAddressGroup
.
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.
@Deprecated public void updateSubchannelAddresses(LoadBalancer.Subchannel subchannel, List<EquivalentAddressGroup> addrs)
LoadBalancer.Subchannel.updateAddresses(java.util.List<io.grpc.EquivalentAddressGroup>)
insteadsubchannel
. This method is superior to
createSubchannel(io.grpc.EquivalentAddressGroup, io.grpc.Attributes)
when the new and old addresses overlap, since the subchannel can
continue using an existing connection.
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.
IllegalArgumentException
- if subchannel
was not returned from createSubchannel(io.grpc.EquivalentAddressGroup, io.grpc.Attributes)
or addrs
is emptypublic abstract ManagedChannel createOobChannel(EquivalentAddressGroup eag, String authority)
The LoadBalancer is responsible for closing unused OOB channels, and closing all OOB
channels within LoadBalancer.shutdown()
.
public void updateOobChannelAddresses(ManagedChannel channel, EquivalentAddressGroup eag)
Channel
that was created by createOobChannel(EquivalentAddressGroup, String)
. This is supperior to createOobChannel(EquivalentAddressGroup, String)
when the old and new addresses overlap,
since the channel can continue using an existing connection.IllegalArgumentException
- if channel
was not returned from createOobChannel(io.grpc.EquivalentAddressGroup, java.lang.String)
public ManagedChannel createResolvingOobChannel(String target)
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 out-of-band channel doesn't have load-balancing. If multiple addresses
are resolved for the target, the first working address will be used.
The LoadBalancer is responsible for closing unused OOB channels, and closing all OOB
channels within LoadBalancer.shutdown()
.
NOT IMPLEMENTED: this method is currently a stub and not yet implemented by gRPC.
public abstract void updateBalancingState(@Nonnull ConnectivityState newState, @Nonnull LoadBalancer.SubchannelPicker newPicker)
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.
public void refreshNameResolution()
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.
@Deprecated public void runSerialized(Runnable task)
getSynchronizationContext()
insteadLoadBalancer
interface.public SynchronizationContext getSynchronizationContext()
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
. getScheduledExecutorService()
is provided for your
convenience.
public ScheduledExecutorService getScheduledExecutorService()
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.
@Deprecated public abstract NameResolver.Factory getNameResolverFactory()
public abstract String getAuthority()
public ChannelLogger getChannelLogger()
ChannelLogger
for the Channel served by this LoadBalancer.public NameResolver.Args getNameResolverArgs()
NameResolver.Args
that the Channel uses to create NameResolver
s.public NameResolverRegistry getNameResolverRegistry()
NameResolverRegistry
that the Channel uses to look for NameResolver
s.