Package org.apache.activemq
Class TransactionContext
java.lang.Object
org.apache.activemq.TransactionContext
- All Implemented Interfaces:
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
begin()
Start a local transaction.void
cleanup()
void
commit()
Commits all work done in this transaction and releases any locks currently held.void
void
void
protected String
int
boolean
boolean
boolean
boolean
boolean
isSameRM
(XAResource xaResource) int
Xid[]
recover
(int flag) void
rollback()
Rolls back any work done in this transaction and releases any locks currently held.void
setConnection
(ActiveMQConnection connection) void
setLocalTransactionEventListener
(LocalTransactionEventListener localTransactionEventListener) Used by the resource adapter to listen to transaction events.void
setRollbackOnly
(boolean val) boolean
setTransactionTimeout
(int seconds) void
Associates a transaction with the resource.toString()
static XAException
toXAException
(jakarta.jms.JMSException e) Converts a JMSException from the server to an XAException. if the JMSException contained a linked XAException that is returned instead.
-
Field Details
-
xaErrorCodeMarker
- See Also:
-
-
Constructor Details
-
TransactionContext
public TransactionContext() -
TransactionContext
-
-
Method Details
-
isInXATransaction
public boolean isInXATransaction() -
setRollbackOnly
public void setRollbackOnly(boolean val) -
isRollbackOnly
public boolean isRollbackOnly() -
isInLocalTransaction
public boolean isInLocalTransaction() -
isInTransaction
public boolean isInTransaction() -
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
-
getTransactionId
-
begin
public void begin() throws jakarta.jms.JMSExceptionStart a local transaction.- Throws:
jakarta.jms.JMSException
- on internal error
-
rollback
public void rollback() throws jakarta.jms.JMSExceptionRolls back any work done in this transaction and releases any locks currently held.- Throws:
jakarta.jms.JMSException
- if the JMS provider fails to roll back the transaction due to some internal error.jakarta.jms.IllegalStateException
- if the method is not called by a transacted session.
-
commit
public void commit() throws jakarta.jms.JMSExceptionCommits all work done in this transaction and releases any locks currently held.- Throws:
jakarta.jms.JMSException
- if the JMS provider fails to commit the transaction due to some internal error.jakarta.jms.IllegalStateException
- if the method is not called by a transacted session.
-
start
Associates a transaction with the resource.- Specified by:
start
in interfaceXAResource
- Throws:
XAException
-
end
- Specified by:
end
in interfaceXAResource
- Throws:
XAException
-
prepare
- Specified by:
prepare
in interfaceXAResource
- Throws:
XAException
-
rollback
- Specified by:
rollback
in interfaceXAResource
- Throws:
XAException
-
commit
- Specified by:
commit
in interfaceXAResource
- Throws:
XAException
-
forget
- Specified by:
forget
in interfaceXAResource
- Throws:
XAException
-
isSameRM
- Specified by:
isSameRM
in interfaceXAResource
- Throws:
XAException
-
recover
- Specified by:
recover
in interfaceXAResource
- Throws:
XAException
-
getTransactionTimeout
- Specified by:
getTransactionTimeout
in interfaceXAResource
- Throws:
XAException
-
setTransactionTimeout
- Specified by:
setTransactionTimeout
in interfaceXAResource
- Throws:
XAException
-
getResourceManagerId
- Throws:
jakarta.jms.JMSException
-
toXAException
Converts a JMSException from the server to an XAException. if the JMSException contained a linked XAException that is returned instead.- Parameters:
e
- JMSException to convert- Returns:
- XAException wrapping original exception or its message
-
getConnection
-
setConnection
-
cleanup
public void cleanup() -
toString
-