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 classIndex as in 'i', the pointer to an entry.private classListener for real transports.(package private) static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ManagedClientTransportThe transport for new outgoing requests.private List<EquivalentAddressGroup> A volatile accessor to.invalid reference
Index#getAddressGroups()private final InternalSubchannel.IndexThe index of the address corresponding to pendingTransport/activeTransport, or at beginning if both are null.private final Stringprivate final BackoffPolicy.Providerprivate final InternalSubchannel.Callbackprivate final CallTracerprivate final ChannelLoggerprivate final ChannelTracerprivate final InternalChannelzprivate Attributesprivate final com.google.common.base.StopwatchTimer monitoring duration since entering CONNECTING state.private final InUseStateAggregator<ConnectionClientTransport> private final InternalLogIdprivate ConnectionClientTransportThe to-be active transport, which is not ready yet.private final booleanprivate BackoffPolicyThe policy to control back off between reconnects.private final ScheduledExecutorServiceprivate ManagedClientTransportprivate Statusprivate ConnectivityStateInfoprivate final SynchronizationContextAll field must be mutated in the syncContext.private final ClientTransportFactoryprivate 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 voidprivate static voidcheckListHasNoNulls(List<?> list, String msg) (package private) List<EquivalentAddressGroup> (package private) StringReturns the authority string associated with this Subchannel.(package private) ChannelLoggerReturn attributes for server address connected by sub channel.getLogId()Returns an ID that is primarily used in debug logs.(package private) ConnectivityStategetState()com.google.common.util.concurrent.ListenableFuture<InternalChannelz.ChannelStats> getStats()Returns the stats object.(package private) ClientTransportReturns a READY transport if there is any, without trying to connect.private voidgotoNonErrorState(ConnectivityState newState) private voidgotoState(ConnectivityStateInfo newState) private voidprivate voidhandleTransportInUseState(ConnectionClientTransport transport, boolean inUse) Returns a READY transport that will be used to create new streams.private StringprintShortStatus(Status status) (package private) voidImmediately attempt to reconnect if the current state is TRANSIENT_FAILURE.private voidscheduleBackoff(Status status) Only called after all addresses attempted and failed (TRANSIENT_FAILURE).void(package private) voidshutdownNow(Status reason) private voidtoString()voidupdateAddresses(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
should also updateinvalid reference
Index#updateAddresses(List)addressGroups. -
addressGroups
A volatile accessor to. There are few methods (invalid reference
Index#getAddressGroups()getAddressGroups()andtoString()access this value where they supposed to access in thesyncContext. Ideallycan 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 .invalid reference
Index#getAddressGroups() -
reconnectPolicy
The policy to control back off between reconnects. Non-nullwhen 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 ofactiveTransportwill 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:TransportProviderReturns a READY transport that will be used to create new streams.Returns
nullif the state is not READY. Will try to connect if state is IDLE.- Specified by:
obtainActiveTransportin 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:InternalWithLogIdReturns 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:
getLogIdin interfaceInternalWithLogId
-
getStats
Description copied from interface:InternalInstrumentedReturns the stats object.- Specified by:
getStatsin interfaceInternalInstrumented<InternalChannelz.ChannelStats>
-
getConnectedAddressAttributes
Return attributes for server address connected by sub channel. -
getState
ConnectivityState getState() -
checkListHasNoNulls
-
printShortStatus
-