/** * Synchronously ends transaction after all previous asynchronous operations are completed. * * @param tx Transaction to commit. * @throws GridException If commit failed. */ void endTx(GridCacheTx tx) throws GridException { awaitLastFut(); tx.close(); }
@Override public CountDownLatch call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheCountDownLatchValue val = latchView.get(key); if (val == null) { if (log.isDebugEnabled()) log.debug("Failed to find count down latch with given name: " + name); assert cnt == 0; return new CountDownLatch(cnt); } tx.commit(); return new CountDownLatch(val.get()); } finally { tx.close(); } } },
/** * Set sampling flag. * * @param val Sampling flag state or {@code null} to clear sampling state and mark it as "not set". * @return {@code True} if sampling mode was actually changed by this call. * @throws GridException If failed. */ public boolean sampling(Boolean val) throws GridException { if (busyLock.enterBusy()) { try { validTxState(false); GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ); try { Object prev = val != null ? metaCache.put(sampling, val) : metaCache.remove(sampling); tx.commit(); return !F.eq(prev, val); } finally { tx.close(); } } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to set sampling flag because Grid is stopping."); }
/** * Set sampling flag. * * @param val Sampling flag state or {@code null} to clear sampling state and mark it as "not set". * @return {@code True} if sampling mode was actually changed by this call. * @throws GridException If failed. */ public boolean sampling(Boolean val) throws GridException { if (busyLock.enterBusy()) { try { validTxState(false); GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ); try { Object prev = val != null ? metaCache.put(sampling, val) : metaCache.remove(sampling); tx.commit(); return !F.eq(prev, val); } finally { tx.close(); } } finally { busyLock.leaveBusy(); } } else throw new IllegalStateException("Failed to set sampling flag because Grid is stopping."); }
@Override public Boolean call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicStampedValue<T, S> stmp = atomicView.get(key); if (stmp == null) throw new GridException("Failed to find atomic stamped with given name: " + name); stmp.set(val, stamp); atomicView.put(key, stmp); tx.commit(); return true; } catch (Error | Exception e) { U.error(log, "Failed to set [val=" + val + ", stamp=" + stamp + ", atomicStamped=" + this + ']', e); throw e; } finally { tx.close(); } } };
@Override public Boolean call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicReferenceValue<T> ref = atomicView.get(key); if (ref == null) throw new GridException("Failed to find atomic reference with given name: " + name); ref.set(val); atomicView.put(key, ref); tx.commit(); return true; } catch (Error | Exception e) { U.error(log, "Failed to set value [val=" + val + ", atomicReference=" + this + ']', e); throw e; } finally { tx.close(); } } };
@Override public Long call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); long retVal = val.get(); val.set(retVal - 1); atomicView.put(key, val); tx.commit(); return retVal; } catch (Error | Exception e) { U.error(log, "Failed to get and decrement and get: " + this, e); throw e; } finally { tx.close(); } } };
@Override public Long call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); long retVal = val.get(); val.set(l); atomicView.put(key, val); tx.commit(); return retVal; } catch (Error | Exception e) { U.error(log, "Failed to get and set: " + this, e); throw e; } finally { tx.close(); } } };
@Override public Long call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); long retVal = val.get() + 1; val.set(retVal); atomicView.put(key, val); tx.commit(); return retVal; } catch (Error | Exception e) { U.error(log, "Failed to increment and get: " + this, e); throw e; } finally { tx.close(); } } };
@Override public Long call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); long retVal = val.get() - 1; val.set(retVal); atomicView.put(key, val); tx.commit(); return retVal; } catch (Error | Exception e) { U.error(log, "Failed to decrement and get: " + this, e); throw e; } finally { tx.close(); } } };
@Override public Long call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); long retVal = val.get() + l; val.set(retVal); atomicView.put(key, val); tx.commit(); return retVal; } catch (Error | Exception e) { U.error(log, "Failed to add and get: " + this, e); throw e; } finally { tx.close(); } } };
@Override public Long call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); long retVal = val.get(); val.set(retVal + l); atomicView.put(key, val); tx.commit(); return retVal; } catch (Error | Exception e) { U.error(log, "Failed to get and add: " + this, e); throw e; } finally { tx.close(); } } };
@Override public Boolean call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); boolean retVal = val.get() == expVal; if (retVal) { val.set(newVal); atomicView.put(key, val); tx.commit(); } return retVal; } catch (Error | Exception e) { U.error(log, "Failed to compare and set: " + this, e); throw e; } finally { tx.close(); } } };
@Override public Long call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicLongValue val = atomicView.get(key); if (val == null) throw new GridException("Failed to find atomic long with given name: " + name); long retVal = val.get(); val.set(retVal + 1); atomicView.put(key, val); tx.commit(); return retVal; } catch (Error | Exception e) { U.error(log, "Failed to get and increment: " + this, e); throw e; } finally { tx.close(); } } };
/** {@inheritDoc} */ @Override public Integer call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheCountDownLatchValue latchVal = latchView.get(key); if (latchVal == null) { if (log.isDebugEnabled()) log.debug("Failed to find count down latch with given name: " + name); assert cnt == 0; return cnt; } int retVal; if (val > 0) { retVal = latchVal.get() - val; if (retVal < 0) retVal = 0; } else retVal = 0; latchVal.set(retVal); latchView.put(key, latchVal); tx.commit(); return retVal; } finally { tx.close(); } } }
@Override public Boolean call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicReferenceValue<T> ref = atomicView.get(key); if (ref == null) throw new GridException("Failed to find atomic reference with given name: " + name); if (!expValPred.apply(ref.get())) { tx.setRollbackOnly(); return false; } else { ref.set(newValClos.apply(ref.get())); atomicView.put(key, ref); tx.commit(); return true; } } catch (Error | Exception e) { U.error(log, "Failed to compare and value [expValPred=" + expValPred + ", newValClos" + newValClos + ", atomicReference" + this + ']', e); throw e; } finally { tx.close(); } } };
@Override public Boolean call() throws Exception { GridCacheTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ); try { GridCacheAtomicStampedValue<T, S> stmp = atomicView.get(key); if (stmp == null) throw new GridException("Failed to find atomic stamped with given name: " + name); if (!(expValPred.apply(stmp.value()) && expStampPred.apply(stmp.stamp()))) { tx.setRollbackOnly(); return false; } else { stmp.set(newValClos.apply(stmp.value()), newStampClos.apply(stmp.stamp())); atomicView.put(key, stmp); tx.commit(); return true; } } catch (Error | Exception e) { U.error(log, "Failed to compare and set [expValPred=" + expValPred + ", newValClos=" + newValClos + ", expStampPred=" + expStampPred + ", newStampClos=" + newStampClos + ", atomicStamped=" + this + ']', e); throw e; } finally { tx.close(); } } };