|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool<CL>
CL - public abstract class AbstractHostPartitionConnectionPool<CL>
Base for all connection pools that keep a separate pool of connections for
each host.
Set of host connection pools
The class maintains the set of all HostConnectionPools for all hosts in the token ring using a non blocking hashmap and a Topology
The hashmap tracks the basic set of hosts and their corresponding connection pools. The topology is used to track the internal state of the token ring
for the cassandra cluster.
The class uses these 2 structures to determine whether there has been a change to the system when a host joins or leaves the ring,
or even if an existing host just receives an update for the token ring partition that it owns. Hence the class can actively rebuild all the partitions
associated with each as and when there is a change.
See addHost(Host, boolean) removeHost(Host, boolean) setHosts(Collection) for host changes and the corresponding trigger to rebuildPartitions()
when this happens.
Note that when the connection pool is started it fetches the list of seed hosts from config (if any) and then inits it's data structures using these seed hosts.
It also employs a listener to the latency score updates so that it can rebuild partitions as and when it receives updates
Execute with failover
The class also provides a basic implementation of executeWithFailover(Operation, RetryPolicy) by repeatedly consulting the RetryPolicy. Note that extending classes
must provide impl for the actual execute with failover. e.g the RoundRobinConnectionPoolImpl fails over to the next HostConnectionPool in the list.
RoundRobinConnectionPoolImpl} {@link BagOfConnectionsConnectionPoolImpl} {@link TokenAwareConnectionPoolImpl} for details on impls that extend this class,
TokenPartitionedTopology} for how the internal topology structure is maintained across the set of hosts| Field Summary | |
|---|---|
protected ConnectionPoolConfiguration |
config
|
protected ConnectionFactory<CL> |
factory
|
protected org.cliffc.high_scale_lib.NonBlockingHashMap<Host,HostConnectionPool<CL>> |
hosts
|
protected ConnectionPoolMonitor |
monitor
|
protected Partitioner |
partitioner
|
protected Topology<CL> |
topology
|
| Constructor Summary | |
|---|---|
AbstractHostPartitionConnectionPool(ConnectionPoolConfiguration config,
ConnectionFactory<CL> factory,
ConnectionPoolMonitor monitor)
|
|
| Method Summary | ||
|---|---|---|
boolean |
addHost(Host host,
boolean refresh)
Add host to the system. |
|
|
executeWithFailover(Operation<CL,R> op,
RetryPolicy retry)
Executes the operation using failover and retry strategy |
|
java.util.List<HostConnectionPool<CL>> |
getActivePools()
list of all active pools |
|
HostConnectionPool<CL> |
getHostPool(Host host)
|
|
Partitioner |
getPartitioner()
|
|
java.util.List<HostConnectionPool<CL>> |
getPools()
|
|
Topology<CL> |
getTopology()
|
|
boolean |
hasHost(Host host)
|
|
boolean |
isHostUp(Host host)
|
|
protected abstract
|
newExecuteWithFailover(Operation<CL,R> op)
Return a new failover context. |
|
protected HostConnectionPool<CL> |
newHostConnectionPool(Host host,
ConnectionFactory<CL> factory,
ConnectionPoolConfiguration config)
|
|
void |
onHostDown(HostConnectionPool<CL> pool)
Host is marked as down |
|
void |
onHostUp(HostConnectionPool<CL> pool)
Host is marked as up |
|
protected void |
rebuildPartitions()
Called every time a host is added, removed or is marked as down |
|
boolean |
removeHost(Host host,
boolean refresh)
Remove host from the system. |
|
void |
setHosts(java.util.Collection<Host> ring)
Set the complete set of hosts in the ring |
|
void |
shutdown()
Clean up resources associated with the conn pool |
|
void |
start()
Starts the conn pool and resources associated with it |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final org.cliffc.high_scale_lib.NonBlockingHashMap<Host,HostConnectionPool<CL>> hosts
protected final ConnectionPoolConfiguration config
protected final ConnectionFactory<CL> factory
protected final ConnectionPoolMonitor monitor
protected final Topology<CL> topology
protected final Partitioner partitioner
| Constructor Detail |
|---|
public AbstractHostPartitionConnectionPool(ConnectionPoolConfiguration config,
ConnectionFactory<CL> factory,
ConnectionPoolMonitor monitor)
config - factory - monitor - | Method Detail |
|---|
public void start()
start in interface ConnectionPool<CL>public void shutdown()
shutdown in interface ConnectionPool<CL>
protected HostConnectionPool<CL> newHostConnectionPool(Host host,
ConnectionFactory<CL> factory,
ConnectionPoolConfiguration config)
public void onHostDown(HostConnectionPool<CL> pool)
onHostDown in interface SimpleHostConnectionPool.Listener<CL>pool - public void onHostUp(HostConnectionPool<CL> pool)
onHostUp in interface SimpleHostConnectionPool.Listener<CL>pool -
public final boolean addHost(Host host,
boolean refresh)
addHost in interface ConnectionPool<CL>host - refresh - public boolean isHostUp(Host host)
isHostUp in interface ConnectionPool<CL>public boolean hasHost(Host host)
hasHost in interface ConnectionPool<CL>public java.util.List<HostConnectionPool<CL>> getActivePools()
getActivePools in interface ConnectionPool<CL>Listpublic java.util.List<HostConnectionPool<CL>> getPools()
getPools in interface ConnectionPool<CL>List
public boolean removeHost(Host host,
boolean refresh)
removeHost in interface ConnectionPool<CL>host - refresh - public HostConnectionPool<CL> getHostPool(Host host)
getHostPool in interface ConnectionPool<CL>host -
HostConnectionPoolpublic void setHosts(java.util.Collection<Host> ring)
ConnectionPool
setHosts in interface ConnectionPool<CL>ring -
public <R> OperationResult<R> executeWithFailover(Operation<CL,R> op,
RetryPolicy retry)
throws ConnectionException
executeWithFailover in interface ConnectionPool<CL>op - retry -
OperationResult
ConnectionException
OperationException
protected abstract <R> ExecuteWithFailover<CL,R> newExecuteWithFailover(Operation<CL,R> op)
throws ConnectionException
R -
ConnectionExceptionprotected void rebuildPartitions()
public Topology<CL> getTopology()
getTopology in interface ConnectionPool<CL>Topologypublic Partitioner getPartitioner()
getPartitioner in interface ConnectionPool<CL>Partitioner
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||