TxnManagerTransaction txntr =
(TxnManagerTransaction) txns.get(new Long(id));
if (txntr == null)
throw new UnknownTransactionException("unknown transaction");
/* Expiration checks are only meaningful for active transactions. */
/* NOTE:
* 1) Cancellation sets expiration to 0 without changing state
* from Active right away. Clients are supposed to treat
* UnknownTransactionException just like Aborted, so it's OK to send
* in this case.
* 2) Might be a small window where client is committing the transaction
* close to the expiration time. If the committed transition takes
* place between getState() and ensureCurrent then the client could get
* a false result.
*/
//TODO - need better locking here. getState and expiration need to be checked atomically
int state = txntr.getState();
if (state == ACTIVE && !ensureCurrent(txntr))
throw new UnknownTransactionException("unknown transaction");
if (operationsLogger.isLoggable(Level.FINER)) {
operationsLogger.exiting(
TxnManagerImpl.class.getName(), "getState",
new Integer(state));