com.netflix.astyanax.connectionpool.impl
Class AbstractHostPartitionConnectionPool<CL>

java.lang.Object
  extended by com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool<CL>
Type Parameters:
CL -
All Implemented Interfaces:
ConnectionPool<CL>, SimpleHostConnectionPool.Listener<CL>
Direct Known Subclasses:
BagOfConnectionsConnectionPoolImpl, RoundRobinConnectionPoolImpl, TokenAwareConnectionPoolImpl

public abstract class AbstractHostPartitionConnectionPool<CL>
extends Object
implements ConnectionPool<CL>, SimpleHostConnectionPool.Listener<CL>

Base for all connection pools that keep a separate pool of connections for each host.

Author:
elandau

Field Summary
protected  ConnectionPoolConfiguration config
           
protected  ConnectionFactory<CL> factory
           
protected  org.cliffc.high_scale_lib.NonBlockingHashMap<Host,HostConnectionPool<CL>> hosts
           
protected  ConnectionPoolMonitor monitor
           
protected  Topology<CL> topology
           
 
Constructor Summary
AbstractHostPartitionConnectionPool(ConnectionPoolConfiguration config, ConnectionFactory<CL> factory, ConnectionPoolMonitor monitor)
           
 
Method Summary
 boolean addHost(Host host, boolean refresh)
          Add a host to the connection pool.
<R> OperationResult<R>
executeWithFailover(Operation<CL,R> op, RetryPolicy retry)
          Execute an operation with failover within the context of the connection pool.
 List<HostConnectionPool<CL>> getActivePools()
          Return list of active hosts on which connections can be created
 HostConnectionPool<CL> getHostPool(Host host)
          Return an immutable connection pool for this host
 boolean hasHost(Host host)
          Return true if host is contained within the connection pool
 boolean isHostUp(Host host)
          Return true if the host is up
protected abstract
<R> ExecuteWithFailover<CL,R>
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)
           
 void onHostUp(HostConnectionPool<CL> pool)
           
protected  void rebuildPartitions()
          Called every time a host is added, removed or is marked as down
 boolean removeHost(Host host, boolean refresh)
          Remove a host from the connection pool.
 void setHosts(Map<BigInteger,List<Host>> ring)
          Sets the complete set of hosts keyed by token.
 void shutdown()
          Shut down the connection pool and terminate all existing connections
 void start()
          Setup the connection pool and start any maintenance threads
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hosts

protected final org.cliffc.high_scale_lib.NonBlockingHashMap<Host,HostConnectionPool<CL>> hosts

config

protected final ConnectionPoolConfiguration config

factory

protected final ConnectionFactory<CL> factory

monitor

protected final ConnectionPoolMonitor monitor

topology

protected final Topology<CL> topology
Constructor Detail

AbstractHostPartitionConnectionPool

public AbstractHostPartitionConnectionPool(ConnectionPoolConfiguration config,
                                           ConnectionFactory<CL> factory,
                                           ConnectionPoolMonitor monitor)
Method Detail

start

public void start()
Description copied from interface: ConnectionPool
Setup the connection pool and start any maintenance threads

Specified by:
start in interface ConnectionPool<CL>

shutdown

public void shutdown()
Description copied from interface: ConnectionPool
Shut down the connection pool and terminate all existing connections

Specified by:
shutdown in interface ConnectionPool<CL>

newHostConnectionPool

protected HostConnectionPool<CL> newHostConnectionPool(Host host,
                                                       ConnectionFactory<CL> factory,
                                                       ConnectionPoolConfiguration config)

onHostDown

public void onHostDown(HostConnectionPool<CL> pool)
Specified by:
onHostDown in interface SimpleHostConnectionPool.Listener<CL>

onHostUp

public void onHostUp(HostConnectionPool<CL> pool)
Specified by:
onHostUp in interface SimpleHostConnectionPool.Listener<CL>

addHost

public final boolean addHost(Host host,
                             boolean refresh)
Description copied from interface: ConnectionPool
Add a host to the connection pool.

Specified by:
addHost in interface ConnectionPool<CL>

isHostUp

public boolean isHostUp(Host host)
Description copied from interface: ConnectionPool
Return true if the host is up

Specified by:
isHostUp in interface ConnectionPool<CL>
Returns:

hasHost

public boolean hasHost(Host host)
Description copied from interface: ConnectionPool
Return true if host is contained within the connection pool

Specified by:
hasHost in interface ConnectionPool<CL>
Returns:

getActivePools

public List<HostConnectionPool<CL>> getActivePools()
Description copied from interface: ConnectionPool
Return list of active hosts on which connections can be created

Specified by:
getActivePools in interface ConnectionPool<CL>
Returns:

removeHost

public boolean removeHost(Host host,
                          boolean refresh)
Description copied from interface: ConnectionPool
Remove a host from the connection pool. Any pending connections will be allowed to complete

Specified by:
removeHost in interface ConnectionPool<CL>

getHostPool

public HostConnectionPool<CL> getHostPool(Host host)
Description copied from interface: ConnectionPool
Return an immutable connection pool for this host

Specified by:
getHostPool in interface ConnectionPool<CL>
Returns:

setHosts

public void setHosts(Map<BigInteger,List<Host>> ring)
Description copied from interface: ConnectionPool
Sets the complete set of hosts keyed by token.

Specified by:
setHosts in interface ConnectionPool<CL>

executeWithFailover

public <R> OperationResult<R> executeWithFailover(Operation<CL,R> op,
                                                  RetryPolicy retry)
                                       throws ConnectionException
Description copied from interface: ConnectionPool
Execute an operation with failover within the context of the connection pool. The operation will only fail over for connection pool errors and not application errors.

Specified by:
executeWithFailover in interface ConnectionPool<CL>
Returns:
Throws:
ConnectionException
OperationException

newExecuteWithFailover

protected abstract <R> ExecuteWithFailover<CL,R> newExecuteWithFailover(Operation<CL,R> op)
                                                             throws ConnectionException
Return a new failover context. The context captures the connection pool state and implements the necessary failover logic.

Type Parameters:
R -
Returns:
Throws:
ConnectionException

rebuildPartitions

protected void rebuildPartitions()
Called every time a host is added, removed or is marked as down



Copyright © 2012. All Rights Reserved.