Package io.grpc.grpclb
Class CachedSubchannelPool
- java.lang.Object
-
- io.grpc.grpclb.CachedSubchannelPool
-
- All Implemented Interfaces:
SubchannelPool
final class CachedSubchannelPool extends java.lang.Object implements SubchannelPool
ASubchannelPoolthat keeps returnedLoadBalancer.Subchannels for a given time before it's shut down by the pool.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCachedSubchannelPool.CacheEntry(package private) classCachedSubchannelPool.ShutdownSubchannelTask-
Nested classes/interfaces inherited from interface io.grpc.grpclb.SubchannelPool
SubchannelPool.PooledSubchannelStateListener
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<EquivalentAddressGroup,CachedSubchannelPool.CacheEntry>cacheprivate LoadBalancer.Helperhelperprivate SubchannelPool.PooledSubchannelStateListenerlistener(package private) static longSHUTDOWN_TIMEOUT_MS
-
Constructor Summary
Constructors Constructor Description CachedSubchannelPool(LoadBalancer.Helper helper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Shuts down all subchannels in the pool immediately.voidregisterListener(SubchannelPool.PooledSubchannelStateListener listener)Registers a listener to received Subchannel status updates.voidreturnSubchannel(LoadBalancer.Subchannel subchannel, ConnectivityStateInfo lastKnownState)Puts aLoadBalancer.Subchannelback to the pool.LoadBalancer.SubchanneltakeOrCreateSubchannel(EquivalentAddressGroup eag, Attributes defaultAttributes)Takes aLoadBalancer.Subchannelfrom the pool for the giveneagif there is one available.private voidupdateCachedSubchannelState(LoadBalancer.Subchannel subchannel, ConnectivityStateInfo newStateInfo)
-
-
-
Field Detail
-
cache
private final java.util.HashMap<EquivalentAddressGroup,CachedSubchannelPool.CacheEntry> cache
-
helper
private final LoadBalancer.Helper helper
-
listener
private SubchannelPool.PooledSubchannelStateListener listener
-
SHUTDOWN_TIMEOUT_MS
static final long SHUTDOWN_TIMEOUT_MS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CachedSubchannelPool
public CachedSubchannelPool(LoadBalancer.Helper helper)
-
-
Method Detail
-
registerListener
public void registerListener(SubchannelPool.PooledSubchannelStateListener listener)
Description copied from interface:SubchannelPoolRegisters a listener to received Subchannel status updates.- Specified by:
registerListenerin interfaceSubchannelPool
-
takeOrCreateSubchannel
public LoadBalancer.Subchannel takeOrCreateSubchannel(EquivalentAddressGroup eag, Attributes defaultAttributes)
Description copied from interface:SubchannelPoolTakes aLoadBalancer.Subchannelfrom the pool for the giveneagif there is one available. Otherwise, creates and returns a newSubchannelwith the giveneaganddefaultAttributes.- Specified by:
takeOrCreateSubchannelin interfaceSubchannelPool
-
updateCachedSubchannelState
private void updateCachedSubchannelState(LoadBalancer.Subchannel subchannel, ConnectivityStateInfo newStateInfo)
-
returnSubchannel
public void returnSubchannel(LoadBalancer.Subchannel subchannel, ConnectivityStateInfo lastKnownState)
Description copied from interface:SubchannelPoolPuts aLoadBalancer.Subchannelback to the pool. From this point the Subchannel is owned by the pool, and the caller should stop referencing to this Subchannel.- Specified by:
returnSubchannelin interfaceSubchannelPool
-
clear
public void clear()
Description copied from interface:SubchannelPoolShuts down all subchannels in the pool immediately.- Specified by:
clearin interfaceSubchannelPool
-
-