/* * (non-Javadoc) * @see javax.transaction.TransactionManager#suspend() */ public Transaction suspend() throws SystemException { if (doTraceLogs) { logger.trace("Suspending tx " + transactionManager.getTransaction()); } final Transaction tx = getAsSleeTransaction(transactionManager.suspend(), false); if (tx != null) { // remove tx context from thread TransactionContextThreadLocal.setTransactionContext(null); return tx; } else { return null; } }
private TransactionContext bindToTransaction(Transaction tx) throws IllegalStateException, SystemException { final TransactionContextImpl txContext = new TransactionContextImpl(); // register for call-backs try { tx.registerSynchronization(new SleeTransactionSynchronization(tx, txContext)); } catch (RollbackException e) { throw new IllegalStateException( "Unable to register listener for created transaction. Error: " + e.getMessage()); } // store tx context in thread TransactionContextThreadLocal.setTransactionContext(txContext); return txContext; }
/* * (non-Javadoc) * @see org.mobicents.slee.runtime.transaction.SleeTransactionManager#getTransactionContext() */ public TransactionContext getTransactionContext() { TransactionContext txContext = TransactionContextThreadLocal.getTransactionContext(); if (txContext == null) { try { final Transaction tx = transactionManager.getTransaction(); if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) { // a tx was started with the real tx manager, lets try to hook the sync handler and a new // tx context txContext = bindToTransaction(tx); } } catch (Throwable e) { throw new SLEEException(e.getMessage(), e); } } return txContext; }
/* * (non-Javadoc) * @see javax.transaction.TransactionManager#resume(javax.transaction.Transaction) */ public void resume(Transaction transaction) throws InvalidTransactionException, IllegalStateException, SystemException { if (transaction.getClass() == SleeTransactionImpl.class) { final SleeTransactionImpl sleeTransactionImpl = (SleeTransactionImpl) transaction; if (doTraceLogs) { logger.trace("Resuming tx " + sleeTransactionImpl.getWrappedTransaction()); } // resume wrapped tx transactionManager.resume(sleeTransactionImpl.getWrappedTransaction()); // store tx context in thread TransactionContextThreadLocal.setTransactionContext( sleeTransactionImpl.getTransactionContext()); } else { throw new InvalidTransactionException(); } }
private SleeTransaction getAsSleeTransaction(Transaction transaction, boolean transactionCreation) throws SystemException { if (transaction != null) { TransactionContext transactionContext = null; if (transactionCreation) { transactionContext = bindToTransaction(transaction); if (logger.isDebugEnabled()) { logger.debug("Started tx " + transaction); } } else { transactionContext = TransactionContextThreadLocal.getTransactionContext(); if (transactionContext == null && transaction.getStatus() == Status.STATUS_ACTIVE) { // we need to bind to tx, this is edge case for a tx that was created directly in the // underlying tx manager transactionContext = bindToTransaction(transaction); } } return new SleeTransactionImpl((Transaction) transaction, transactionContext, this); } else { return null; } }