web server - Borland Technical Publications

web server - Borland Technical Publications web server - Borland Technical Publications

techpubs.borland.com
from techpubs.borland.com More from this publisher
12.11.2014 Views

Application development overview The Connectors 1.0 specification defines the CCI for EIS access. The CCI is a standard client API for application components that enables these and EAI frameworks to drive interactions across heterogeneous EISs. The CCI is primarily targeted for Enterprise Application Integration (EAI), third-party enterprise tool vendors, and migration of legacy modules to the J2EE Platform. In the CCI, a connection factory is a public interface that enables connection to an EIS instance. The ConnectionFactory interface is implemented by the Resource Adapter to provide this service. An application looks up a ConnectionFactory instance in the JNDI namespace, and uses it to request to obtain EIS connections. The application then uses the returned Connection interface to access the EIS. To provide a consistent application programming model across both CCI and EIS-specific APIs, the ConnectionFactory and Connection interfaces comply to the Interface Template design pattern. This defines the skeleton of the connection creation and connection closing, deferring the appropriate steps to subclasses. This allows for these interfaces to be easily extended and adapted to redefine certain steps of connection creation and closing without changing these operations' structure. For more information on the application of the Interface Template design pattern to these interfaces, refer to Section 5.5.1 in the Connectors 1.0 specification (http:// java.sun.com/j2ee/connector). Managed application scenario The following steps are performed when a managed application requests to obtain a connection to an EIS instance from a connection factory, as specified in the res-type variable: 1 The application assembler or component provider specifies the connection factory requirements for an application component by using a deployment descriptor: res-ref-name: shme/shmeAdapter res-type:javax.resource.cci.ConnectionFactory res-auth: Application | Container 2 The Resource Adapter deployer sets the configuration information for the Resource Adapter. 3 VisiConnect uses a configured Resource Adapter to create physical connections to the underlying EIS. 4 The application component performs a JNDI lookup of a connection factory instance in the component's environment: // obtain the initial JNDI Naming context javax.naming.Context ctx = new javax.naming.InitialContext(); // perform the JNDI lookup to obtain the connection factory javax.resource.cci.ConnectionFactory cxFactory = (javax.resource.cci.ConnectionFactory)ctx.lookup( "java:comp/env/shme/shmeAdapterConnectionFactory"); 5 The JNDI name passed in the context lookup is that same as that specified in the res-ref-element of the component's deployment descriptor. The JNDI lookup returns a connection factory instance of type java.resource.cci.ConnectionFactory as specified in the res-type element. 6 The application component invokes the getConnection() method on the connection factory to request to obtain an EIS connection. The returned connection instance represents an application level handle to an underlying physical connection. An application component requests multiple connections by invoking the getConnection() method on the connection factory multiple times. javax.resource.cci.Connection cx = cxFactory.getConnection(); 7 The application component uses the returned connection to access the underlying EIS. This is specific to the Resource Adapter. Chapter 27: Using VisiConnect 271

Application development overview 8 After the component finishes with the connection, it closes it using the close() method on the connection interface. cx.close(); 9 If the application component fails to close an allocated connection after its use, that connection is considered an unused connection. Borland Enterprise Server manages to cleanup of unused connections. When the container terminates a component instance, the container cleans up all the connections used by that component instance. Non-managed application scenario In the non-managed application scenario, a similar programming model must be followed in the application component. The non-managed application must lookup a connection factory instance, request to obtain an EIS connection, use the connection for EIS interactions, and close the connection when completed. The following steps are performed when a non-managed application component requests to obtain a connection to an EIS instance from a connection factory: 1 The application component calls the getConnection() method on the javax.resource.cci.ConnectionFactory instance to get a connection to the underlying EIS instance. 2 The connection factory instance delegates the connection request to the default connection manager instance. The Resource Adapter provides the default connection manager implementation. 3 The connection manager instance creates a new physical connection to the underlying EIS instance by calling the ManagedConnectionFactory.createManagedConnection() method. 4 Invoking ManagedConnectionFactory.createManagedConnection() creates a new physical connection to the underlying EIS, represented by the ManagedConnection instance it returns. The ManagedConnectionFactory uses the security information from the JAAS Subject object, and ConnectionRequestInfo, and its configured set of properties (port number, server name, etc.) to create the new ManagedConnection instance. 5 The connection manager instance calls the ManagedConnection.getConnection() method to get an application-level connection handle. This method call does not necessarily create a new physical connection to the EIS instance; it produces a temporary handle that is used by an application to access the underlying physical connection, represented by the ManagedConnection instance. 6 The connection manager instance returns the connection handle to the connection factory instance; the connection factory in turn returns the connection to the requesting application component. Code excerpts - programming to the CCI The following code excerpts illustrate the application programming model based on the CCI requesting to obtain a connection, obtaining the connection factory, creating the interaction and interaction spec, obtaining a record factory and records, executing the interaction with the records, and performing the same using result sets and custom records. // Get a connection to an EIS instance after lookup of a connection factory // instance from the JNDI namespace. In this case, the component allows the // container to manage the EIS sign-on javax.naming.Context ctx = new javax.naming.InitialContext(); javax.resource.cci.ConnectionFactory cxFactory = (javax.resource.cci.ConnectionFactory)ctx.lookup( "java:comp/env/shme/shmeAdapter" ); javax.resource.cci.Connection cx = cxFactory.getConnection(); 272 BES Developer’s Guide

Application development overview<br />

8 After the component finishes with the connection, it closes it using the close()<br />

method on the connection interface.<br />

cx.close();<br />

9 If the application component fails to close an allocated connection after its use, that<br />

connection is considered an unused connection. <strong>Borland</strong> Enterprise Server<br />

manages to cleanup of unused connections. When the container terminates a<br />

component instance, the container cleans up all the connections used by that<br />

component instance.<br />

Non-managed application scenario<br />

In the non-managed application scenario, a similar programming model must be<br />

followed in the application component. The non-managed application must lookup a<br />

connection factory instance, request to obtain an EIS connection, use the connection<br />

for EIS interactions, and close the connection when completed.<br />

The following steps are performed when a non-managed application component<br />

requests to obtain a connection to an EIS instance from a connection factory:<br />

1 The application component calls the getConnection() method on the<br />

javax.resource.cci.ConnectionFactory instance to get a connection to the underlying<br />

EIS instance.<br />

2 The connection factory instance delegates the connection request to the default<br />

connection manager instance. The Resource Adapter provides the default<br />

connection manager implementation.<br />

3 The connection manager instance creates a new physical connection to the<br />

underlying EIS instance by calling the<br />

ManagedConnectionFactory.createManagedConnection() method.<br />

4 Invoking ManagedConnectionFactory.createManagedConnection() creates a new<br />

physical connection to the underlying EIS, represented by the ManagedConnection<br />

instance it returns. The ManagedConnectionFactory uses the security information from<br />

the JAAS Subject object, and ConnectionRequestInfo, and its configured set of<br />

properties (port number, <strong>server</strong> name, etc.) to create the new ManagedConnection<br />

instance.<br />

5 The connection manager instance calls the ManagedConnection.getConnection()<br />

method to get an application-level connection handle. This method call does not<br />

necessarily create a new physical connection to the EIS instance; it produces a<br />

temporary handle that is used by an application to access the underlying physical<br />

connection, represented by the ManagedConnection instance.<br />

6 The connection manager instance returns the connection handle to the connection<br />

factory instance; the connection factory in turn returns the connection to the<br />

requesting application component.<br />

Code excerpts - programming to the CCI<br />

The following code excerpts illustrate the application programming model based on the<br />

CCI requesting to obtain a connection, obtaining the connection factory, creating the<br />

interaction and interaction spec, obtaining a record factory and records, executing the<br />

interaction with the records, and performing the same using result sets and custom<br />

records.<br />

// Get a connection to an EIS instance after lookup of a connection factory<br />

// instance from the JNDI namespace. In this case, the component allows the<br />

// container to manage the EIS sign-on<br />

javax.naming.Context ctx = new javax.naming.InitialContext();<br />

javax.resource.cci.ConnectionFactory cxFactory =<br />

(javax.resource.cci.ConnectionFactory)ctx.lookup(<br />

"java:comp/env/shme/shmeAdapter" );<br />

javax.resource.cci.Connection cx = cxFactory.getConnection();<br />

272 BES Developer’s Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!