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 GridClusterStateProcessor method sendComputeChangeGlobalState.
/**
* @param activate New cluster state.
* @param resFut State change future.
*/
private void sendComputeChangeGlobalState(boolean activate, BaselineTopology blt, boolean forceBlt, final GridFutureAdapter<Void> resFut) {
AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
if (log.isInfoEnabled()) {
log.info("Sending " + prettyStr(activate) + " request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon=" + ctx.isDaemon() + "]");
}
IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
IgniteFuture<Void> fut = comp.runAsync(new ClientChangeGlobalStateComputeRequest(activate, blt, forceBlt));
fut.listen(new CI1<IgniteFuture>() {
@Override
public void apply(IgniteFuture fut) {
try {
fut.get();
resFut.onDone();
} catch (Exception e) {
resFut.onDone(e);
}
}
});
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class LargeEntryUpdateTest method testEntryUpdate.
/**
* @throws Exception If failed.
*/
@Test
public void testEntryUpdate() throws Exception {
try (Ignite ignite = startGrid()) {
for (int i = 0; i < CACHE_COUNT; ++i) {
IgniteCache<Long, byte[]> cache = ignite.cache(CACHE_PREFIX + i);
cache.put(0L, new byte[PAGE_SIZE * 2]);
}
IgniteCompute compute = ignite.compute().withAsync();
long endTime = System.currentTimeMillis() + WAIT_TIMEOUT;
int iter = 0;
while (System.currentTimeMillis() < endTime) {
log.info("Iteration: " + iter++);
cacheUpdate.set(true);
try {
List<IgniteFuture> futs = new ArrayList<>();
for (int i = 0; i < THREAD_COUNT; ++i) {
compute.run(new CacheUpdater());
futs.add(compute.future());
}
Thread.sleep(30_000);
cacheUpdate.set(false);
for (IgniteFuture fut : futs) fut.get();
} finally {
cacheUpdate.set(false);
}
}
}
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class DistributedComputing method async.
void async(Ignite ignite) {
// tag::async[]
IgniteCompute compute = ignite.compute();
Collection<IgniteCallable<Integer>> calls = new ArrayList<>();
// Iterate through all words in the sentence and create callable jobs.
for (String word : "Count characters using a callable".split(" ")) calls.add(word::length);
IgniteFuture<Collection<Integer>> future = compute.callAsync(calls);
future.listen(fut -> {
// Total number of characters.
int total = fut.get().stream().mapToInt(Integer::intValue).sum();
System.out.println("Total number of characters: " + total);
});
// end::async[]
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class ClusterAPI method remoteNodes.
@Test
void remoteNodes() {
// tag::remote-nodes[]
Ignite ignite = Ignition.ignite();
IgniteCluster cluster = ignite.cluster();
// Get compute instance which will only execute
// over remote nodes, i.e. all the nodes except for this one.
IgniteCompute compute = ignite.compute(cluster.forRemotes());
// Broadcast to all remote nodes and print the ID of the node
// on which this closure is executing.
compute.broadcast(() -> System.out.println("Hello Node: " + ignite.cluster().localNode().id()));
// end::remote-nodes[]
}
Aggregations