Class LoadBalancer.Helper
- java.lang.Object
-
- io.grpc.LoadBalancer.Helper
-
- Enclosing class:
- LoadBalancer
@ThreadSafe @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771") public abstract static class LoadBalancer.Helper extends java.lang.Object
Provides essentials for LoadBalancer implementations.- Since:
- 1.2.0
-
-
Constructor Summary
Constructors Constructor Description Helper()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract ManagedChannelcreateOobChannel(EquivalentAddressGroup eag, java.lang.String authority)Out-of-band channel for LoadBalancer’s own RPC needs, e.g., talking to an external load-balancer service.ManagedChannelcreateResolvingOobChannel(java.lang.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.SubchannelcreateSubchannel(EquivalentAddressGroup addrs, Attributes attrs)Deprecated.LoadBalancer.SubchannelcreateSubchannel(LoadBalancer.CreateSubchannelArgs args)Creates a Subchannel, which is a logical connection to the given group of addresses which are considered equivalent.LoadBalancer.SubchannelcreateSubchannel(java.util.List<EquivalentAddressGroup> addrs, Attributes attrs)Deprecated.abstract java.lang.StringgetAuthority()Returns the authority string of the channel, which is derived from the DNS-style target name.ChannelLoggergetChannelLogger()Returns theChannelLoggerfor the Channel served by this LoadBalancer.NameResolver.ArgsgetNameResolverArgs()Returns theNameResolver.Argsthat the Channel uses to createNameResolvers.abstract NameResolver.FactorygetNameResolverFactory()Deprecated.this method will be deleted in a future release.NameResolverRegistrygetNameResolverRegistry()Returns theNameResolverRegistrythat the Channel uses to look forNameResolvers.java.util.concurrent.ScheduledExecutorServicegetScheduledExecutorService()Returns aScheduledExecutorServicefor scheduling delayed tasks.SynchronizationContextgetSynchronizationContext()Returns aSynchronizationContextthat runs tasks in the same Synchronization Context as that the callback methods on theLoadBalancerinterface are run in.voidrefreshNameResolution()CallNameResolver.refresh()on the channel's resolver.voidrunSerialized(java.lang.Runnable task)Deprecated.use/implementgetSynchronizationContext()insteadabstract voidupdateBalancingState(ConnectivityState newState, LoadBalancer.SubchannelPicker newPicker)Set a new state with a new picker to the channel.voidupdateOobChannelAddresses(ManagedChannel channel, EquivalentAddressGroup eag)Updates the addresses used for connections in theChannelthat was created bycreateOobChannel(EquivalentAddressGroup, String).voidupdateSubchannelAddresses(LoadBalancer.Subchannel subchannel, EquivalentAddressGroup addrs)Deprecated.voidupdateSubchannelAddresses(LoadBalancer.Subchannel subchannel, java.util.List<EquivalentAddressGroup> addrs)Deprecated.
-
-
-
Method Detail
-
createSubchannel
@Deprecated public final LoadBalancer.Subchannel createSubchannel(EquivalentAddressGroup addrs, Attributes attrs)
Deprecated.UsecreateSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)instead. Note the new API must be called fromthe Synchronization Context.Equivalent tocreateSubchannel(List, Attributes)with the given singleEquivalentAddressGroup.- Since:
- 1.2.0
-
createSubchannel
@Deprecated public LoadBalancer.Subchannel createSubchannel(java.util.List<EquivalentAddressGroup> addrs, Attributes attrs)
Deprecated.UsecreateSubchannel(io.grpc.LoadBalancer.CreateSubchannelArgs)instead. Note the new API must be called fromthe Synchronization Context.Creates a Subchannel, which is a logical connection to the given group of addresses which are considered equivalent. Theattrsare custom attributes associated with this Subchannel, and can be accessed later throughSubchannel.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().- Throws:
java.lang.IllegalArgumentException- ifaddrsis empty- Since:
- 1.14.0
-
createSubchannel
public LoadBalancer.Subchannel createSubchannel(LoadBalancer.CreateSubchannelArgs args)
Creates a Subchannel, which is a logical connection to the given group of addresses which are considered equivalent. Theattrsare custom attributes associated with this Subchannel, and can be accessed later throughSubchannel.getAttributes().The LoadBalancer is responsible for closing unused Subchannels, and closing all Subchannels within
LoadBalancer.shutdown().It must be called from
the Synchronization Context- Since:
- 1.22.0
-
updateSubchannelAddresses
@Deprecated public final void updateSubchannelAddresses(LoadBalancer.Subchannel subchannel, EquivalentAddressGroup addrs)
Deprecated.Equivalent toupdateSubchannelAddresses(io.grpc.LoadBalancer.Subchannel, List)with the given singleEquivalentAddressGroup.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.
- Since:
- 1.4.0
-
updateSubchannelAddresses
@Deprecated public void updateSubchannelAddresses(LoadBalancer.Subchannel subchannel, java.util.List<EquivalentAddressGroup> addrs)
Deprecated.Replaces the existing addresses used withsubchannel. This method is superior tocreateSubchannel(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.
- Throws:
java.lang.IllegalArgumentException- ifsubchannelwas not returned fromcreateSubchannel(io.grpc.EquivalentAddressGroup, io.grpc.Attributes)oraddrsis empty- Since:
- 1.14.0
-
createOobChannel
public abstract ManagedChannel createOobChannel(EquivalentAddressGroup eag, java.lang.String authority)
Out-of-band channel for LoadBalancer’s own RPC needs, e.g., talking to an external load-balancer service.The LoadBalancer is responsible for closing unused OOB channels, and closing all OOB channels within
LoadBalancer.shutdown().- Since:
- 1.4.0
-
updateOobChannelAddresses
public void updateOobChannelAddresses(ManagedChannel channel, EquivalentAddressGroup eag)
Updates the addresses used for connections in theChannelthat was created bycreateOobChannel(EquivalentAddressGroup, String). This is supperior tocreateOobChannel(EquivalentAddressGroup, String)when the old and new addresses overlap, since the channel can continue using an existing connection.- Throws:
java.lang.IllegalArgumentException- ifchannelwas not returned fromcreateOobChannel(io.grpc.EquivalentAddressGroup, java.lang.String)- Since:
- 1.4.0
-
createResolvingOobChannel
public ManagedChannel createResolvingOobChannel(java.lang.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. See the documentation onManagedChannelBuilder.forTarget(java.lang.String)for the format of a target string.The target string will be resolved by a
NameResolvercreated 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.
- Since:
- 1.20.0
-
updateBalancingState
public abstract void updateBalancingState(@Nonnull ConnectivityState newState, @Nonnull LoadBalancer.SubchannelPicker newPicker)Set a new state with a new picker to the channel.When a new picker is provided via
updateBalancingState(), the channel will apply the picker on all buffered RPCs, by callingLoadBalancer.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. IfupdateBalancingState()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.
- Since:
- 1.6.0
-
refreshNameResolution
public void refreshNameResolution()
CallNameResolver.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.
- Since:
- 1.18.0
-
runSerialized
@Deprecated public void runSerialized(java.lang.Runnable task)
Deprecated.use/implementgetSynchronizationContext()insteadSchedule a task to be run in the Synchronization Context, which serializes the task with the callback methods on theLoadBalancerinterface.- Since:
- 1.2.0
-
getSynchronizationContext
public SynchronizationContext getSynchronizationContext()
Returns aSynchronizationContextthat runs tasks in the same Synchronization Context as that the callback methods on theLoadBalancerinterface 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 aScheduledExecutorService.getScheduledExecutorService()is provided for your convenience.- Since:
- 1.17.0
-
getScheduledExecutorService
public java.util.concurrent.ScheduledExecutorService getScheduledExecutorService()
Returns aScheduledExecutorServicefor 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()andshutdownNow(). They will throw if called.- Since:
- 1.17.0
-
getNameResolverFactory
@Deprecated public 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.Returns the NameResolver of the channel.- Since:
- 1.2.0
-
getAuthority
public abstract java.lang.String getAuthority()
Returns the authority string of the channel, which is derived from the DNS-style target name.- Since:
- 1.2.0
-
getChannelLogger
public ChannelLogger getChannelLogger()
Returns theChannelLoggerfor the Channel served by this LoadBalancer.- Since:
- 1.17.0
-
getNameResolverArgs
public NameResolver.Args getNameResolverArgs()
Returns theNameResolver.Argsthat the Channel uses to createNameResolvers.- Since:
- 1.22.0
-
getNameResolverRegistry
public NameResolverRegistry getNameResolverRegistry()
Returns theNameResolverRegistrythat the Channel uses to look forNameResolvers.- Since:
- 1.22.0
-
-