com.ibm.jtopenlite
Class HostServerConnectionPool<T extends HostServerConnection>

java.lang.Object
  extended by com.ibm.jtopenlite.HostServerConnectionPool<T>

public class HostServerConnectionPool<T extends HostServerConnection>
extends Object

Used to pool HostServerConnections of a specific type to a specific system. For example:

   // 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 Summary
HostServerConnectionPool(SystemInfo info)
          Constructs a new connection pool for the specified system.
 
Method Summary
 void checkin(T conn)
          Adds or returns a connection to this pool.
 T checkout(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(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(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(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(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(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(String user)
          Returns the number of used connections for the specified user in this pool.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HostServerConnectionPool

public HostServerConnectionPool(SystemInfo info)
Constructs a new connection pool for the specified system. All connections checked into this pool must have a matching SystemInfo object.

Method Detail

getInfo

public SystemInfo getInfo()
Returns the system information for this pool.


finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

checkin

public void checkin(T conn)
             throws IOException
Adds or returns a connection to this pool. If the connection is closed or its SystemInfo does not match what was defined for this pool, the connection is removed from this pool if it already exists in this pool, but is otherwise ignored.

Throws:
IOException

checkout

public T checkout(String user)
                                        throws IOException
Obtains a free connection from this pool for the specified user. If there are no free connections in the pool for the specified user, null is returned.

Throws:
IOException

remove

public void remove(T conn)
Removes the specified connection from this pool, regardless if it is free or in use. If the connection is not in the pool, it is ignored.


close

public void close()
           throws IOException
Closes and removes all connections in this pool, both free and in use.

Throws:
IOException

closeFree

public void closeFree()
               throws IOException
Closes and removes all free connections in this pool.

Throws:
IOException

closeUsed

public void closeUsed()
               throws IOException
Closes and removes all in-use connections in this pool.

Throws:
IOException

close

public void close(String user)
           throws IOException
Closes and removes all connections for the specified user in this pool, both free and in use.

Throws:
IOException

closeFree

public void closeFree(String user)
               throws IOException
Closes and removes all free connections for the specified user in this pool.

Throws:
IOException

closeUsed

public void closeUsed(String user)
               throws IOException
Closes and removes all in-use connections for the specified user in this pool.

Throws:
IOException

getConnectionCount

public int getConnectionCount()
Returns the total number of connections in this pool, both free and in use.


getFreeConnectionCount

public int getFreeConnectionCount()
Returns the number of free connections in this pool.


getUsedConnectionCount

public int getUsedConnectionCount()
Returns the number of in-use connections in this pool.


getConnectionCount

public int getConnectionCount(String user)
Returns the total number of connections for the specified user in this pool, both free and in use.


getFreeConnectionCount

public int getFreeConnectionCount(String user)
Returns the number of free connections for the specified user in this pool.


getUsedConnectionCount

public int getUsedConnectionCount(String user)
Returns the number of used connections for the specified user in this pool.


getUsers

public String[] getUsers()
Returns an array of users of connections in this pool, both free and in use.