Class ConnectionPool
java.lang.Object
org.serviceconnector.net.connection.ConnectionPool
The Class ConnectionPool. Concrete implementation of connection pooling.
This connection pool takes care of following listed points:
- creating / destroying of connections
- observing the max numbers of connections
- keeping a minimum of connections active
- disconnect connection after Constants.DEFAULT_NR_OF_KEEP_ALIVES_TO_CLOSE
- destroying connection pool, destroys all connections
optional functions:
- closing connection after getting it back
- initializing pool by starting a minimum of connections immediately
- observing connection idle timeout and sending keep alive messages to refresh firewall
- force closing of a specific connection, very useful if connection has a curious state
This connection pool takes care of following listed points:
- creating / destroying of connections
- observing the max numbers of connections
- keeping a minimum of connections active
- disconnect connection after Constants.DEFAULT_NR_OF_KEEP_ALIVES_TO_CLOSE
- destroying connection pool, destroys all connections
optional functions:
- closing connection after getting it back
- initializing pool by starting a minimum of connections immediately
- observing connection idle timeout and sending keep alive messages to refresh firewall
- force closing of a specific connection, very useful if connection has a curious state
- Author:
- JTraber
-
Constructor Summary
ConstructorsConstructorDescriptionConnectionPool(String host, int port, String conType, int keepAliveIntervalSeconds, int keepAliveOTIMillis) Instantiates a new connection pool. -
Method Summary
Modifier and TypeMethodDescriptionvoidconnectionIdle(IConnection connection) Connection idle.voiddestroy()Destroy the pool.voiddump(XMLDumpWriter writer) Dump the connection pool into the xml writer.protected voidfinalize()voidforceClosingConnection(IConnection connection, boolean quietClose) Force closing specific connection.voidfreeConnection(IConnection connection) Free connection.intGets the number of busy connections at this time.Gets a connection of the pool.Gets the free connections.getHost()Gets the host.intGets the keep alive interval the pool is observing. 0 means disabled.intGets the max connections.intGets the min connections.intgetPort()Gets the port.Gets the used connections.booleanChecks for free connections in the pool.voidInitiates the minimum connections.voidsetCloseAfterKeepAlive(boolean closeAfterKeepAlive) Sets the close after keep alive.voidsetCloseOnFree(boolean closeOnFree) Sets the close on free.voidsetMaxConnections(int maxConnections) Sets the max connections for the pool.voidsetMinConnections(int minConnections) Sets the minimum connections for the pool.
-
Constructor Details
-
Method Details
-
getConnection
Gets a connection of the pool.- Returns:
- the connection
- Throws:
Exception- the exception
-
freeConnection
Free connection. Gives connection back for other interested parties.- Parameters:
connection- the connection
-
setMaxConnections
public void setMaxConnections(int maxConnections) Sets the max connections for the pool.- Parameters:
maxConnections- the new max connections
-
destroy
public void destroy()Destroy the pool. -
forceClosingConnection
Force closing specific connection.- Parameters:
connection- the connectionquietClose- the quiet close
-
setCloseOnFree
public void setCloseOnFree(boolean closeOnFree) Sets the close on free. Indicates that connection should be closed at the time they get freed.- Parameters:
closeOnFree- the new close on free
-
setCloseAfterKeepAlive
public void setCloseAfterKeepAlive(boolean closeAfterKeepAlive) Sets the close after keep alive. Indicates that a connection gets closed after Constants.DEFAULT_NR_OF_KEEP_ALIVES_TO_CLOSE.- Parameters:
closeAfterKeepAlive- the new close after keep alive
-
setMinConnections
public void setMinConnections(int minConnections) Sets the minimum connections for the pool.- Parameters:
minConnections- the new minimum connections
-
initMinConnections
public void initMinConnections()Initiates the minimum connections. The minimum of connections gets active immediately. -
getMaxConnections
public int getMaxConnections()Gets the max connections.- Returns:
- the max connections
-
getMinConnections
public int getMinConnections()Gets the min connections.- Returns:
- the min connections
-
getBusyConnections
public int getBusyConnections()Gets the number of busy connections at this time.- Returns:
- the busy connections
-
hasFreeConnections
public boolean hasFreeConnections()Checks for free connections in the pool.- Returns:
- true, if successful
-
connectionIdle
Connection idle. Process idle event of connection. Sending of keep alive does not need to be synchronized.- Parameters:
connection- the connection
-
getKeepAliveInterval
public int getKeepAliveInterval()Gets the keep alive interval the pool is observing. 0 means disabled.- Returns:
- the keep alive interval
-
getHost
Gets the host.- Returns:
- the host
-
getPort
public int getPort()Gets the port.- Returns:
- the port
-
getFreeConnections
Gets the free connections.- Returns:
- the free connections
-
getUsedConnections
Gets the used connections.- Returns:
- the used connections
-
finalize
-
dump
Dump the connection pool into the xml writer.- Parameters:
writer- the writer- Throws:
Exception- the exception
-