Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.activemq
Class TransactionContext  view TransactionContext download TransactionContext.java

java.lang.Object
  extended byorg.activemq.TransactionContext
All Implemented Interfaces:
javax.transaction.xa.XAResource

public class TransactionContext
extends java.lang.Object
implements javax.transaction.xa.XAResource

A TransactionContext provides the means to control a JMS transaction. It provides a local transaction interface and also an XAResource interface.

An application server controls the transactional assignment of an XASession by obtaining its XAResource. It uses the XAResource to assign the session to a transaction, prepare and commit work on the transaction, and so on.

An XAResource provides some fairly sophisticated facilities for interleaving work on multiple transactions, recovering a list of transactions in progress, and so on. A JTA aware JMS provider must fully implement this functionality. This could be done by using the services of a database that supports XA, or a JMS provider may choose to implement this functionality from scratch.

Version:
$Revision: 1.1.1.1 $

Field Summary
private  org.activemq.message.ActiveMQXid activeXid
           
private  javax.transaction.xa.Xid associatedXid
           
private  ActiveMQConnection connection
           
private  LocalTransactionEventListener localTransactionEventListener
           
private  java.lang.String localTransactionId
           
private  org.activemq.util.IdGenerator localTransactionIdGenerator
           
private static org.apache.commons.logging.Log log
           
private  java.util.ArrayList sessions
           
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
TransactionContext(ActiveMQConnection connection)
           
 
Method Summary
 void addSession(ActiveMQSession session)
           
 void begin()
          Start a local transaction.
 void commit()
          Commits all messages done in this transaction and releases any locks currently held.
 void commit(javax.transaction.xa.Xid xid, boolean onePhase)
           
 void end(javax.transaction.xa.Xid xid, int flags)
           
 void forget(javax.transaction.xa.Xid xid)
           
 ActiveMQConnection getConnection()
           
 LocalTransactionEventListener getLocalTransactionEventListener()
           
private  java.lang.String getResourceManagerId()
           
 java.lang.Object getTransactionId()
           
 int getTransactionTimeout()
           
 boolean isInLocalTransaction()
           
 boolean isInXATransaction()
           
 boolean isSameRM(javax.transaction.xa.XAResource xaResource)
           
private  void postCommit()
           
private  void postRollback()
           
 int prepare(javax.transaction.xa.Xid xid)
           
 javax.transaction.xa.Xid[] recover(int flag)
           
 void removeSession(ActiveMQSession session)
           
 void rollback()
          Rolls back any messages done in this transaction and releases any locks currently held.
 void rollback(javax.transaction.xa.Xid xid)
           
 void setLocalTransactionEventListener(LocalTransactionEventListener localTransactionEventListener)
          Used by the resource adapter to listen to transaction events.
 boolean setTransactionTimeout(int seconds)
           
private  void setXid(javax.transaction.xa.Xid xid)
           
 void start(javax.transaction.xa.Xid xid, int flags)
          Associates a transaction with the resource.
private  javax.transaction.xa.XAException toXAException(javax.jms.JMSException e)
          Converts a JMSException from the server to an XAException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

connection

private final ActiveMQConnection connection

sessions

private final java.util.ArrayList sessions

localTransactionIdGenerator

private final org.activemq.util.IdGenerator localTransactionIdGenerator

associatedXid

private javax.transaction.xa.Xid associatedXid

activeXid

private org.activemq.message.ActiveMQXid activeXid

localTransactionId

private java.lang.String localTransactionId

localTransactionEventListener

private LocalTransactionEventListener localTransactionEventListener
Constructor Detail

TransactionContext

public TransactionContext(ActiveMQConnection connection)
Method Detail

isInXATransaction

public boolean isInXATransaction()

isInLocalTransaction

public boolean isInLocalTransaction()

getLocalTransactionEventListener

public LocalTransactionEventListener getLocalTransactionEventListener()

setLocalTransactionEventListener

public void setLocalTransactionEventListener(LocalTransactionEventListener localTransactionEventListener)
Used by the resource adapter to listen to transaction events.


addSession

public void addSession(ActiveMQSession session)

removeSession

public void removeSession(ActiveMQSession session)

postRollback

private void postRollback()

postCommit

private void postCommit()

getTransactionId

public java.lang.Object getTransactionId()

begin

public void begin()
           throws javax.jms.JMSException
Start a local transaction.


rollback

public void rollback()
              throws javax.jms.JMSException
Rolls back any messages done in this transaction and releases any locks currently held.


commit

public void commit()
            throws javax.jms.JMSException
Commits all messages done in this transaction and releases any locks currently held.


start

public void start(javax.transaction.xa.Xid xid,
                  int flags)
           throws javax.transaction.xa.XAException
Associates a transaction with the resource.

Specified by:
start in interface javax.transaction.xa.XAResource

end

public void end(javax.transaction.xa.Xid xid,
                int flags)
         throws javax.transaction.xa.XAException
Specified by:
end in interface javax.transaction.xa.XAResource

prepare

public int prepare(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Specified by:
prepare in interface javax.transaction.xa.XAResource

rollback

public void rollback(javax.transaction.xa.Xid xid)
              throws javax.transaction.xa.XAException
Specified by:
rollback in interface javax.transaction.xa.XAResource

commit

public void commit(javax.transaction.xa.Xid xid,
                   boolean onePhase)
            throws javax.transaction.xa.XAException
Specified by:
commit in interface javax.transaction.xa.XAResource

forget

public void forget(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Specified by:
forget in interface javax.transaction.xa.XAResource

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource xaResource)
                 throws javax.transaction.xa.XAException
Specified by:
isSameRM in interface javax.transaction.xa.XAResource

recover

public javax.transaction.xa.Xid[] recover(int flag)
                                   throws javax.transaction.xa.XAException
Specified by:
recover in interface javax.transaction.xa.XAResource

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource

setTransactionTimeout

public boolean setTransactionTimeout(int seconds)
                              throws javax.transaction.xa.XAException
Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource

getResourceManagerId

private java.lang.String getResourceManagerId()
                                       throws javax.jms.JMSException

setXid

private void setXid(javax.transaction.xa.Xid xid)
             throws javax.transaction.xa.XAException

toXAException

private javax.transaction.xa.XAException toXAException(javax.jms.JMSException e)
Converts a JMSException from the server to an XAException. if the JMSException contained a linked XAException that is returned instead.


getConnection

public ActiveMQConnection getConnection()