|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.basho.riak.pbc.RiakConnectionPool
public class RiakConnectionPool
A bounded or boundless pool of RiakConnections to be reused by RiakClient
The pool is designed to be threadsafe, and ideally to be used as a singleton.
Due to backwards compatibility requirements it has not been implemented as a singleton.
This is really a host connection pool. There is a minor optimization for reusing a connection
by client Id, but more work needs doing here.
| Field Summary | |
|---|---|
static int |
LIMITLESS
Constant to use for maxSize when creating an unbounded pool |
| Constructor Summary | |
|---|---|
RiakConnectionPool(int initialSize,
int maxSize,
InetAddress host,
int port,
long connectionWaitTimeoutMillis,
int bufferSizeKb,
long idleConnectionTTLMillis)
Crate a new host connection pool. |
|
RiakConnectionPool(int initialSize,
Semaphore poolSemaphore,
InetAddress host,
int port,
long connectionWaitTimeoutMillis,
int bufferSizeKb,
long idleConnectionTTLMillis)
Crate a new host connection pool. |
|
| Method Summary | |
|---|---|
com.basho.riak.pbc.RiakConnection |
getConnection(byte[] clientId)
Get a connection from the pool for the given client Id. |
String |
getPoolState()
Convenience method to check the state of the pool. |
static Semaphore |
getSemaphore(int maxSize)
Create the correct type of semaphore for the maxSize, zero is limitless. |
void |
releaseConnection(com.basho.riak.pbc.RiakConnection c)
Returns a connection to the pool (unless the connection is closed (for some reason)) |
void |
shutdown()
Close this pool and all its connections. |
void |
start()
Starts the reaper thread |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int LIMITLESS
maxSize when creating an unbounded pool
| Constructor Detail |
|---|
public RiakConnectionPool(int initialSize,
int maxSize,
InetAddress host,
int port,
long connectionWaitTimeoutMillis,
int bufferSizeKb,
long idleConnectionTTLMillis)
throws IOException
initialSize - the number of connections to create at pool creation timemaxSize - the maximum number of connections this pool will have at any
one time, 0 means limitless (i.e. creates a new connection if
none are available)host - the host this pool holds connections toport - the port on host that this pool holds connections toconnectionWaitTimeoutMillis - the connection timeoutbufferSizeKb - the size of the socket/stream read/write buffers (3 buffers,
each of this size)idleConnectionTTLMillis - How long for an idle connection to exist before it is reaped,
0 mean forever
IOException - If the initial connection creation throws an IOException
public RiakConnectionPool(int initialSize,
Semaphore poolSemaphore,
InetAddress host,
int port,
long connectionWaitTimeoutMillis,
int bufferSizeKb,
long idleConnectionTTLMillis)
throws IOException
initialSize - the number of connections to create at pool creation timeclusterSemaphore - a Semaphore set with the number of permits for the
pool (and maybe cluster (see PoolSemaphore))host - the host this pool holds connections toport - the port on host that this pool holds connections toconnectionWaitTimeoutMillis - the connection timeoutbufferSizeKb - the size of the socket/stream read/write buffers (3 buffers,
each of this size)idleConnectionTTLMillis - How long for an idle connection to exist before it is reaped,
0 mean forever
IOException - If the initial connection creation throws an IOException| Method Detail |
|---|
public void start()
public static Semaphore getSemaphore(int maxSize)
maxSize, zero is limitless.
- Parameters:
maxSize - the number of permits to create a semaphore for
- Returns:
- a
Semaphore with maxSize permits, or a
LimitlessSemaphore if maxSize is zero or less.
public com.basho.riak.pbc.RiakConnection getConnection(byte[] clientId)
throws IOException
clientId - the client id of the connection requested
IOException
AcquireConnectionTimeoutException - if unable to acquire a permit to create a *new* connection
within the timeout configured. This means that the pool has
no available connections and there are no permits available to
create new connections. Repeated incidences of this exception
probably indicate that you have sized your pool too small.public void releaseConnection(com.basho.riak.pbc.RiakConnection c)
c - the connection to return.public void shutdown()
IllegalStateException for calls to getConnection. While shutting
down it will still accept calls to releaseConnection.
public String getPoolState()
State of the pool
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||