The following sections describe connection management in WebLogic Server resource adapters. For more information on connection management, see Chapter 6, “Connection Management,” of the.
One of the requirements of theis the connection management contract. The connection management contract between WebLogic Server and a resource adapter:
The resource adapter’s side of the connection management contract is embodied in the resource adapter’s
A J2EE application component uses a public interface called a connection factory to access a connection instance, which the component then uses to connect to the underlying EIS. Examples of connections include database connections and JMS (Java Message Service) connections.
A resource adapter provides connection and connection factory interfaces, acting as a connection factory for EIS connections. For example, thejavax.sql.DataSource and java.sql.Connection interfaces are JDBC-based interfaces for connecting to a relational database.
An application looks up a connection factory instance in the Java Naming and Directory Interface (JNDI) namespace and uses it to obtain EIS connections. See Obtaining the ConnectionFactory (Client-JNDI Interaction).
Version 1.5 resource adapters can be bound in the JNDI tree as independent objects, making them available as system resources in their own right or as message sources for message-driven beans (MDBs). In contrast, version 1.0 resource adapters are identified by their
ConnectionFactory objects bound in the JNDI tree.
In a version 1.5 resource adapter, at deployment time, the
ResourceAdapter Bean (if it exists) is bound into the JNDI tree using the value of the jndi-name element in the
weblogic-ra.xml file. As a result, administrators can view resource adapters as single deployable entities, and they can interact with resource adapter capabilities publicly exposed by the resource adapter provider. For more information, see jndi-name in weblogic-ra.xml Schema.
The application assembler or component provider configures the Connection Factory requirements for an application component in the application’s deployment descriptor. For example:
res-auth: Application or Container
The resource adapter deployer provides the configuration information for the resource adapter.
An application looks up a
ConnectionFactory instance in the Java Naming and Directory Interface (JNDI) namespace and uses it to obtain EIS connections. The following events occur when an application in a managed environment obtains a connection to an EIS instance from a Connection Factory, as specified in the
|Note:||A managed application environment defines an operational environment for a J2EE-based, multi-tier, Web-enabled application that accesses EISes.|
ConnectionFactoryinstance in the component’s environment by using the JNDI interface, as shown in Listing 5-1.
//obtain the initial JNDI Naming context
Context initctx = new InitialContext();
// perform JNDI lookup to obtain the connection factory
javax.resource.cci.ConnectionFactory cxf =
The JNDI name passed in the method
NamingContext.lookup is the same as that specified in the
res-ref-name element of the deployment descriptor. The JNDI lookup results in an instance of type
java.resource.cci.ConnectionFactory as specified in the res-type element.
getConnectionmethod on the
ConnectionFactoryto obtain an EIS connection. The returned connection instance represents an application level handle to an underlying physical connection. An application component obtains multiple connections by calling the method getConnection on the connection factory multiple times.
javax.resource.cci.Connection cx = cxf.getConnection();
Outbound resource adapters based on the
weblogic-ra.xml deployment descriptor files.
You use the
outbound-resource-adapter element and its subelements in the
weblogic-ra.xml deployment descriptor to describe the outbound components of a resource adapter.
You can define outbound connection pools at three levels:
default-connection-propertieselement. See default-connection-properties.
ra.xmldeployment descriptor using the
connection-definition-groupelement. A one-to-one correspondence exists from a connection factory in
ra.xmlto a connection definition group in
weblogic-ra.xml. The properties specified in a group override any parameters specified at the global level. See connection-definition-group.
connection-factory-interface element (a subelement of the
connection-definition-group element) serves as a required unique element (a key) to each
connection-definition-group. There must be a one-to-one relationship between the
connection-definition-interface element in
weblogic-ra.xml and the
connectiondefinition-interface element in
connection-instanceelement of the
weblogic-ra.xmldeployment descriptor. These correspond to the individual connection pools for the resource adapter. You can use the
connection-propertiessubelement to specify properties at the instance level too; properties specified at the instance level override those provided at the group and global levels. See connection-instance.
The following is an example of a
weblogic-ra.xml deployment descriptor that configures multiple outbound connections:
<?xml version="1.0" ?>
Thepermits you to configure a resource adapter to support inbound message connections. The following are the main steps for configuring an inbound connection:
weblogic-ra.xmldeployment descriptor. See jndi-name.
ActivationSpecfor each supported inbound message type in the
ra.xmldeployment descriptor. For information about requirements for an
ActivationSpecclass, see Chapter 12, “Message Inflow” in the .
resource-adapter-jndi-nameelement of the
weblogic-ejb-jar.xmldeployment descriptor, provide the same JNDI name assigned to the resource adapter in the previous step. Setting this value enables the MDB and resource adapter to communicate with each other.
The following example shows how an inbound connection with two message listener/activation specs could be configured in the
ra.xml deployment descriptor:
This section explains how to configure WebLogic Server resource adapter connection pool parameters in the
weblogic-ra.xml deployment descriptor. For more details, see weblogic-ra.xml Schema.
Depending on the complexity of the Enterprise Information System (EIS) that the
ManagedConnection is representing, creating
ManagedConnections can be expensive. You may decide to populate the connection pool with an initial number of
ManagedConnections upon startup of WebLogic Server and therefore avoid creating them at run time. You can configure this setting using the
initial-capacity element in the
weblogic-ra.xml descriptor file. The default value for this element is
Because no initiating security principal or request context information is known at WebLogic Server startup, you create initial connections using a security subject that you specify in the
security element, as described in Configuring Security Identities for Resource Adapters.
ManagedConnections are created, they consume more system resources—such as memory and disk space. Depending on the Enterprise Information System (EIS), this consumption may affect the performance of the overall system. To control the effects of
ManagedConnections on system resources, you can specify a maximum number of allocated
ManagedConnections in the
max-capacity element of the
weblogic-ra.xml descriptor file.
If a new
ManagedConnection (or more than one
ManagedConnection in the case of
capacity-increment being greater than one) needs to be created during a connection request, WebLogic Server ensures that no more than the maximum number of allowed
ManagedConnections are created. Requests for newly allocated
ManagedConnections beyond this limit results in a
ResourceAllocationException being returned to the caller.
In compliance with the
ManagedConnection in the connection pool. However, if a match is not found, a new
ManagedConnection may be created to satisfy the connection request.
capacity-increment element in the
weblogic-ra.xml descriptor file, you can specify a number of additional
ManagedConnections to be created automatically when a match is not found. This feature provides give you the flexibility to control connection pool growth over time and the performance hit on the server each time this growth occurs.
Although setting the maximum number of
ManagedConnections prevents the server from becoming overloaded by more allocated
ManagedConnections than it can handle, it does not control the efficient amount of system resources needed at any given time. WebLogic Server provides a service that monitors the activity of
ManagedConnections in the connection pool of a resource adapter. If the usage decreases and remains at this level over a period of time, the size of the connection pool is reduced to the initial capacity or as close to this as possible to adequately satisfy ongoing connection requests.
This system resource usage service is turned on by default. However, to turn off this service, you can set the
shrinking-enabled element in the
weblogic-ra.xml descriptor file to
shrink-frequency-seconds element in the
weblogic-ra.xml descriptor file to identify the amount of time (in seconds) the Connection Pool Manager will wait between attempts to reclaim unused
ManagedConnections. The default value of this element is
If the maximum number of connections has been reached and there are no available connections, WebLogic Server retries until the call times out. The
highest-num-waiters element controls the number of clients that can be waiting at any given time for a connection.
When a connection is created and fails, the connection is placed on an unavailable list. WebLogic Server attempts to recreate failed connections on the unavailable list. The
highest-num-unavailable element controls the number of unavailable connections that can exist on the unavailable list at one time.
To configure WebLogic Server to attempt to recreate a connection that fails while creating additional
ManagedConnections, enable the
connection-creation-retry-frequency-seconds element. By default, this feature is disabled.
A connection request contains parameter information. By default, the connector container calls the
matchManagedConnections() method on the
ManagedConnectionFactory to match the available connection in the pool to the parameters in the request. The connection that is successfully matched is returned.
It may be that the
ManagedConnectionFactory does not support the call to
matchManagedConnections(). If so, the
matchManagedConnections() method call throws a
javax.resource.NotSupportedException. If the exception is caught, the connector container automatically stops calling the
matchManagedConnections() method on the
You can set the
match-connections-supported element to specify whether the resource adapter supports connection matching. By default, this element is set to true and the
matchManagedConnections() method is called at least once. If it is set to false, the method call is never made.
If connection matching is not supported, a new resource is created and returned if the maximum number of resources has not been reached; otherwise, the oldest unavailable resource is refreshed and returned.
test-frequency-seconds element allows you to specify how frequently (in seconds) connections in the pool are tested for viability.
You can set the
test-connections-on-create element to enable the testing of connections as they are created. The default value is
You can set the
test-connections-on-release element to enable the testing of connections as they are released back into the connection pool. The default value is
You can set the
test-connections-on-reserve element to enable the testing of connections as they are reserved from the connection pool. The default value is
The connection proxy wrapper feature is valid only for resource adapters that are created based on the J2EE 1.0 Connector Architecture. When a connection request is made, WebLogic Server returns to the client (by way of the resource adapter) a proxy object that wraps the connection object. WebLogic Server uses this proxy to provide the following features:
If the connection object returned from a connection request is cast as a
Connection implementation class (rather than an interface implemented by the
Connection class), a
ClassCastException can occur. This exception is caused by one of the following:
An attempt is made by WebLogic Server to detect the
ClassCastException caused by the resource adapter. If the server detects that this cast is failing, it turns off the proxy wrapper feature and proceeds by returning the unwrapped connection object during a connection request. The server logs a warning message to indicate that proxy generation has been turned off. When this occurs, connection leak detection and late XAResource enlistment features are also turned off.
WebLogic Server attempts to detect the
ClassCastException by performing a test at resource adapter deployment time by acting as a client using container-managed security. This requires the resource adapter to be deployed with security credentials defined.
If the client is performing the cast and receiving a
ClassCastException, the client code can be modified, as in the following example.
Assume the client is casting the connection object to
If you know for sure whether or not a connection proxy can be used in the resource adapter, you can avoid a proxy test by explicitly setting the
use-connection-proxies element in the WebLogic Server 8.1 version of
|Note:||WebLogic Server still supports J2CA 1.0 resource adapters. For 1.0 resource adapters, continue to use the WebLogic Server 8.1 deployment descriptors found in
If set to true, the proxy test is not performed and connection properties are generated.
If set to false, the proxy test is not performed and connection proxies are generated.
use-connection-proxies is unspecified, the proxy test is performed and proxies are generated if the test passes. (The test passes if a
ClassCastException is not thrown by the resource adapter).
|Note:||The test cannot detect a
If a resource adapter’s
ManagedConnectionFactory implements the
ValidatingManagedConnectionFactory interface, then the application server can test the validity of existing connections. You can test either a specific outbound connection or the entire pool of outbound connections for a particular
ManagedConnectionFactory. Testing the entire pool results in testing each connection in the pool individually. For more information on this feature, see section 126.96.36.199 “Detecting Invalid Connections” in the .
The following optional elements in the
weblogic-ra.xml deployment descriptor allow you to control the testing of connections in the pool.
test-frequency-seconds—The connector container periodically tests all the free connections in the pool. Use this element to specify the frequency with which the connections are tested. The default is 0, which means the connections will not be tested.
test-connections-on-create—Determines whether the connection should be tested upon its creation. By default it is false.
test-connections-on-release—Determines whether the connection should be tested upon its release. By default it is false.
test-connections-on-reserve—Determines whether the connection should be tested upon its reservation. By default it is false.
To test a resource adapter's connection pools:
Seein the console help.