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
ASubchannelPool
that keeps returnedLoadBalancer.Subchannel
s for a given time before it's shut down by the pool.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CachedSubchannelPool.CacheEntry
(package private) class
CachedSubchannelPool.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>
cache
private LoadBalancer.Helper
helper
private SubchannelPool.PooledSubchannelStateListener
listener
(package private) static long
SHUTDOWN_TIMEOUT_MS
-
Constructor Summary
Constructors Constructor Description CachedSubchannelPool(LoadBalancer.Helper helper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Shuts down all subchannels in the pool immediately.void
registerListener(SubchannelPool.PooledSubchannelStateListener listener)
Registers a listener to received Subchannel status updates.void
returnSubchannel(LoadBalancer.Subchannel subchannel, ConnectivityStateInfo lastKnownState)
Puts aLoadBalancer.Subchannel
back to the pool.LoadBalancer.Subchannel
takeOrCreateSubchannel(EquivalentAddressGroup eag, Attributes defaultAttributes)
Takes aLoadBalancer.Subchannel
from the pool for the giveneag
if there is one available.private void
updateCachedSubchannelState(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:SubchannelPool
Registers a listener to received Subchannel status updates.- Specified by:
registerListener
in interfaceSubchannelPool
-
takeOrCreateSubchannel
public LoadBalancer.Subchannel takeOrCreateSubchannel(EquivalentAddressGroup eag, Attributes defaultAttributes)
Description copied from interface:SubchannelPool
Takes aLoadBalancer.Subchannel
from the pool for the giveneag
if there is one available. Otherwise, creates and returns a newSubchannel
with the giveneag
anddefaultAttributes
.- Specified by:
takeOrCreateSubchannel
in interfaceSubchannelPool
-
updateCachedSubchannelState
private void updateCachedSubchannelState(LoadBalancer.Subchannel subchannel, ConnectivityStateInfo newStateInfo)
-
returnSubchannel
public void returnSubchannel(LoadBalancer.Subchannel subchannel, ConnectivityStateInfo lastKnownState)
Description copied from interface:SubchannelPool
Puts aLoadBalancer.Subchannel
back to the pool. From this point the Subchannel is owned by the pool, and the caller should stop referencing to this Subchannel.- Specified by:
returnSubchannel
in interfaceSubchannelPool
-
clear
public void clear()
Description copied from interface:SubchannelPool
Shuts down all subchannels in the pool immediately.- Specified by:
clear
in interfaceSubchannelPool
-
-