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);
}
}
}
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;
}
Aggregations