public class HostServerConnectionPool<T extends HostServerConnection>
extends java.lang.Object
// Get the SystemInfo object used to seed our pool. SignonConnection signon = SignonConnection.getConnection("system", "user", "password"); SystemInfo info = signon.getInfo(); signon.close(); // Construct the pool (initially empty). HostServerConnectionPool<CommandConnection> commandPool = new HostServerConnectionPool<CommandConnection>(info); // To populate the pool, create connections and check them in. // To use the pool, check out connections from the pool. CommandConnection conn = CommandConnection.getConnection(info, "FRED", "password"); commandPool.checkin(conn); conn = commandPool.checkout("FRED"); commandPool.checkin(conn); // You can check the current size of the pool. int used = commandPool.getUsedConnectionCount(); int free = commandPool.getFreeConnectionCount(); // You can check the number of connections per user. int fredUsed = commandPool.getUsedConnectionCount("FRED"); int fredFree = commandPool.getFreeConnectionCount("FRED"); // Closing the pool will close all connections in the pool, both free and in use. commandPool.close();
Constructor and Description |
---|
HostServerConnectionPool(SystemInfo info)
Constructs a new connection pool for the specified system.
|
Modifier and Type | Method and Description |
---|---|
void |
checkin(T conn)
Adds or returns a connection to this pool.
|
T |
checkout(java.lang.String user)
Obtains a free connection from this pool for the specified user.
|
void |
close()
Closes and removes all connections in this pool, both free and in use.
|
void |
close(java.lang.String user)
Closes and removes all connections for the specified user in this pool, both free and in use.
|
void |
closeFree()
Closes and removes all free connections in this pool.
|
void |
closeFree(java.lang.String user)
Closes and removes all free connections for the specified user in this pool.
|
void |
closeUsed()
Closes and removes all in-use connections in this pool.
|
void |
closeUsed(java.lang.String user)
Closes and removes all in-use connections for the specified user in this pool.
|
protected void |
finalize() |
int |
getConnectionCount()
Returns the total number of connections in this pool, both free and in use.
|
int |
getConnectionCount(java.lang.String user)
Returns the total number of connections for the specified user in this pool, both free and in use.
|
int |
getFreeConnectionCount()
Returns the number of free connections in this pool.
|
int |
getFreeConnectionCount(java.lang.String user)
Returns the number of free connections for the specified user in this pool.
|
SystemInfo |
getInfo()
Returns the system information for this pool.
|
int |
getUsedConnectionCount()
Returns the number of in-use connections in this pool.
|
int |
getUsedConnectionCount(java.lang.String user)
Returns the number of used connections for the specified user in this pool.
|
java.lang.String[] |
getUsers()
Returns an array of users of connections in this pool, both free and in use.
|
void |
remove(T conn)
Removes the specified connection from this pool, regardless if it is free or in use.
|
public HostServerConnectionPool(SystemInfo info)
public SystemInfo getInfo()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void checkin(T conn) throws java.io.IOException
java.io.IOException
public T checkout(java.lang.String user) throws java.io.IOException
java.io.IOException
public void remove(T conn)
public void close() throws java.io.IOException
java.io.IOException
public void closeFree() throws java.io.IOException
java.io.IOException
public void closeUsed() throws java.io.IOException
java.io.IOException
public void close(java.lang.String user) throws java.io.IOException
java.io.IOException
public void closeFree(java.lang.String user) throws java.io.IOException
java.io.IOException
public void closeUsed(java.lang.String user) throws java.io.IOException
java.io.IOException
public int getConnectionCount()
public int getFreeConnectionCount()
public int getUsedConnectionCount()
public int getConnectionCount(java.lang.String user)
public int getFreeConnectionCount(java.lang.String user)
public int getUsedConnectionCount(java.lang.String user)
public java.lang.String[] getUsers()