Presentation is loading. Please wait.

Presentation is loading. Please wait.

JTA | Developer Conference 2009 1 JBoss Transactions Ivo Studenský JBoss QA Engineer, Jiří Pechanec JBoss QE Supervisor, Red Hat Sep 10th, 2009.

Similar presentations


Presentation on theme: "JTA | Developer Conference 2009 1 JBoss Transactions Ivo Studenský JBoss QA Engineer, Jiří Pechanec JBoss QE Supervisor, Red Hat Sep 10th, 2009."— Presentation transcript:

1 JTA | Developer Conference 2009 1 JBoss Transactions Ivo Studenský JBoss QA Engineer, Jiří Pechanec JBoss QE Supervisor, Red Hat Sep 10th, 2009

2 JTA | Developer Conference 2009 2 Agenda ● JBoss Transactions Overview ● JTA Overview ● Application Interfaces ● Container Interfaces ● Demonstration ● User Transaction ● Transaction Manager ● Sample Resource Implementation ● Synchronization

3 JTA | Developer Conference 2009 3 JBoss Transactions ● JBoss Transactions is a rebadge of the Arjuna Transaction Service which supports high performance, high reliability transaction processing, compliant with JTA, JTS and Web Services standards. ● http://jboss.org/jbosstm ● Standards compliance ● CORBA Object Transaction Service (OTS) ● Java Enterprise (JEE) transactions ● Java Transaction API (JTA) ● Java Transaction Service (JTS) ● Web services transactions ● Web Services Coordination (WS-Coordination) ● Web Services Atomic Transaction (WS-AtomicTransaction) ● Web Services Business Activity Framework (WS-BusinessActivity)

4 JTA | Developer Conference 2009 4 Java Enterprise transactions ● Java Transaction API (JTA) ● JTA specifies standard Java interfaces between a transaction manager and the parties involved in a distributed transaction system: the resource manager, the application server, and the transactional applications. ● JTA is a specification developed under the Java Community Process as JSR 907. ● Java Transaction Service (JTS) ● JTS specifies the implementation of a transaction manager that supports JTA specification at the high level and implements the Java mapping of the OMG Object Transaction Service (OTS) specification at the low level. JTS uses the standard CORBA ORB/TS interfaces and Internet Inter- ORB Protocol (IIOP) for transaction context propagation between JTS transaction managers.

5 JTA | Developer Conference 2009 5 JTA Composition ● High-level application interface for transaction boundaries demarcation ● High-level transaction manager interface used by container to control transactions ● Java mapping to X/Open XA protocol to participate in transaction controlled by external transaction manager

6 JTA | Developer Conference 2009 6 Transactional services in JEE

7 JTA | Developer Conference 2009 7 Application interface ● Interface javax.transaction.UserTransaction ● Used by JEE applications to programmatically demarcate transactions ● Obtained via JNDI (java:comp/UserTransaction) or using resource annotation ● Transactions are associated with running thread ● Provides basic operations ● begin ● commit ● rollback ● setRollbackOnly ● getStatus ● Application only manages transaction, the resources that participates in transaction are managed by container

8 JTA | Developer Conference 2009 8 UserTransaction – basic operations ● begin() ● create a new transaction and associate it with the current thread ● commit() ● complete the transaction associated with the current thread ● rollback() ● roll back the transaction associated with the current thread ● setRollbackOnly() ● modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction. ● getStatus() ● obtain the status of the transaction associated with the current thread

9 JTA | Developer Conference 2009 9 Container Transaction Management

10 JTA | Developer Conference 2009 10 Transaction Manager ● Interface javax.transaction.TransactionManager ● Used by container ● Can be obtained by application – container specific ● JBoss – via JNDI (java:/TransactionManager) ● Supports not only starting and ending transactions but also suspension – used for session bean transactional attributes ● begin ● commit ● rollback ● setRollbackOnly ● getStatus ● getTransaction ● suspend ● resume

11 JTA | Developer Conference 2009 11 TransactionManager – basic operations ● begin() - creates a new transaction and associate it with the current thread ● commit() - completes the transaction associated with the current thread ● rollback() - rolls back the transaction associated with the current thread ● setRollbackOnly() - modifies the outcome of the transaction to roll back ● int getStatus() - obtains the status of the transaction associated with the current thread ● Transaction getTransaction() - gets the transaction object that represents the transaction context of the calling thread ● Transaction suspend() - suspends the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended ● resume(Transaction t) - resumes the transaction context association of the calling thread with the transaction represented by the supplied Transaction object.

12 JTA | Developer Conference 2009 12 Transaction ● Interface javax.transaction.Transaction ● Represents transaction started by transaction manager ● Controls transaction outcome ● commit ● rollback ● setRollbackOnly ● Enlists/delists resources to transactions ● enlistResource ● delistResource ● Registers synchronizations with transactions ● registerSynchronization

13 JTA | Developer Conference 2009 13 Transaction – basic actions ● commit() ● rollback() ● setRollbackOnly() ● enlistResource(XAResource xaRes) ● enlists the resource specified with the transaction associated with the target Transaction object ● delistResource(XAResource xaRes, int flag) ● disassociates the resource specified from the transaction associated with the target Transaction object ● registerSynchronization(Synchronization sync) ● registers a synchronization object for the transaction currently associated with the target object

14 JTA | Developer Conference 2009 14 Synchronization ● Interface javax.transaction.Synchronization ● Callback interface to inform interested components about transaction completion ● beforeCompletion() - called by the transaction manager prior to the start of the two-phase transaction commit process ● afterCompletion(int status) - called by the transaction manager after the transaction is committed or rolled back ● Typically used by cache to update/invalidate its contents ● Best-effort only, not guaranteed to be called in case of crash

15 JTA | Developer Conference 2009 15 XA Resource ● Interface javax.transaction.xa.XAResource ● Represents any object that supports one or two phase protocol to participate in transaction and can ensure ACID properties ● Database connections ● JMS Connections ● Methods are called exclusively by Transaction Manager ● start ● end ● prepare ● commit ● rollback ● recover ● forget

16 JTA | Developer Conference 2009 16 XAResource – basic actions ● start(Xid xid, int flags) - starts work on behalf of a transaction branch specified in xid ● end(Xid xid, int flags) - ends the work performed on behalf of a transaction branch ● prepare(Xid xid) - asks the resource manager to prepare for a transaction commit of the transaction specified in xid ● commit(Xid xid, boolean onePhase) - commits the global transaction specified by xid ● rollback(Xid xid) - informs the resource manager to roll back work done on behalf of a transaction branch ● Xid[] recover(int flag) - obtains a list of prepared transaction branches from a resource manager ● forget(Xid xid) - tells the resource manager to forget about a heuristically completed transaction branch

17 JTA | Developer Conference 2009 17 XID ● Interface javax.transaction.xa.Xid ● Unique identifier of transaction ● Industry standard ● fully portable across different Transaction Managers, allows creation of delegated transactions in case of hierarchical Transaction Managers ● Consists of three components ● Format identifier – must be unique across the transaction systems ● Global transaction identifier ● Branch qualifier

18 JTA | Developer Conference 2009 18 Logical transaction flow

19 JTA | Developer Conference 2009 19 Example 1 – User Transaction ● Start-up user transaction ● Show how the database is enlisted to transaction behind the scenes ● Show how the database connection is rolled back/committed when JTA transaction is ended

20 JTA | Developer Conference 2009 20 Example 2 – Transaction Manager ● Start-up transaction ● Update database in transaction and suspend it ● Update database in another transaction ● Resume and complete suspended transaction

21 JTA | Developer Conference 2009 21 Example 3 – Sample Resource ● Create XA resource representing File ● Simulate two phase commit ● Prepare phase – temporary file ● Commit phase – move temporary file to final one ● Show recovery after TM crash

22 JTA | Developer Conference 2009 22 Example 4 - Synchronization ● Print the message when Synchronization is called ● Show when the events are fired

23 JTA | Developer Conference 2009 23 Questions ?

24 JTA | Developer Conference 2009 24 Transaction Fundamentals ● ACID ● Atomicity – the transaction completes successfully (commits) or if it fails (aborts) all of its effects are undone (rolled back) ● Consistency – transactions produce consistent results and preserve application-specific invariants, i.e. preserves the internal consistency of the data it acts on ● Isolation – intermediate states produced while a transaction is executing are not visible to others (serializability) ● Durability – the effects of a committed transaction are never lost (except by a catastrophic failure) ● Transaction can be terminated in two ways: committed or aborted (rolled back).


Download ppt "JTA | Developer Conference 2009 1 JBoss Transactions Ivo Studenský JBoss QA Engineer, Jiří Pechanec JBoss QE Supervisor, Red Hat Sep 10th, 2009."

Similar presentations


Ads by Google