Search This Blog

Tuesday 23 February 2010

Universal Connection Pool (UCP) / Fast Connection Failover (FCF)

I wanted to verify a UCP and how it works with FCF. I had previously used ICC/FCF which UCP/FCF now replaces. Development confirmed it is pretty much the same as explained below.

The basic usage model for FCF in UCP is the same as back in ICC. The user gets a Connection, performs JDBC operations on it, gets an exception from a RAC failure, reconnects and recovers if necessary. The main difference from ICC usage is the isValid() API that UCP provides, so that users do not need to check hard-coded exception error codes when deciding whether to reconnect.

So in short code as follows can now be added avoiding the need to check for error codes to determine if indeed a connection needs to reconnect.


public void run () throws SQLException
{
Connection conn = null;

try
{
counter++;
conn = pool.getConnection();
getInstanceDetails(conn, counter);
pool.displayDetails();
}
catch (SQLException sqle)
{
// The recommended way to check connection usability after a
// RAC-down event triggers UCP FCF actions.
if (conn == null || !((ValidConnection) conn).isValid())
{
logger.log
(Level.INFO,
"** FCFTest : Connection retry necessary : " + sqle.getMessage());

// Use UCP's FCF-specific statistics to verify the pool's
// FCF actions.
OracleJDBCConnectionPoolStatistics stats =
(OracleJDBCConnectionPoolStatistics) pool.getStats();

logger.log
(Level.INFO,
"** FCFTest : " + stats.getFCFProcessingInfo());
}
else
{
logger.log
(Level.SEVERE,
"** FCFTest : Exception occurred ->");
sqle.printStackTrace();
}
}
finally
{
try
{
pool.returnConnection(conn);
}
catch (SQLException se)
{
// not much we can do here
logger.log
(Level.INFO,
"** FCFTest : Exception detected when closing connection ");
se.printStackTrace();
}
}
}

No comments: