org.apache.activemq
Class TransactionContext

java.lang.Object
  extended by org.apache.activemq.TransactionContext
All Implemented Interfaces:
XAResource

public class TransactionContext
extends Object
implements 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.

See Also:
Session, QueueSession, TopicSession, XASession

Field Summary
 
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 addSynchronization(Synchronization s)
           
 void begin()
          Start a local transaction.
 void cleanup()
           
 void commit()
          Commits all work done in this transaction and releases any locks currently held.
 void commit(Xid xid, boolean onePhase)
           
 void end(Xid xid, int flags)
           
 void forget(Xid xid)
           
 ActiveMQConnection getConnection()
           
 LocalTransactionEventListener getLocalTransactionEventListener()
           
 TransactionId getTransactionId()
           
 int getTransactionTimeout()
           
 boolean isInLocalTransaction()
           
 boolean isInTransaction()
           
 boolean isInXATransaction()
           
 boolean isSameRM(XAResource xaResource)
           
 int prepare(Xid xid)
           
 Xid[] recover(int flag)
           
 void rollback()
          Rolls back any work done in this transaction and releases any locks currently held.
 void rollback(Xid xid)
           
 void setLocalTransactionEventListener(LocalTransactionEventListener localTransactionEventListener)
          Used by the resource adapter to listen to transaction events.
 boolean setTransactionTimeout(int seconds)
           
 void start(Xid xid, int flags)
          Associates a transaction with the resource.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransactionContext

public TransactionContext(ActiveMQConnection connection)
Method Detail

isInXATransaction

public boolean isInXATransaction()

isInLocalTransaction

public boolean isInLocalTransaction()

isInTransaction

public boolean isInTransaction()

getLocalTransactionEventListener

public LocalTransactionEventListener getLocalTransactionEventListener()
Returns:
Returns the localTransactionEventListener.

setLocalTransactionEventListener

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

Parameters:
localTransactionEventListener - The localTransactionEventListener to set.

addSynchronization

public void addSynchronization(Synchronization s)

getTransactionId

public TransactionId getTransactionId()

begin

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

Throws:
JMSException - on internal error

rollback

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

Throws:
JMSException - if the JMS provider fails to roll back the transaction due to some internal error.
IllegalStateException - if the method is not called by a transacted session.

commit

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

Throws:
JMSException - if the JMS provider fails to commit the transaction due to some internal error.
IllegalStateException - if the method is not called by a transacted session.

start

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

Specified by:
start in interface XAResource
Throws:
XAException

end

public void end(Xid xid,
                int flags)
         throws XAException
Specified by:
end in interface XAResource
Throws:
XAException

prepare

public int prepare(Xid xid)
            throws XAException
Specified by:
prepare in interface XAResource
Throws:
XAException

rollback

public void rollback(Xid xid)
              throws XAException
Specified by:
rollback in interface XAResource
Throws:
XAException

commit

public void commit(Xid xid,
                   boolean onePhase)
            throws XAException
Specified by:
commit in interface XAResource
Throws:
XAException

forget

public void forget(Xid xid)
            throws XAException
Specified by:
forget in interface XAResource
Throws:
XAException

isSameRM

public boolean isSameRM(XAResource xaResource)
                 throws XAException
Specified by:
isSameRM in interface XAResource
Throws:
XAException

recover

public Xid[] recover(int flag)
              throws XAException
Specified by:
recover in interface XAResource
Throws:
XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws XAException
Specified by:
getTransactionTimeout in interface XAResource
Throws:
XAException

setTransactionTimeout

public boolean setTransactionTimeout(int seconds)
                              throws XAException
Specified by:
setTransactionTimeout in interface XAResource
Throws:
XAException

getConnection

public ActiveMQConnection getConnection()

cleanup

public void cleanup()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2005-2012 The Apache Software Foundation. All Rights Reserved.