use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridCacheReferenceCleanupSelfTest method severalAsyncOpsCallable.
/**
* Crates callable for several async ops test.
*
* @return Callable.
* @throws Exception If failed.
*/
private Callable<Collection<WeakReference<Object>>> severalAsyncOpsCallable() throws Exception {
return new Callable<Collection<WeakReference<Object>>>() {
@Override
public Collection<WeakReference<Object>> call() throws Exception {
Collection<WeakReference<Object>> refs = new ArrayList<>();
Ignite g = startGrid();
try {
IgniteCache<Integer, TestValue> cache = g.cache(DEFAULT_CACHE_NAME);
refs.add(new WeakReference<Object>(cacheContext(cache)));
Collection<IgniteFuture<?>> futs = new ArrayList<>(1000);
for (int i = 0; i < 1000; i++) {
TestValue val = new TestValue(i);
refs.add(new WeakReference<Object>(val));
futs.add(cache.putIfAbsentAsync(0, val));
}
for (IgniteFuture<?> fut : futs) fut.get();
} finally {
G.stop(g.name(), cancel);
}
return refs;
}
};
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class PlatformTransactions method processInStreamOutLong.
/**
* {@inheritDoc}
*/
@Override
public long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
long txId = reader.readLong();
IgniteFuture fut0;
switch(type) {
case OP_COMMIT_ASYNC:
fut0 = tx(txId).commitAsync();
break;
case OP_ROLLBACK_ASYNC:
fut0 = tx(txId).rollbackAsync();
break;
default:
return super.processInStreamOutLong(type, reader);
}
// Future result is the tx itself, we do not want to return it to the platform.
IgniteFuture fut = fut0.chain(new C1<IgniteFuture, Object>() {
private static final long serialVersionUID = 0L;
@Override
public Object apply(IgniteFuture fut) {
return null;
}
});
readAndListenFuture(reader, fut);
return TRUE;
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class PlatformDotNetEntityFrameworkCacheExtension method startBackgroundCleanup.
/**
* Starts the background cleanup of old cache entries.
*
* @param grid Grid.
* @param metaCache Meta cache.
* @param dataCacheName Data cache name.
* @param currentVersions Current versions.
*/
private void startBackgroundCleanup(Ignite grid, final Cache<CleanupNodeId, UUID> metaCache, final String dataCacheName, final Map<String, EntryProcessorResult<Long>> currentVersions) {
if (cleanupFlags.containsKey(dataCacheName))
// Current node already performs cleanup.
return;
if (!trySetGlobalCleanupFlag(grid, metaCache))
return;
cleanupFlags.put(dataCacheName, true);
final ClusterGroup dataNodes = grid.cluster().forDataNodes(dataCacheName);
IgniteFuture f = grid.compute(dataNodes).broadcastAsync(new RemoveOldEntriesRunnable(dataCacheName, currentVersions));
f.listen(new CleanupCompletionListener(metaCache, dataCacheName));
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class PlatformTargetProxyImpl method inStreamOutListenableAsync.
/**
* Performs asyncronous operation.
*
* @param type Type.
* @param memPtr Stream pointer.
* @return Listenable.
* @throws Exception On error.
*/
private PlatformListenable inStreamOutListenableAsync(int type, long memPtr) throws Exception {
try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
BinaryRawReaderEx reader = platformCtx.reader(mem);
long futId = reader.readLong();
int futTyp = reader.readInt();
final PlatformAsyncResult res = target.processInStreamAsync(type, reader);
if (res == null)
throw new IgniteException("PlatformTarget.processInStreamAsync should not return null.");
IgniteFuture fut = res.future();
if (fut == null)
throw new IgniteException("PlatformAsyncResult.future() should not return null.");
return PlatformFutureUtils.listen(platformCtx, fut, futId, futTyp, new PlatformFutureUtils.Writer() {
/**
* {@inheritDoc}
*/
@Override
public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
res.write(writer, obj);
}
/**
* {@inheritDoc}
*/
@Override
public boolean canWrite(Object obj, Throwable err) {
return err == null;
}
}, target);
} catch (Exception e) {
throw target.convertException(e);
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class ComputeAsyncExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println("Compute asynchronous example started.");
// Enable asynchronous mode.
IgniteCompute compute = ignite.compute().withAsync();
Collection<IgniteFuture<?>> futs = new ArrayList<>();
// Iterate through all words in the sentence and create runnable jobs.
for (final String word : "Print words using runnable".split(" ")) {
// Execute runnable on some node.
compute.run(() -> {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");
});
futs.add(compute.future());
}
// Wait for completion of all futures.
futs.forEach(IgniteFuture::get);
System.out.println();
System.out.println(">>> Finished printing words using runnable execution.");
System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
}
}
Aggregations