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 class
InternalSubchannel.Callback
(package private) static class
InternalSubchannel.CallTracingTransport
(package private) static class
InternalSubchannel.Index
Index as in 'i', the pointer to an entry.private class
InternalSubchannel.TransportListener
Listener for real transports.(package private) static class
InternalSubchannel.TransportLogger
-
Field Summary
Fields Modifier and Type Field Description private ManagedClientTransport
activeTransport
The transport for new outgoing requests.private java.util.List<EquivalentAddressGroup>
addressGroups
A volatile accessor togetAddressGroups()
.private InternalSubchannel.Index
addressIndex
The index of the address corresponding to pendingTransport/activeTransport, or at beginning if both are null.private java.lang.String
authority
private BackoffPolicy.Provider
backoffPolicyProvider
private InternalSubchannel.Callback
callback
private CallTracer
callsTracer
private ChannelLogger
channelLogger
private ChannelTracer
channelTracer
private InternalChannelz
channelz
private Attributes
connectedAddressAttributes
private com.google.common.base.Stopwatch
connectingTimer
Timer monitoring duration since entering CONNECTING state.private InUseStateAggregator<ConnectionClientTransport>
inUseStateAggregator
private InternalLogId
logId
private ConnectionClientTransport
pendingTransport
The to-be active transport, which is not ready yet.private boolean
reconnectDisabled
private BackoffPolicy
reconnectPolicy
The policy to control back off between reconnects.private SynchronizationContext.ScheduledHandle
reconnectTask
private java.util.concurrent.ScheduledExecutorService
scheduledExecutor
private SynchronizationContext.ScheduledHandle
shutdownDueToUpdateTask
private ManagedClientTransport
shutdownDueToUpdateTransport
private Status
shutdownReason
private ConnectivityStateInfo
state
private SynchronizationContext
syncContext
All field must be mutated in the syncContext.private ClientTransportFactory
transportFactory
private java.util.List<ClientTransportFilter>
transportFilters
private java.util.Collection<ConnectionClientTransport>
transports
All transports that are not terminated.private java.lang.String
userAgent
-
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 void
cancelReconnectTask()
private static void
checkListHasNoNulls(java.util.List<?> list, java.lang.String msg)
(package private) java.util.List<EquivalentAddressGroup>
getAddressGroups()
(package private) java.lang.String
getAuthority()
Returns the authority string associated with this Subchannel.(package private) ChannelLogger
getChannelLogger()
Attributes
getConnectedAddressAttributes()
Return attributes for server address connected by sub channel.InternalLogId
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
getTransport()
Returns a READY transport if there is any, without trying to connect.private void
gotoNonErrorState(ConnectivityState newState)
private void
gotoState(ConnectivityStateInfo newState)
private void
handleTermination()
private void
handleTransportInUseState(ConnectionClientTransport transport, boolean inUse)
ClientTransport
obtainActiveTransport()
Returns a READY transport that will be used to create new streams.private java.lang.String
printShortStatus(Status status)
(package private) void
resetConnectBackoff()
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
shutdown(Status reason)
(package private) void
shutdownNow(Status reason)
private void
startNewTransport()
java.lang.String
toString()
void
updateAddresses(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-null
when 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 ofactiveTransport
will 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: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
@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:
toString
in 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: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
public com.google.common.util.concurrent.ListenableFuture<InternalChannelz.ChannelStats> getStats()
Description copied from interface:InternalInstrumented
Returns the stats object.- Specified by:
getStats
in 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)
-
-