@Immutable public static final class LoadBalancer2.PickResult extends Object
SubchannelPicker
for an RPC.
The outcome of the decision will be one of the following:
withSubchannel()
, and is
in READY state when the RPC tries to start on it, the RPC will proceed on that
Subchannel.withError()
, and the RPC is not
wait-for-ready (i.e., CallOptions.withWaitForReady()
was not called), the RPC will
fail immediately with the given error.Helper.updatePicker()
, when the RPC
will go through the same picking process again.Modifier and Type | Method and Description |
---|---|
Status |
getStatus()
The status associated with this result.
|
LoadBalancer2.Subchannel |
getSubchannel()
The Subchannel if this result was created by
withSubchannel() , or
null otherwise. |
String |
toString() |
static LoadBalancer2.PickResult |
withError(Status error)
A decision to report a connectivity error to the RPC.
|
static LoadBalancer2.PickResult |
withNoResult()
No decision could be made.
|
static LoadBalancer2.PickResult |
withSubchannel(LoadBalancer2.Subchannel subchannel)
A decision to proceed the RPC on a Subchannel.
|
public static LoadBalancer2.PickResult withSubchannel(LoadBalancer2.Subchannel subchannel)
Only Subchannels returned by Helper.createSubchannel()
will work. DO NOT try to use your own implementations of Subchannels, as they won't work.
When the RPC tries to use the return Subchannel, which is briefly after this method returns, the state of the Subchannel will decide where the RPC would go:
All buffered RPCs will stay buffered until the next call of Helper.updatePicker()
, which will trigger a new picking process.
Note that Subchannel's state may change at the same time the picker is making the decision, which means the decision may be made with (to-be) outdated information. For example, a picker may return a Subchannel known to be READY, but it has become IDLE when is about to be used by the RPC, which makes the RPC to be buffered. The LoadBalancer will soon learn about the Subchannels' transition from READY to IDLE, create a new picker and allow the RPC to use another READY transport if there is any.
You will want to avoid running into a situation where there are READY Subchannels out there but some RPCs are still buffered for longer than a brief time.
In order to prevent unnecessary delay of RPCs, the rules of thumb are:
Subchannel.requestConnection()
whenever the Subchannel has transitioned to IDLE, then you don't need to include
IDLE Subchannels in your pick results.Helper.updatePicker()
whenever handleSubchannelState()
is called, unless the
new state is SHUTDOWN. See handleSubchannelState
's javadoc for more
details.public static LoadBalancer2.PickResult withError(Status error)
wait-for-ready
, it will stay buffered. Otherwise, it will fail
with the given error.error
- the error status. Must not be OK.public static LoadBalancer2.PickResult withNoResult()
@Nullable public LoadBalancer2.Subchannel getSubchannel()
withSubchannel()
, or
null otherwise.public Status getStatus()