Package com.swiftmq.swiftlet.xa
Interface XAContext
public interface XAContext
This class acts as a context for an XA transaction. Multiple so-called 'threads of
control' (ToC) can share an XAContext. Before they access it, they have to register itself to
become associated with the XA transaction. Thereafter they do their work and add
QueueTransactions to this context before they unregister. If no more ToCs are registered
with the XAContext, the 2-phase-commit protocol is used to finish the transaction.
- Author:
- IIT GmbH, Bremen/Germany, Copyright (c) 2000-2003, All Rights Reserved
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addTransaction
(int id, String queueName, QueueTransaction transaction) Add a QueueTransaction to the XA transaction.void
close()
Closes this XAContext.long
commit
(boolean onePhase) Performs a commit operation on all registered QueueTransactions.getXid()
Returns the Xid.boolean
Returns whether this transaction is in the 'prepared' state.boolean
Returns whether this transaction was recovered on startup from the prepared logvoid
prepare()
Performs a prepare operation on all registered QueueTransactions.int
Registers a new Thread of Control at this XAContext.void
rollback()
Performs a rollback operation on all registered QueueTransaction.void
setPrepared
(boolean b) Sets this context to the 'prepared' statevoid
unregister
(int id, boolean rollbackOnly) Unregisters a ToC from this XAContext.
-
Method Details
-
getXid
XidImpl getXid()Returns the Xid.- Returns:
- xid.
-
isPrepared
boolean isPrepared()Returns whether this transaction is in the 'prepared' state.- Returns:
- true/false
-
setPrepared
void setPrepared(boolean b) Sets this context to the 'prepared' state- Parameters:
b
- true/false
-
isRecovered
boolean isRecovered()Returns whether this transaction was recovered on startup from the prepared log- Returns:
- true/false
-
register
Registers a new Thread of Control at this XAContext.- Parameters:
description
- A description of the ToC- Returns:
- id ToC id
- Throws:
XAContextException
- on error
-
addTransaction
void addTransaction(int id, String queueName, QueueTransaction transaction) throws XAContextException Add a QueueTransaction to the XA transaction. This has to be done while the ToC is registered.- Parameters:
id
- the ToC idqueueName
- Name of the queuetransaction
- QueueTransaction- Throws:
XAContextException
- on error
-
unregister
Unregisters a ToC from this XAContext.- Parameters:
id
- ToC idrollbackOnly
- marks this transaction as rollback only- Throws:
XAContextException
- on error
-
prepare
Performs a prepare operation on all registered QueueTransactions. All ToCs have to be unregistered to this.- Throws:
XAContextException
- on error
-
commit
Performs a commit operation on all registered QueueTransactions. If 'onePhase' is set to true, a normal commit is performed, otherwise a 2PC commit is performed. All ToCs have to be unregistered to this. For 2PC commit the XAContext has to be in the prepared state (isPrepared() must return true).- Parameters:
onePhase
- perform a 1PC commit.- Returns:
- Flowcontrol delay
- Throws:
XAContextException
- on error.
-
rollback
Performs a rollback operation on all registered QueueTransaction. If the XAContext is in the prepared state (isPrepared() return true), a 2PC rollback is performed, otherwise a 1PC rollback (normal rollback) is performed. All ToCs have to be unregistered to this.- Throws:
XAContextException
-
close
void close()Closes this XAContext. This method is called when the XAResourceManagerSwiftlet shuts down. If the XAContext is not in the prepared state, a normal rollback is performed on all registered QueueTransactions.
-