|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
General Java Interfacing Transaction Services
Interfacing Transaction Services
By: Maros Cunderlik
Mar. 1, 1998 12:00 AM
Introduction In this article, we will explore how Java components can access transaction services. We will describe the common framework for transaction processing: Distributed Transaction Processing (DTP) Model. We will also take a closer look at two common applications of DTP-like transaction models. In Part I, we will cover the concepts of the Microsoft Transaction Server (MTS), and OLE Transactions and build a sample MTS-based order validation application in Java. In Part II, we will explore the CORBA Object Transaction Service (OTS) and its commercial implementation. In the end, you will have a good understanding of transaction models, their underlying principles and how Java applications can participate in transaction processing. Before we start, I want to emphasize that the purpose of this article is to focus on understanding transaction processing concepts. We will not attempt to 'rate' various commercial implementations of TP monitors or component standards. You should also have a basic understanding of COM and CORBA.
Distributed Transaction Processing - X/Open DTP Model These four properties are also known as ACID properties and form the foundation of transactional systems. In truth, it is not that difficult to achieve ACID properties in highly integrated systems. However, maintaining ACID properties becomes increasingly complex in systems spanning multiple machines, platforms, databases or database systems. To address transaction processing in the distributed and heterogeneous environment, X/Open group defined the Distributed Transaction Processing (DTP) Model. The basic X/Open DTP model consists of three main entities and two interfaces. Transaction Manager manages the scope (context) of transaction, provides a unique transaction identifier and determines the outcome of transaction. Resource Manager enlists transaction resources in transactions ('ax_reg', 'xa_start'), most importantly databases. Application communicates with Transaction Manager via TX interface. Transaction Manager 'talks' to Resource Manager via XA interface. Figure 1 shows how Application starts transaction ('tx_begin'). Transaction Manager informs Resource Manager about the transaction; Application then makes a series of calls to Resource Manager using the native API. The application signals the end of transaction by calling Transaction Manager ('tx_commit'). At this point, Transaction Manager starts the two-phase commit process using XA interface. In a simplified view of two-phase commit, Transaction Manager instructs all participating Resource Managers to prepare the commit ('xa_prepare'). Resource Managers communicate with their resources to prepare commit and send an acknowledge massage ('commit ready', or 'commit aborted') to the Transaction Manager. The Transaction Manager awaits the responses. If all resource managers responded with 'commit ready', the final commit command ('xa_commit') is issued by the Transaction Manager and all changes are committed. The information about successful commit is communicated back to the client. If one or more resource managers could not prepare to commit, the transaction manager issues the rollback message and all resource managers ensure that the initial state is restored. Finally, the transaction manager informs the client that the changes failed and the initial state was restored.
Microsoft Transaction Server (MTS) Understanding MTS and OLE
Transactions MTS Executive has an 'intimate' knowledge of the application component and interacts with MTS runtime on its behalf. Figure 2 illustrates the core components of MTS runtime that participate in transaction processing. If a component is declared as transactional, MTS runtime contacts Microsoft Distributed Transaction Coordinator (MS DTC) and automatically starts a new transaction, or joins the existing one, when the component is instantiated. As illustrated in Figure 2, MTS Executive requests resources from Dispenser Manager. Dispenser Manager maintains resource pools with the help of Inventory Statistics Manager and Holder. The Holder component lists the resource inventory for each Resource Dispenser. Resource Dispenser has an 'intimate' knowledge of the underlying resource. It knows how to allocate and reclaim the resource. On start-up, Resource Dispenser registers with Dispenser Manager and enlists its resource with Resource Manager and Holder. The dispenser usually provides public API or COM interfaces that are used by client applications to access the resource. Resource Manager is a component that is part of the OLE Transactions model. The resource manager communicates with MS DTC and participates in a two-phase commit process. Dispenser Manager periodically (every 10 seconds in MTS 2.0) interrogates each Holder to allow them to readjust their inventory. Each Holder, in turn, calls Inventory Statistics Manager to suggest the appropriate inventory levels. As a result, Holder instructs Resource Dispenser to either create or destroy some resources. After the resource is allocated, Dispenser Manager asks MTS Executive whether the application component is running within a transaction. If so, Dispenser Manager asks Resource Dispenser to enlist the resource in the transaction. Resource Dispenser, in turn, contacts Resource Manager to enlist the resource with MS DTC.
OLE Transactions
MTS Programming in Java Because MTS is COM-based, the process of building an MTS application is basically the same as building COM components in Java. However, when attempting to create scalable systems we must consider issues such as an objects' state, persistence, granularity, object pooling and resource management. There are key differences between building the scalable applications in MTS and plain COM. For example, resource management and object pooling make acquiring and destroying resources in MTS relatively 'cheap'. Therefore, the traditional model of acquiring resources once and then holding onto them as long as they are needed is no longer valid in MTS. The 'typical' MTS component would create and destroy resources as needed and commit/rollback changes as soon as possible. The component sends commit/rollback messages by calling SetComplete/SetAbort methods on IObjectContext interface. In addition to committing changes, the SetComplete/SetAbort calls cause the object instance to be 'recycled' using the object pool. MTS version 2.0 supports the most basic object pooling - instances are created and destroyed on demand, no object pool is maintained. As a result, clients cannot rely on MTS objects to maintain their state after MTS objects issue SetComplete/SetAbort commands. This behavior constitutes the single most important paradigm change in the COM programming model. MTS also introduces a new security model on top of NT domain security. The centerpiece of MTS security model is the concept of roles. A role usually refers to a group or type of users for a set of components; e.g., Manager, Sales Representative or Customer.
To demonstrate these concepts we will build a sample order validation system. First a little background. Our company - M.C. Manufacturing (MCM) - is adopting a new business model. It allows its customers to order any sample and experimental products. After a few successful sample orders, the customers would presumably place a large order and the product could be eventually added to the standard product line. MCM's IT department must now build an order validation system that could pre-process the large volume of custom-made products. Pre-processing orders will help to minimize the lead times. We will attempt to build the system in the following steps:
Designing conceptual-level interfaces
Designing physical, MTS COM interfaces using COM IDL Traditionally, inside of Order class we would also create an instance of Item and Dispatcher classes and use them when validating and submitting order. These classes would, therefore, remain in memory for the lifetime of order instance. Clearly, this is not the best use of system resources. Consider the following scenario. When entering an order, we create an instance of Order component. When an item is added, we will obtain and keep a reference to it for the lifetime of instance of Order class. We will use an object manager to create an instance of Item class as needed. The object manager will 'know' how to create an instance of a class. It also 'knows' how to restore object's state based on the reference. What we are describing here is a process of adding persistence. COM has a concept of monikers that are used for implementing persistence. However, monikers are not supported in Java and, therefore, we must implement persistence ourselves. Our implementation is simple. Every class will implement an IPersistObject interface that defines how to load state, save state, return a persistent object reference to itself and notify about changes in state. Clients then use a static BindToObject() method of PersistManager class to recreate state of persistent objects. Listing 2 shows the IDL definition of IPersistObject interface. Listing 2 describes the IDL definitions of all interfaces and COM implementation classes. Note that the IDL file contains TRANSACTION REQUIRED and JAVACLASS attributes. First attribute marks the component as transactional and causes MTS to start a new transaction or include it in the existing one. The JAVACLASS attribute provides a class name of concrete Java implementation class. For example, Java MCMValidateImpl.Order class will implement COM class COrder.
Mapping IDL files and creating
implementation classes Implementation of Order and Dispatcher components illustrates the importance of state awareness in MTS. Since we want to keep order's state until it is submitted, AddItem() method does not call SetComplete(). On the other hand, Submit() method uses SetComplete()/SetAbort() to commit changes and to recycle the object instance. Dispatcher component is an example of a so-called 'stateless' component. It does not have any private state, all information is passed in via parameters and each method calls SetComplete()/SetAbort() upon completion. This design pattern minimizes use of system resources and also allows clients to use Dispatcher component without having to restore the component's state between method calls. In implementing large systems, it is clearly critical for clients to fully understand the MTS components' state behavior and use them accordingly.
Creating, and deploying MTS components.
Conclusion Microsoft Transaction Server (MTS) has emerged as one of the most important frameworks for component development. MTS provides COM components with common services such as resource management, object pooling and transactions. MTS components access transaction services by using OLE Transactions technology. MTS runtime participates in OLE Transactions on behalf of MTS components. In addition to transaction processing, MTS introduces the new COM programming model. To build effective MTS components, we must consider additional design issues such as state management, resource management and object pooling. In Part II we will explore the CORBA OTS specification. We will review and explain OTS-defined interfaces, entities and behaviors. We will also examine a commercial implementation of OTS, and demonstrate how Java clients can interact with OTS entities.
References and Resources Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||