use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridCommonAbstractTest method doInTransaction.
/**
* @param ignite Ignite instance.
* @param concurrency Transaction concurrency.
* @param isolation Transaction isolation.
* @param clo Closure.
* @return Result of closure execution.
* @throws Exception If failed.
*/
protected static <T> T doInTransaction(Ignite ignite, TransactionConcurrency concurrency, TransactionIsolation isolation, Callable<T> clo) throws Exception {
while (true) {
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
T res = clo.call();
tx.commit();
return res;
} catch (CacheException e) {
if (e.getCause() instanceof ClusterTopologyException) {
ClusterTopologyException topEx = (ClusterTopologyException) e.getCause();
topEx.retryReadyFuture().get();
} else
throw e;
} catch (ClusterTopologyException e) {
IgniteFuture<?> fut = e.retryReadyFuture();
fut.get();
} catch (TransactionRollbackException ignore) {
// Safe to retry right away.
}
}
}
Aggregations