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

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

public final class ConnectionManager
extends java.lang.Object
implements IConnectionManager

The manager of the connections and of the pools. It is a singleton since all it does is providing the methods for accessing the pool. The logic is all in the pool. To request a connection it is just necessary to call the checkOut() methods with the appropriate parameters. If a pool for that connection is not available, it will be created, otherwise it will get the one already available and return a connection from there.

To return a connection to the pool, it is necessary to use the checkIn() method.

The release() method is not yet implemented.

Author:
Milo Casagrande

Method Summary
 void checkIn(IConnection connection)
          Give a connection back to the pool
 IConnection checkOut(java.lang.String address, int port)
          Take a connection from the pool.
 IConnection checkOut(java.lang.String address, int port, int capacity)
          Take a connection from the pool.
static ConnectionManager getInstance()
          Get the instance of the manager
 int getPoolSize(java.lang.String address, int port)
          Retrieve the actual size of the pool identified by this address and port
 void release()
          Release all the connection in the pool NOT IMPLEMENTED YET
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ConnectionManager getInstance()
Get the instance of the manager

Returns:
the singleton instance of the ConnectionManager

checkOut

public IConnection checkOut(java.lang.String address,
                            int port)
Description copied from interface: IConnectionManager
Take a connection from the pool. If there is no pool, a new one is initialized with capacity set to zero, meaning that there is no limit in the pool.

Specified by:
checkOut in interface IConnectionManager
Parameters:
address - the address of the connection
port - the port of the connection
Returns:
an open connection, or null

checkOut

public IConnection checkOut(java.lang.String address,
                            int port,
                            int capacity)
Description copied from interface: IConnectionManager
Take a connection from the pool. If there is no pool, a new one is created with capacity set to capacity.

Specified by:
checkOut in interface IConnectionManager
Parameters:
address - the address of the connection
port - the port of the connection
capacity - the capacity of the pool
Returns:
an open connection, or null

checkIn

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

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

getPoolSize

public int getPoolSize(java.lang.String address,
                       int port)
Description copied from interface: IConnectionManager
Retrieve the actual size of the pool identified by this address and port

Specified by:
getPoolSize in interface IConnectionManager
Parameters:
address - the address of the connection
port - the port of the connection
Returns:
the size of the pool identified by address and port

release

public void release()
Description copied from interface: IConnectionManager
Release all the connection in the pool

NOT IMPLEMENTED YET

Specified by:
release in interface IConnectionManager