3.2 Connection Management Architecture
To understand how the connection management architecture works, let's look at Figure 3.2, which shows connection management for an application in a managed environment.
Figure 3.2. Connection Management.
The resource adapter provides interfaces for an application component to create a connection to an EIS using a connection factory. An application component that wants to connect to an underlying EIS uses the services of the resource adapter.
Specific steps occur when an application component attempts to establish a connection to an EIS. However, prior to this, the deployer configures the JNDI namespace to include a connection factory. (This is marked as step 1 in Figure 3.2.) The connection factory carries the configuration information, specifically the EIS server and port number, required to create connections to the EIS. Briefly, here is what happens when an application component tries to establish a connection to an EIS.
The application component begins by doing a JNDI lookup of a connection factory from the JNDI namespace.
The application component, after successfully locating a connection factory, calls a method on the connection factory to create a connection to the EIS. It uses the connection factory to obtain a connection to the underlying EIS.
Before it creates the connection, the connection factory, which is provided by the resource adapter, delegates the connection request to the application server using the connection management contract. The application server provides a connection pool, along with other services such as transaction management, security management, and error logging.
The application server, when it receives a request to create a connection, attempts to find a suitable existing connection in the application server's connection pool. The connections in the pool are called managed connections. A managed connection represents an actual physical connection to the underlying EIS. If the application server finds a matching connection in the pool, it uses that matching managed connection to satisfy the application's connection request.
If the application server cannot find a matching connection in the pool, then it uses the resource adapter to create a new physical connectionâ€”also represented by a managed connectionâ€”to the underlying EIS.
The resource adapter for the EIS creates a new managed connection by establishing a physical connection to the EIS. A resource adapter returns the newly created managed connection to the application server.
The application server adds the new managed connection to its connection pool. As part of this process, the application server creates an application-level connection handle for the managed connection. The application server returns this connection handle to the resource adapter, which in turn returns it to the application component.
The application component uses the connection handle returned by the resource adapter to access the EIS.
When the application component completes its work with the connection, it closes the connection handle.
What does all this mean to an application? Essentially, the connection management contract enables an application server to offer a number of important benefits to an application.
It eliminates any dependencies of the application on the connection pooling and keeps the connection pooling transparent to an application. Because connection pooling is implemented independently from an application, the application need not have any knowledge of how the application server accomplishes connection pooling, nor does it have any dependencies on a particular connection pooling mechanism.
It simplifies the application programming model for the management of connections. An application is not exposed to how the application server and resource adapter use the connection management contract.
It enables the application server to provide different qualities of services related to EIS integration. Examples of services include transaction management, security management, and error logging and tracing support. An application server can also implement different levels of connection pooling using this connection management contract.
It increases the scalability of an application. An application can now support a greater number of concurrent client sessions accessing EISs.