Class LoadBalancer.Subchannel
- Direct Known Subclasses:
ForwardingSubchannel
- Enclosing class:
LoadBalancer
EquivalentAddressGroup
.
It maintains at most one physical connection (aka transport) for sending new RPCs, while also keeps track of previous transports that has been shut down but not terminated yet.
If there isn't an active transport yet, and an RPC is assigned to the Subchannel, it will
create a new transport. It won't actively create transports otherwise. requestConnection()
can be used to ask Subchannel to create a transport if
there isn't any.
start(io.grpc.LoadBalancer.SubchannelStateListener)
must be called prior to calling any other methods, with the exception of
shutdown()
, which can be called at any time.
- Since:
- 1.2.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(Internal use only) returns aChannel
that is backed by this Subchannel.final EquivalentAddressGroup
Returns the addresses that this Subchannel is bound to.Returns the addresses that this Subchannel is bound to.abstract Attributes
The same attributes passed toHelper.createSubchannel()
.Returns aChannelLogger
for this Subchannel.(Internal use only) returns attributes of the address subchannel is connected to.(Internal use only) returns an object that represents the underlying subchannel that is used by the Channel for sending RPCs when thisLoadBalancer.Subchannel
is picked.abstract void
Asks the Subchannel to create a connection (aka transport), if there isn't an active one.abstract void
shutdown()
Shuts down the Subchannel.void
start
(LoadBalancer.SubchannelStateListener listener) Starts the Subchannel.void
Replaces the existing addresses used with thisSubchannel
.
-
Constructor Details
-
Subchannel
public Subchannel()
-
-
Method Details
-
start
Starts the Subchannel. Can only be called once.Must be called prior to any other method on this class, except for
shutdown()
which may be called at any time.Must be called from the
Synchronization Context
, otherwise it may throw. See #5015 for more discussions.- Parameters:
listener
- receives state updates for this Subchannel.
-
shutdown
public abstract void shutdown()Shuts down the Subchannel. After this method is called, this Subchannel should no longer be returned by the latestpicker
, and can be safely discarded.Calling it on an already shut-down Subchannel has no effect.
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.2.0
-
requestConnection
public abstract void requestConnection()Asks the Subchannel to create a connection (aka transport), if there isn't an active one.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.2.0
-
getAddresses
Returns the addresses that this Subchannel is bound to. This can be called only if the Subchannel has only oneEquivalentAddressGroup
. Under the hood it callsgetAllAddresses()
.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:
IllegalStateException
- if this subchannel has more than one EquivalentAddressGroup. UsegetAllAddresses()
instead- Since:
- 1.2.0
-
getAllAddresses
Returns the addresses that this Subchannel is bound to. The returned list will not be empty.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.14.0
-
getAttributes
The same attributes passed toHelper.createSubchannel()
. LoadBalancer can use it to attach additional information here, e.g., the shard this Subchannel belongs to.- Since:
- 1.2.0
-
asChannel
(Internal use only) returns aChannel
that is backed by this Subchannel. This allows a LoadBalancer to issue its own RPCs for auxiliary purposes, such as health-checking, on already-established connections. This channel has certain restrictions:- It can issue RPCs only if the Subchannel is
READY
. IfChannel.newCall(io.grpc.MethodDescriptor<RequestT, ResponseT>, io.grpc.CallOptions)
is called when the Subchannel is notREADY
, the RPC will fail immediately. - It doesn't support
wait-for-ready
RPCs. Such RPCs will fail immediately.
RPCs made on this Channel is not counted when determining ManagedChannel's
idle mode
. In other words, they won't prevent ManagedChannel from entering idle mode.Warning: RPCs made on this channel will prevent a shut-down transport from terminating. If you make long-running RPCs, you need to make sure they will finish in time after the Subchannel has transitioned away from
READY
state (notified throughLoadBalancer.handleSubchannelState(io.grpc.LoadBalancer.Subchannel, io.grpc.ConnectivityStateInfo)
).Warning: this is INTERNAL API, is not supposed to be used by external users, and may change without notice. If you think you must use it, please file an issue.
- It can issue RPCs only if the Subchannel is
-
getChannelLogger
Returns aChannelLogger
for this Subchannel.- Since:
- 1.17.0
-
updateAddresses
Replaces the existing addresses used with thisSubchannel
. If the new and old addresses overlap, the Subchannel can continue using an existing connection.It must be called from the Synchronization Context or will throw.
- Throws:
IllegalArgumentException
- ifaddrs
is empty- Since:
- 1.22.0
-
getInternalSubchannel
(Internal use only) returns an object that represents the underlying subchannel that is used by the Channel for sending RPCs when thisLoadBalancer.Subchannel
is picked. This is an opaque object that is both provided and consumed by the Channel. Its type is notSubchannel
.Warning: this is INTERNAL API, is not supposed to be used by external users, and may change without notice. If you think you must use it, please file an issue and we can consider removing its "internal" status.
-
getConnectedAddressAttributes
(Internal use only) returns attributes of the address subchannel is connected to.Warning: this is INTERNAL API, is not supposed to be used by external users, and may change without notice. If you think you must use it, please file an issue and we can consider removing its "internal" status.
-