use of org.apache.ignite.Ignite in project ignite by apache.
the class CacheAffinityExample 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(">>> Cache affinity example started.");
// Auto-close cache at the end of the example.
try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME)) {
for (int i = 0; i < KEY_CNT; i++) cache.put(i, Integer.toString(i));
// Co-locates jobs with data using IgniteCompute.affinityRun(...) method.
visitUsingAffinityRun();
// Co-locates jobs with data using IgniteCluster.mapKeysToNodes(...) method.
visitUsingMapKeysToNodes();
} finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(CACHE_NAME);
}
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class ComputeFibonacciContinuationExample 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 Fibonacci continuation example started.");
long N = 100;
final UUID exampleNodeId = ignite.cluster().localNode().id();
// Filter to exclude this node from execution.
final IgnitePredicate<ClusterNode> nodeFilter = new IgnitePredicate<ClusterNode>() {
@Override
public boolean apply(ClusterNode n) {
// Give preference to remote nodes.
return ignite.cluster().forRemotes().nodes().isEmpty() || !n.id().equals(exampleNodeId);
}
};
long start = System.currentTimeMillis();
BigInteger fib = ignite.compute(ignite.cluster().forPredicate(nodeFilter)).apply(new ContinuationFibonacciClosure(nodeFilter), N);
long duration = System.currentTimeMillis() - start;
System.out.println();
System.out.println(">>> Finished executing Fibonacci for '" + N + "' in " + duration + " ms.");
System.out.println(">>> Fibonacci sequence for input number '" + N + "' is '" + fib + "'.");
System.out.println(">>> If you re-run this example w/o stopping remote nodes - the performance will");
System.out.println(">>> increase since intermediate results are pre-cache on remote nodes.");
System.out.println(">>> You should see prints out every recursive Fibonacci execution on cluster nodes.");
System.out.println(">>> Check remote nodes for output.");
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class ComputeTaskMapExample 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 task map example started.");
// Execute task on the cluster and wait for its completion.
int cnt = ignite.compute().execute(MapExampleCharacterCountTask.class, "Hello Ignite Enabled World!");
System.out.println();
System.out.println(">>> Total number of characters in the phrase is '" + cnt + "'.");
System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class ComputeTaskSplitExample 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 task split example started.");
// Execute task on the cluster and wait for its completion.
int cnt = ignite.compute().execute(SplitExampleCharacterCountTask.class, "Hello Ignite Enabled World!");
System.out.println();
System.out.println(">>> Total number of characters in the phrase is '" + cnt + "'.");
System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteAtomicReferenceExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws Exception If example execution failed.
*/
public static void main(String[] args) throws Exception {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Atomic reference example started.");
// Make name of atomic reference.
final String refName = UUID.randomUUID().toString();
// Make value of atomic reference.
String val = UUID.randomUUID().toString();
// Initialize atomic reference.
IgniteAtomicReference<String> ref = ignite.atomicReference(refName, val, true);
System.out.println("Atomic reference initial value : " + ref.get() + '.');
// Make closure for checking atomic reference value on cluster.
IgniteRunnable c = new ReferenceClosure(refName);
// Check atomic reference on all cluster nodes.
ignite.compute().run(c);
// Make new value of atomic reference.
String newVal = UUID.randomUUID().toString();
System.out.println("Try to change value of atomic reference with wrong expected value.");
// Won't change.
ref.compareAndSet("WRONG EXPECTED VALUE", newVal);
// Check atomic reference on all cluster nodes.
// Atomic reference value shouldn't be changed.
ignite.compute().run(c);
System.out.println("Try to change value of atomic reference with correct expected value.");
ref.compareAndSet(val, newVal);
// Check atomic reference on all cluster nodes.
// Atomic reference value should be changed.
ignite.compute().run(c);
}
System.out.println();
System.out.println("Finished atomic reference example...");
System.out.println("Check all nodes for output (this node is also part of the cluster).");
}
Aggregations