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 java.lang.Object implements InternalInstrumented<InternalChannelz.ChannelStats>, TransportProvider
Transports for a singleSocketAddress.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classInternalSubchannel.Callback(package private) static classInternalSubchannel.CallTracingTransport(package private) static classInternalSubchannel.IndexIndex as in 'i', the pointer to an entry.private classInternalSubchannel.TransportListenerListener for real transports.(package private) static classInternalSubchannel.TransportLogger
-
Field Summary
Fields Modifier and Type Field Description private ManagedClientTransportactiveTransportThe transport for new outgoing requests.private java.util.List<EquivalentAddressGroup>addressGroupsA volatile accessor togetAddressGroups().private InternalSubchannel.IndexaddressIndexThe index of the address corresponding to pendingTransport/activeTransport, or at beginning if both are null.private java.lang.Stringauthorityprivate BackoffPolicy.ProviderbackoffPolicyProviderprivate InternalSubchannel.Callbackcallbackprivate CallTracercallsTracerprivate ChannelLoggerchannelLoggerprivate ChannelTracerchannelTracerprivate InternalChannelzchannelzprivate AttributesconnectedAddressAttributesprivate com.google.common.base.StopwatchconnectingTimerTimer monitoring duration since entering CONNECTING state.private InUseStateAggregator<ConnectionClientTransport>inUseStateAggregatorprivate InternalLogIdlogIdprivate ConnectionClientTransportpendingTransportThe to-be active transport, which is not ready yet.private booleanreconnectDisabledprivate BackoffPolicyreconnectPolicyThe policy to control back off between reconnects.private SynchronizationContext.ScheduledHandlereconnectTaskprivate java.util.concurrent.ScheduledExecutorServicescheduledExecutorprivate SynchronizationContext.ScheduledHandleshutdownDueToUpdateTaskprivate ManagedClientTransportshutdownDueToUpdateTransportprivate StatusshutdownReasonprivate ConnectivityStateInfostateprivate SynchronizationContextsyncContextAll field must be mutated in the syncContext.private ClientTransportFactorytransportFactoryprivate java.util.List<ClientTransportFilter>transportFiltersprivate java.util.Collection<ConnectionClientTransport>transportsAll transports that are not terminated.private java.lang.StringuserAgent
-
Constructor Summary
Constructors Constructor Description InternalSubchannel(LoadBalancer.CreateSubchannelArgs args, java.lang.String authority, java.lang.String userAgent, BackoffPolicy.Provider backoffPolicyProvider, ClientTransportFactory transportFactory, java.util.concurrent.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, java.util.List<ClientTransportFilter> transportFilters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcancelReconnectTask()private static voidcheckListHasNoNulls(java.util.List<?> list, java.lang.String msg)(package private) java.util.List<EquivalentAddressGroup>getAddressGroups()(package private) java.lang.StringgetAuthority()Returns the authority string associated with this Subchannel.(package private) ChannelLoggergetChannelLogger()AttributesgetConnectedAddressAttributes()Return attributes for server address connected by sub channel.InternalLogIdgetLogId()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) ClientTransportgetTransport()Returns a READY transport if there is any, without trying to connect.private voidgotoNonErrorState(ConnectivityState newState)private voidgotoState(ConnectivityStateInfo newState)private voidhandleTermination()private voidhandleTransportInUseState(ConnectionClientTransport transport, boolean inUse)ClientTransportobtainActiveTransport()Returns a READY transport that will be used to create new streams.private java.lang.StringprintShortStatus(Status status)(package private) voidresetConnectBackoff()Immediately attempt to reconnect if the current state is TRANSIENT_FAILURE.private voidscheduleBackoff(Status status)Only called after all addresses attempted and failed (TRANSIENT_FAILURE).voidshutdown(Status reason)(package private) voidshutdownNow(Status reason)private voidstartNewTransport()java.lang.StringtoString()voidupdateAddresses(java.util.List<EquivalentAddressGroup> newAddressGroups)Replaces the existing addresses, avoiding unnecessary reconnects.
-
-
-
Field Detail
-
logId
private final InternalLogId logId
-
authority
private final java.lang.String authority
-
userAgent
private final java.lang.String userAgent
-
backoffPolicyProvider
private final BackoffPolicy.Provider backoffPolicyProvider
-
callback
private final InternalSubchannel.Callback callback
-
transportFactory
private final ClientTransportFactory transportFactory
-
scheduledExecutor
private final java.util.concurrent.ScheduledExecutorService scheduledExecutor
-
channelz
private final InternalChannelz channelz
-
callsTracer
private final CallTracer callsTracer
-
channelTracer
private final ChannelTracer channelTracer
-
channelLogger
private final ChannelLogger channelLogger
-
reconnectDisabled
private final boolean reconnectDisabled
-
transportFilters
private final java.util.List<ClientTransportFilter> transportFilters
-
syncContext
private final SynchronizationContext syncContext
All field must be mutated in the syncContext.
-
addressIndex
private final InternalSubchannel.Index 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
private volatile java.util.List<EquivalentAddressGroup> 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
private BackoffPolicy reconnectPolicy
The policy to control back off between reconnects. Non-nullwhen a reconnect task is scheduled.
-
connectingTimer
private final com.google.common.base.Stopwatch connectingTimer
Timer monitoring duration since entering CONNECTING state.
-
reconnectTask
@Nullable private SynchronizationContext.ScheduledHandle reconnectTask
-
shutdownDueToUpdateTask
@Nullable private SynchronizationContext.ScheduledHandle shutdownDueToUpdateTask
-
shutdownDueToUpdateTransport
@Nullable private ManagedClientTransport shutdownDueToUpdateTransport
-
transports
private final java.util.Collection<ConnectionClientTransport> 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
private final InUseStateAggregator<ConnectionClientTransport> inUseStateAggregator
-
pendingTransport
@Nullable private ConnectionClientTransport pendingTransport
The to-be active transport, which is not ready yet.
-
activeTransport
@Nullable private volatile ManagedClientTransport activeTransport
The transport for new outgoing requests. Non-null only in READY state.
-
state
private volatile ConnectivityStateInfo state
-
shutdownReason
private Status shutdownReason
-
connectedAddressAttributes
private volatile Attributes connectedAddressAttributes
-
-
Constructor Detail
-
InternalSubchannel
InternalSubchannel(LoadBalancer.CreateSubchannelArgs args, java.lang.String authority, java.lang.String userAgent, BackoffPolicy.Provider backoffPolicyProvider, ClientTransportFactory transportFactory, java.util.concurrent.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, java.util.List<ClientTransportFilter> transportFilters)
-
-
Method Detail
-
getChannelLogger
ChannelLogger getChannelLogger()
-
obtainActiveTransport
public ClientTransport 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
@Nullable ClientTransport getTransport()
Returns a READY transport if there is any, without trying to connect.
-
getAuthority
java.lang.String getAuthority()
Returns the authority string associated with this Subchannel.
-
startNewTransport
private void startNewTransport()
-
scheduleBackoff
private void scheduleBackoff(Status status)
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
private void gotoNonErrorState(ConnectivityState newState)
-
gotoState
private void gotoState(ConnectivityStateInfo newState)
-
updateAddresses
public void updateAddresses(java.util.List<EquivalentAddressGroup> newAddressGroups)
Replaces the existing addresses, avoiding unnecessary reconnects.
-
shutdown
public void shutdown(Status reason)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
handleTermination
private void handleTermination()
-
handleTransportInUseState
private void handleTransportInUseState(ConnectionClientTransport transport, boolean inUse)
-
shutdownNow
void shutdownNow(Status reason)
-
getAddressGroups
java.util.List<EquivalentAddressGroup> getAddressGroups()
-
cancelReconnectTask
private void cancelReconnectTask()
-
getLogId
public InternalLogId 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
public com.google.common.util.concurrent.ListenableFuture<InternalChannelz.ChannelStats> getStats()
Description copied from interface:InternalInstrumentedReturns the stats object.- Specified by:
getStatsin interfaceInternalInstrumented<InternalChannelz.ChannelStats>
-
getConnectedAddressAttributes
public Attributes getConnectedAddressAttributes()
Return attributes for server address connected by sub channel.
-
getState
ConnectivityState getState()
-
checkListHasNoNulls
private static void checkListHasNoNulls(java.util.List<?> list, java.lang.String msg)
-
printShortStatus
private java.lang.String printShortStatus(Status status)
-
-