Search in sources :

Example 1 with PartylineException

use of org.commonjava.util.partyline.PartylineException in project partyline by Commonjava.

the class InfinispanJFS method updateBlock.

void updateBlock(final FileBlock block) throws IOException {
    TransactionManager transactionManager = blockCache.getAdvancedCache().getTransactionManager();
    try {
        transactionManager.begin();
        blockCache.put(block.getBlockID(), block);
    } catch (NotSupportedException | SystemException e) {
        try {
            transactionManager.rollback();
            throw new PartylineException("Failed to begin transaction. Rolling back. Block: " + block.getBlockID(), e);
        } catch (SystemException e1) {
            LoggerFactory.getLogger(getClass().getName()).error("System Exception during transaction rollback involving Block: " + block.getBlockID(), e1);
        }
    } finally {
        try {
            transactionManager.commit();
        } catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e) {
            LoggerFactory.getLogger(getClass().getName()).error("Exception during transaction commit involving block: " + block.getBlockID(), e);
        }
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) HeuristicMixedException(javax.transaction.HeuristicMixedException) PartylineException(org.commonjava.util.partyline.PartylineException) NotSupportedException(javax.transaction.NotSupportedException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException)

Example 2 with PartylineException

use of org.commonjava.util.partyline.PartylineException in project partyline by Commonjava.

the class InfinispanTransactionalGLM method executeInTransaction.

/**
 * If transaction not supported, we throw PartylineException to inform the caller to not try again. For other
 * transactional exceptions, we return null to let caller retry later.
 * @param txManager
 * @param operation
 * @param <T>
 * @return
 * @throws PartylineException if transaction not supported
 */
private <T> T executeInTransaction(TransactionManager txManager, TransactionalOperation<T> operation) throws PartylineException {
    try {
        txManager.begin();
    } catch (NotSupportedException e) {
        throw new PartylineException("Transaction not supported", e);
    } catch (SystemException e) {
        logger.error("Failed to begin transaction.", e);
        return null;
    }
    try {
        T ret = operation.execute();
        txManager.commit();
        return ret;
    } catch (SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
        logger.warn("Failed to commit transaction.", e);
        return null;
    } catch (Exception e) {
        try {
            logger.error("Failed to execute. Rolling back.", e);
            txManager.rollback();
        } catch (SystemException e1) {
            logger.error("Exception during rollback", e1);
        }
    }
    return null;
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) PartylineException(org.commonjava.util.partyline.PartylineException) NotSupportedException(javax.transaction.NotSupportedException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) PartylineException(org.commonjava.util.partyline.PartylineException) UnknownHostException(java.net.UnknownHostException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Aggregations

HeuristicMixedException (javax.transaction.HeuristicMixedException)2 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)2 NotSupportedException (javax.transaction.NotSupportedException)2 RollbackException (javax.transaction.RollbackException)2 SystemException (javax.transaction.SystemException)2 PartylineException (org.commonjava.util.partyline.PartylineException)2 UnknownHostException (java.net.UnknownHostException)1 TransactionManager (javax.transaction.TransactionManager)1