com.mymed.controller.core.manager.connection
Class ConnectionPool

java.lang.Object
  extended by com.mymed.controller.core.manager.connection.ConnectionPool
All Implemented Interfaces:
IConnectionPool

public class ConnectionPool
extends java.lang.Object
implements IConnectionPool

Implementation of a connection pool

Author:
Milo Casagrande

Constructor Summary
ConnectionPool(java.lang.String address, int port)
          Create a new connection pool with a maximum capacity of 100.
ConnectionPool(java.lang.String address, int port, int capacity)
          Create a new connection pool with initial capacity defined by capacity.
 
Method Summary
 void checkIn(IConnection connection)
          Give a connection back to the pool
 IConnection checkOut()
          Get a connection from the pool
 int getCapacity()
          Get the maximum capacity of the pool
 int getSize()
          Get the size of the pool, or how many connections are in it
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(java.lang.String address,
                      int port)
Create a new connection pool with a maximum capacity of 100.

Parameters:
address - the address where to connect to
port - the port to use for the connection

ConnectionPool

public ConnectionPool(java.lang.String address,
                      int port,
                      int capacity)
Create a new connection pool with initial capacity defined by capacity. If capacity is zero, the pool is limit-less.

Parameters:
address - the address where to connect to
port - the port to use for the connection
capacity - the maximum capacity of the pool
Method Detail

checkOut

public IConnection checkOut()
Description copied from interface: IConnectionPool
Get a connection from the pool

Specified by:
checkOut in interface IConnectionPool
Returns:
the first available connection

checkIn

public void checkIn(IConnection connection)
Description copied from interface: IConnectionPool
Give a connection back to the pool

Specified by:
checkIn in interface IConnectionPool
Parameters:
connection - the connection to return to the pool

getSize

public int getSize()
Description copied from interface: IConnectionPool
Get the size of the pool, or how many connections are in it

Specified by:
getSize in interface IConnectionPool
Returns:
the actual size of the pool

getCapacity

public int getCapacity()
Description copied from interface: IConnectionPool
Get the maximum capacity of the pool

Specified by:
getCapacity in interface IConnectionPool
Returns:
the maximum capacity of the pool