Package io.grpc.internal
Class InternalSubchannel
java.lang.Object
io.grpc.internal.InternalSubchannel
- All Implemented Interfaces:
TransportProvider
,InternalInstrumented<InternalChannelz.ChannelStats>
,InternalWithLogId
@ThreadSafe
final class InternalSubchannel
extends Object
implements InternalInstrumented<InternalChannelz.ChannelStats>, TransportProvider
Transports for a single
SocketAddress
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
(package private) static final class
(package private) static final class
Index as in 'i', the pointer to an entry.private class
Listener for real transports.(package private) static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ManagedClientTransport
The transport for new outgoing requests.private List
<EquivalentAddressGroup> A volatile accessor togetAddressGroups()
.private final InternalSubchannel.Index
The index of the address corresponding to pendingTransport/activeTransport, or at beginning if both are null.private final String
private final BackoffPolicy.Provider
private final InternalSubchannel.Callback
private final CallTracer
private final ChannelLogger
private final ChannelTracer
private final InternalChannelz
private Attributes
private final com.google.common.base.Stopwatch
Timer monitoring duration since entering CONNECTING state.private final InUseStateAggregator
<ConnectionClientTransport> private final InternalLogId
private ConnectionClientTransport
The to-be active transport, which is not ready yet.private final boolean
private BackoffPolicy
The policy to control back off between reconnects.private final ScheduledExecutorService
private ManagedClientTransport
private Status
private ConnectivityStateInfo
private final SynchronizationContext
All field must be mutated in the syncContext.private final ClientTransportFactory
private final List
<ClientTransportFilter> private final Collection
<ConnectionClientTransport> All transports that are not terminated.private final String
-
Constructor Summary
ConstructorsConstructorDescriptionInternalSubchannel
(LoadBalancer.CreateSubchannelArgs args, String authority, String userAgent, BackoffPolicy.Provider backoffPolicyProvider, ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier, SynchronizationContext syncContext, InternalSubchannel.Callback callback, InternalChannelz channelz, CallTracer callsTracer, ChannelTracer channelTracer, InternalLogId logId, ChannelLogger channelLogger, List<ClientTransportFilter> transportFilters) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private static void
checkListHasNoNulls
(List<?> list, String msg) (package private) List
<EquivalentAddressGroup> (package private) String
Returns the authority string associated with this Subchannel.(package private) ChannelLogger
Return attributes for server address connected by sub channel.getLogId()
Returns an ID that is primarily used in debug logs.(package private) ConnectivityState
getState()
com.google.common.util.concurrent.ListenableFuture
<InternalChannelz.ChannelStats> getStats()
Returns the stats object.(package private) ClientTransport
Returns a READY transport if there is any, without trying to connect.private void
gotoNonErrorState
(ConnectivityState newState) private void
gotoState
(ConnectivityStateInfo newState) private void
private void
handleTransportInUseState
(ConnectionClientTransport transport, boolean inUse) Returns a READY transport that will be used to create new streams.private String
printShortStatus
(Status status) (package private) void
Immediately attempt to reconnect if the current state is TRANSIENT_FAILURE.private void
scheduleBackoff
(Status status) Only called after all addresses attempted and failed (TRANSIENT_FAILURE).void
(package private) void
shutdownNow
(Status reason) private void
toString()
void
updateAddresses
(List<EquivalentAddressGroup> newAddressGroups) Replaces the existing addresses, avoiding unnecessary reconnects.
-
Field Details
-
logId
-
authority
-
userAgent
-
backoffPolicyProvider
-
callback
-
transportFactory
-
scheduledExecutor
-
channelz
-
callsTracer
-
channelTracer
-
channelLogger
-
reconnectDisabled
private final boolean reconnectDisabled -
transportFilters
-
syncContext
All field must be mutated in the syncContext. -
addressIndex
The index of the address corresponding to pendingTransport/activeTransport, or at beginning if both are null.Note: any
updateAddresses(List)
should also updateaddressGroups
. -
addressGroups
A volatile accessor togetAddressGroups()
. There are few methods (getAddressGroups()
andtoString()
access this value where they supposed to access in thesyncContext
. IdeallygetAddressGroups()
can be volatile, so we don't need to maintain this volatile accessor. Although, having this accessor can reduce unnecessary volatile reads while it delivers clearer intention of why . -
reconnectPolicy
The policy to control back off between reconnects. Non-null
when a reconnect task is scheduled. -
connectingTimer
private final com.google.common.base.Stopwatch connectingTimerTimer monitoring duration since entering CONNECTING state. -
reconnectTask
-
shutdownDueToUpdateTask
-
shutdownDueToUpdateTransport
-
transports
All transports that are not terminated. At the very least the value ofactiveTransport
will be present, but previously used transports that still have streams or are stopping may also be present. -
inUseStateAggregator
-
pendingTransport
The to-be active transport, which is not ready yet. -
activeTransport
The transport for new outgoing requests. Non-null only in READY state. -
state
-
shutdownReason
-
connectedAddressAttributes
-
-
Constructor Details
-
InternalSubchannel
InternalSubchannel(LoadBalancer.CreateSubchannelArgs args, String authority, String userAgent, BackoffPolicy.Provider backoffPolicyProvider, ClientTransportFactory transportFactory, ScheduledExecutorService scheduledExecutor, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchSupplier, SynchronizationContext syncContext, InternalSubchannel.Callback callback, InternalChannelz channelz, CallTracer callsTracer, ChannelTracer channelTracer, InternalLogId logId, ChannelLogger channelLogger, List<ClientTransportFilter> transportFilters)
-
-
Method Details
-
getChannelLogger
ChannelLogger getChannelLogger() -
obtainActiveTransport
Description copied from interface:TransportProvider
Returns a READY transport that will be used to create new streams.Returns
null
if the state is not READY. Will try to connect if state is IDLE.- Specified by:
obtainActiveTransport
in interfaceTransportProvider
-
getTransport
Returns a READY transport if there is any, without trying to connect. -
getAuthority
String getAuthority()Returns the authority string associated with this Subchannel. -
startNewTransport
private void startNewTransport() -
scheduleBackoff
Only called after all addresses attempted and failed (TRANSIENT_FAILURE).- Parameters:
status
- the causal status when the channel begins transition to TRANSIENT_FAILURE.
-
resetConnectBackoff
void resetConnectBackoff()Immediately attempt to reconnect if the current state is TRANSIENT_FAILURE. Otherwise this method has no effect. -
gotoNonErrorState
-
gotoState
-
updateAddresses
Replaces the existing addresses, avoiding unnecessary reconnects. -
shutdown
-
toString
-
handleTermination
private void handleTermination() -
handleTransportInUseState
-
shutdownNow
-
getAddressGroups
List<EquivalentAddressGroup> getAddressGroups() -
cancelReconnectTask
private void cancelReconnectTask() -
getLogId
Description copied from interface:InternalWithLogId
Returns an ID that is primarily used in debug logs. It usually contains the class name and a numeric ID that is unique among the instances.The subclasses of this interface usually want to include the log ID in their
Object.toString()
results.- Specified by:
getLogId
in interfaceInternalWithLogId
-
getStats
Description copied from interface:InternalInstrumented
Returns the stats object.- Specified by:
getStats
in interfaceInternalInstrumented<InternalChannelz.ChannelStats>
-
getConnectedAddressAttributes
Return attributes for server address connected by sub channel. -
getState
ConnectivityState getState() -
checkListHasNoNulls
-
printShortStatus
-