ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

J2EE Connector Architecture
Pages: 1, 2, 3

3. J2EE Demo Application

Implement a stateless session bean that uses CCI to obtain connections and interact with Tuxedo through the Attunity resource adapter.



See the following code example.

// Do context lookup for Attunity Connection Factory
Context ic = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) 
    ic.lookup("java:comp/env/eis/attunityForTuxedo");

// Get a connection
Connection con = cf.getConnection();

// Create an interaction
Interaction ix = con.createInteraction();

// Add an interaction spec and set it with
// the Tuxedo service name
AttuInteractionSpec iSpec = new AttuInteractionSpec();
iSpec.setFunctionName("STOCKQUOTE");

// Ask Attunity's record factory to create an 
// input record with the proper format
RecordFactory rf = cf.getRecordFactory();
MappedRecord input = 
    rf.createMappedRecord("Record1");

// Add data, which is the stock quote request, 
// to input record
input.put("Record1_data", "<stock_quote><symbol>" 
    + symbol + "</symbol></stock_quote>");

// Execute interaction with input record and spec
MappedRecord output = 
    (MappedRecord) ix.execute(iSpec, input);

// Return output for further processing.
return output;

The connection factory, record factory, connection, and interaction classes used by the session bean come from the Attunity resource adapter and implement interfaces / APIs defined in CCI. The session bean interacts with the resource adapter by calling the methods of these classes.

When the session bean invokes the interaction, the Attunity resource adapter gathers the function name, STOCKQUOTE, from the interaction specification, and the argument, which is the stock quote request containing the stock symbol, from the input record. It then invokes the STOCKQUOTE service on the Tuxedo server with the request. Some resource adapters may invoke the Tuxedo service directly. In the case of the Attunity adapter, this call is performed through the Attunity Connect Engine. The Attunity resource adapter first sends the interaction call to the Attunity Connect Engine, which repackages the data into the appropriate Tuxedo format and then invokes the Tuxedo service, using Tuxedo's proprietary API.

Once the Attunity Connect Engine receives a response from Tuxedo, it reformats it into the return data structure type defined in Attunity Connect Studio. It then sends the response back to the EJB through the Attunity resource adapter.

J2EE 1.4 and J2EE CA Version 1.5

Now that we've introduced you to J2EE CA 1.0, let's discuss J2EE CA 1.5 (see JSR-112), which will be part of J2EE 1.4.

While J2EE CA 1.0 represents a major step forward for legacy system integration for Java and J2EE applications, certain aspects were not addressed in this release. Version 1.0 still treats the EIS as a data source to be queried, not as an active process that can produce events and initiate calls itself. J2EE CA 1.5 extends the capabilities of J2EE CA 1.0 by adding:

Related Reading

J2EE Design Patterns
By William Crawford, Jonathan Kaplan

  • Lifecycle management: A new contract between an application server and a resource adapter lets the application server manage the resource adapter lifecycle (deployment/undeployment, adapter startup/shutdown).

  • Work management: A new contract between an application server and a resource adapter standardizes the management of work between both parties by letting the resource adapter submit work requests to the application server. It also lets the application server control thread management and pooling associated with work requests submitted by the resource adapter. In addition, the new contract lets the adapter create and schedule tasks to be executed within specific transaction contexts. Task scheduling is extremely flexible, allowing for blocking calls as well as asynchronous calls.

  • Transaction inflow: A new contract between an application server and a resource adapter lets the resource adapter propagate transactions initiated by the EIS to the application server. It also allows for Quality of Service, such as crash recovery.

  • Message inflow: A new contract between an application server and a resource adapter supports generic asynchronous message delivery from the EIS to different message endpoints located in the applications server through the resource adapter. In this way, different message providers, such as the Java Message Service (JMS) and Java API for XML Messaging (JAXM), can be plugged into J2EE application servers. This contract allows the EIS to be an active process, generating its own events and messages rather than a passive data source. Resource adapters will be able to leverage this to eliminate mid-tier polling, a traditional but poor use of mid-tier resources.

So, how would our example above benefit from J2EE CA 1.5? Using J2EE CA 1.5 would strengthen the integration between the J2EE platform and the Attunity Tuxedo adapter in the following key areas:

  • Improved resource usage and quality of service. This is a result of the addition of well-defined lifecycle management and work management contracts.

  • Bi-directional integration with legacy systems based on inbound message and transaction inflow capabilities. This lets systems such as Tuxedo send XML messages into the J2EE platform and initiate transactions that will be propagated to the J2EE application server.

  • Enhanced performance, failure resilience, and scalability, by introducing asynchronous integration.

After learning about all the new and exciting features provided with J2EE CA 1.5, you probably can't wait to start experiencing it first hand.

Fortunately, Oracle provides the OC4J 10g (10.0.3) Developer Preview 2 that has passed the J2EE 1.4 compatibility test suite and is officially J2EE 1.4 compatible.

Conclusions

This article discussed the challenges historically associated with legacy system integration and introduced the J2EE Connector Architecture as a standard way of solving these problems. J2EE CA can significantly help you with any legacy system integration. It's available today and will become even more powerful in the future through new releases. Start using it today.

Anthony Lai is a principal member of the Oracle technical staff and a developer in the J2EE Connector Architecture area of Oracle Application Server Containers of J2EE.

Jyotsna Laxminarayanan is a principal member of the Oracle technical staff and contributes to the J2EE Connector Architecture implementation, which is part of Oracle Application Server.

Lars Ewe is a senior principal product manager for Oracle System Management Products.


Return to ONJava.com.