Search in sources :

Example 76 with IgniteFuture

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.
        }
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) LT(org.apache.ignite.internal.util.typedef.internal.LT) CacheException(javax.cache.CacheException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException)

Aggregations

IgniteFuture (org.apache.ignite.lang.IgniteFuture)76 Ignite (org.apache.ignite.Ignite)36 ArrayList (java.util.ArrayList)28 IgniteException (org.apache.ignite.IgniteException)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 CountDownLatch (java.util.concurrent.CountDownLatch)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 CacheException (javax.cache.CacheException)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteCompute (org.apache.ignite.IgniteCompute)9 CI1 (org.apache.ignite.internal.util.typedef.CI1)9 List (java.util.List)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 UUID (java.util.UUID)6 Collection (java.util.Collection)5 IgniteInClosure (org.apache.ignite.lang.IgniteInClosure)5 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4