use of org.apache.ignite.internal.util.future.GridEmbeddedFuture in project ignite by apache.
the class GridCacheAdapter method commitTxAsync.
/**
* Asynchronously commits transaction after all previous asynchronous operations are completed.
*
* @param tx Transaction to commit.
* @return Transaction commit future.
*/
@SuppressWarnings("unchecked")
IgniteInternalFuture<IgniteInternalTx> commitTxAsync(final GridNearTxLocal tx) {
FutureHolder holder = lastFut.get();
holder.lock();
try {
IgniteInternalFuture fut = holder.future();
if (fut != null && !fut.isDone()) {
IgniteInternalFuture<IgniteInternalTx> f = new GridEmbeddedFuture<>(fut, new C2<Object, Exception, IgniteInternalFuture<IgniteInternalTx>>() {
@Override
public IgniteInternalFuture<IgniteInternalTx> apply(Object o, Exception e) {
return tx.commitNearTxLocalAsync();
}
});
saveFuture(holder, f, /*retry*/
false);
return f;
}
IgniteInternalFuture<IgniteInternalTx> f = tx.commitNearTxLocalAsync();
saveFuture(holder, f, /*retry*/
false);
ctx.tm().resetContext();
return f;
} finally {
holder.unlock();
}
}
use of org.apache.ignite.internal.util.future.GridEmbeddedFuture in project ignite by apache.
the class GridCacheAdapter method asyncOp.
/**
* @param tx Transaction.
* @param op Cache operation.
* @param opCtx Cache operation context.
* @param <T> Return type.
* @return Future.
*/
@SuppressWarnings("unchecked")
protected <T> IgniteInternalFuture<T> asyncOp(GridNearTxLocal tx, final AsyncOp<T> op, final CacheOperationContext opCtx, final boolean retry) {
IgniteInternalFuture<T> fail = asyncOpAcquire(retry);
if (fail != null)
return fail;
FutureHolder holder = lastFut.get();
holder.lock();
try {
IgniteInternalFuture fut = holder.future();
final GridNearTxLocal tx0 = tx;
if (fut != null && !fut.isDone()) {
IgniteInternalFuture<T> f = new GridEmbeddedFuture(fut, new IgniteOutClosure<IgniteInternalFuture>() {
@Override
public IgniteInternalFuture<T> apply() {
if (ctx.kernalContext().isStopping())
return new GridFinishedFuture<>(new IgniteCheckedException("Operation has been cancelled (node is stopping)."));
return op.op(tx0, opCtx).chain(new CX1<IgniteInternalFuture<T>, T>() {
@Override
public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
try {
return tFut.get();
} catch (IgniteTxRollbackCheckedException e) {
throw e;
} catch (IgniteCheckedException e1) {
tx0.rollbackNearTxLocalAsync();
throw e1;
} finally {
ctx.shared().txContextReset();
}
}
});
}
});
saveFuture(holder, f, retry);
return f;
}
final IgniteInternalFuture<T> f = op.op(tx, opCtx).chain(new CX1<IgniteInternalFuture<T>, T>() {
@Override
public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
try {
return tFut.get();
} catch (IgniteTxRollbackCheckedException e) {
throw e;
} catch (IgniteCheckedException e1) {
tx0.rollbackNearTxLocalAsync();
throw e1;
} finally {
ctx.shared().txContextReset();
}
}
});
saveFuture(holder, f, retry);
if (tx.implicit())
ctx.tm().resetContext();
return f;
} finally {
holder.unlock();
}
}
use of org.apache.ignite.internal.util.future.GridEmbeddedFuture in project ignite by apache.
the class GridNearTxLocal method lockAllAsync.
/**
* @param cacheCtx Cache context.
* @param keys Keys.
* @param retval Return value flag.
* @param read Read flag.
* @param createTtl Create ttl.
* @param accessTtl Access ttl.
* @param <K> Key type.
* @param skipStore Skip store flag.
* @param keepBinary Keep binary flag.
* @return Future with respond.
*/
public <K> IgniteInternalFuture<GridCacheReturn> lockAllAsync(GridCacheContext cacheCtx, final Collection<? extends K> keys, boolean retval, boolean read, long createTtl, long accessTtl, boolean skipStore, boolean keepBinary) {
assert pessimistic();
try {
checkValid();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
if (F.isEmpty(keys))
return new GridFinishedFuture<>(ret);
init();
if (log.isDebugEnabled())
log.debug("Before acquiring transaction lock on keys: " + keys);
long timeout = remainingTime();
if (timeout == -1)
return new GridFinishedFuture<>(timeoutException());
IgniteInternalFuture<Boolean> fut = cacheCtx.colocated().lockAllAsyncInternal(keys, timeout, this, isInvalidate(), read, retval, isolation, createTtl, accessTtl, CU.empty0(), skipStore, keepBinary);
return new GridEmbeddedFuture<>(fut, new PLC1<GridCacheReturn>(ret, false) {
@Override
protected GridCacheReturn postLock(GridCacheReturn ret) {
if (log.isDebugEnabled())
log.debug("Acquired transaction lock on keys: " + keys);
return ret;
}
});
}
Aggregations