use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class ComputeRunnableExample 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 runnable example started.");
IgniteCompute compute = ignite.compute();
// 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.");
});
}
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).");
}
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class CacheManualRebalancingTest method testRebalance.
/**
* @throws Exception If failed.
*/
public void testRebalance() throws Exception {
// Fill cache with large dataset to make rebalancing slow.
try (IgniteDataStreamer<Object, Object> streamer = grid(0).dataStreamer(MYCACHE)) {
for (int i = 0; i < 100_000; i++) streamer.addData(i, i);
}
// Start new node.
final IgniteEx newNode = startGrid(NODES_CNT);
int newNodeCacheSize;
// Start manual rebalancing.
IgniteCompute compute = newNode.compute().withAsync();
compute.broadcast(new MyCallable());
final ComputeTaskFuture<Object> rebalanceTaskFuture = compute.future();
boolean rebalanceFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return rebalanceTaskFuture.isDone();
}
}, 10_000);
assertTrue(rebalanceFinished);
assertTrue(newNode.context().cache().cache(MYCACHE).context().preloader().rebalanceFuture().isDone());
newNodeCacheSize = newNode.cache(MYCACHE).localSize(CachePeekMode.ALL);
System.out.println("New node cache local size: " + newNodeCacheSize);
assertTrue(newNodeCacheSize > 0);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridClosureProcessorSelfTest method callAsync.
/**
* @param idx Node index.
* @param jobs Callable job.
* @param p Optional node predicate.
* @return Future object.
*/
private IgniteFuture<Collection<Integer>> callAsync(int idx, Collection<ClosureTestCallable> jobs, @Nullable IgnitePredicate<ClusterNode> p) {
assert idx >= 0 && idx < NODES_CNT;
assert !F.isEmpty(jobs);
execCntr.set(0);
IgniteCompute comp = p != null ? compute(grid(idx).cluster().forPredicate(p)) : grid(idx).compute();
return comp.callAsync(jobs);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridClosureProcessorSelfTest method testCallAsyncErrorNoFailover.
/**
* @throws Exception If failed.
*/
public void testCallAsyncErrorNoFailover() throws Exception {
IgniteCompute comp = compute(grid(0).cluster().forPredicate(F.notEqualTo(grid(0).localNode())));
IgniteFuture<Integer> fut = comp.withNoFailover().callAsync(new ClosureTestCallableError());
try {
fut.get();
assert false : "Exception should have been thrown.";
} catch (IgniteException e) {
info("Caught expected exception: " + e);
}
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridClosureProcessorSelfTest method broadcast.
/**
* @param idx Node index.
* @param job Callable job.
* @param p Optional node predicate.
* @return Future object.
*/
private IgniteFuture<Collection<Integer>> broadcast(int idx, IgniteCallable<Integer> job, @Nullable IgnitePredicate<ClusterNode> p) {
assert idx >= 0 && idx < NODES_CNT;
assert job != null;
execCntr.set(0);
IgniteCompute comp = p != null ? compute(grid(idx).cluster().forPredicate(p)) : grid(idx).compute();
return comp.broadcastAsync(job);
}
Aggregations