Skip Headers
Oracle® Universal Connection Pool for JDBC Developer's Guide
12c Release 1 (12.1)

E17659-11
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

9 Ensuring Application Continuity

Oracle Database 12c Release 1 (12.1) introduces the Application Continuity feature that provides a general purpose, application-independent infrastructure. Application Continuity enables recovery of work from an application perspective, after the occurrence of a planned or unplanned outage that can be related to system, communication, or hardware following a repair, a configuration change, or a patch application.

See Also:

Oracle Database Development Guide for more information about Application Continuity

For using Application Continuity, you must first configure your data source as described in "Data Source Configuration". After that, use one of the following two features for implementing Application Continuity in your applications using Universal Connection Pool (UCP) for JDBC:

Data Source Configuration

To utilize the Application Continuity feature on a pool-enabled data source, the application must make the following call on oracle.ucp.jdbc.PoolDataSource interface:

// pds is a PoolDataSource
pds.setConnectionFactoryClassName("oracle.jdbc.replay.OracleDataSourceImpl");

Always connect to a service, instead of using SID. Application Continuity is not supported when connecting in the SID syntax.

See Also:

Oracle Database Development Guide for more information about Application Continuity

When running against Oracle Real Application Clusters (Oracle RAC) or Data Guard, the application should also enable Fast Connection Failover (FCF) as shown in the following code snippet:

pds.setFastConnectionFailoverEnabled(true);
pds.setONSConfiguration("......");  // Oracle RAC ONS configuration

See Also:

"Enabling Fast Connection Failover" for more information

Connection Labeling

Connection labeling enables an application to attach arbitrary name/value pairs to a connection. The application can request a connection with the desired label from the connection pool.

See Also:

"Labeling Connections in UCP" for more information labeling connections

Connection labeling sets the initial state for each connection request. If the application uses connection labeling or benefits from labeling connections, then a labeling callback should be registered for Application Continuity to initialize clean connections at failover.

Every time Application Continuity gets a new connection from the underlying data source, the labeling callback executes. The callback executes during normal connection check-out and also during replay. So, the state that is created at runtime is exactly re-created during replay. The initialization must be idempotent.

It is legal for the callback to execute a transaction as long as the transaction completes (either it commits or rolls back) at the end of callback invocation. Application Continuity repeats any action coded within the callback implementation, including such transaction. If an outage occurs during the execution of a UCP labeling callback, then Application Continuity may execute the callback more than once as part of the replay attempt. Again, it is important for the callback actions to be idempotent.

Connection Initialization Callback

If an application cannot use connection labeling because it cannot be changed, then the connection initialization callback is provided for such an application.

When registered, the initialization callback is executed every time a connection is borrowed from the pool and at each successful reconnection following a recoverable error. Using the same callback at both run time and replay ensures that exactly the same initialization, which was used when the original session was established, is reestablished at runtime. If the callback invocation fails, then replay is disabled on that connection.

This section discusses initialization callbacks in the following sections:

Creating an Initialization Callback

To create a UCP connection initialization callback, an application implements the oracle.ucp.jdbc.ConnectionInitializationCallback interface. This interface has the following method:

void initialize(java.sql.Connection connection) throws SQLException;

Note:

  • One callback is created for every connection pool.

  • This callback is not used if a labeling callback is registered for the connection pool.

Example

The following example demonstrates how to create a simple initialization callback:

import oracle.ucp.jdbc.ConnectionInitializationCallback;
class MyConnectionInitializationCallback implements ConnectionInitializationCallback
{
  public MyConnectionInitializationCallback()
  {
    ...
  }
  public void initialize(java.sql.Connection connection) throws SQLException
  {
     // Reset the state for the connection, if necessary (like ALTER SESSION)
  }
}

Registering an Initialization Callback

UCP provides the registerConnectionInitializationCallback method in the oracle.ucp.jdbc.PoolDataSource interface for registering a connection initialization callback.

public void registerConnectionInitializationCallback (ConnectionInitializationCallback cbk) throws SQLException;

One callback may be registered on each connection pool instance.

Removing or Unregistering an Initialization Callback

UCP provides the unregisterConnectionInitializationCallback method in the oracle.ucp.jdbc.PoolDataSource interface for unregistering a connection initialization callback.

public void unregisterConnectionInitializationCallback (ConnectionInitializationCallback cbk) throws SQLException;