Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-45 1496f8081 -> 24c6fed22


IGNITE-45 - Examples


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/fbdfa726
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/fbdfa726
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/fbdfa726

Branch: refs/heads/ignite-45
Commit: fbdfa726e476553cf2aefc59f0060d7375ef2390
Parents: 093a2fc
Author: Valentin Kulichenko <vkuliche...@gridgain.com>
Authored: Sat Mar 21 02:14:39 2015 -0700
Committer: Valentin Kulichenko <vkuliche...@gridgain.com>
Committed: Sat Mar 21 02:14:39 2015 -0700

----------------------------------------------------------------------
 .../computegrid/ComputeCallableExample.java     | 11 ++++++---
 .../ComputeExecutorServiceExample.java          |  7 +++---
 .../computegrid/ComputeRunnableExample.java     | 26 +++++++++++---------
 .../computegrid/ComputeTaskSplitExample.java    | 12 ++++++---
 .../montecarlo/CreditRiskExample.java           | 12 +++------
 5 files changed, 38 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdfa726/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeCallableExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeCallableExample.java
 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeCallableExample.java
index cedab92..c24df5e 100644
--- 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeCallableExample.java
+++ 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeCallableExample.java
@@ -22,7 +22,6 @@ import org.apache.ignite.examples.java7.*;
 import org.apache.ignite.lang.*;
 
 import java.util.*;
-import java.util.stream.*;
 
 /**
  * Demonstrates using of {@link IgniteCallable} job execution on the cluster.
@@ -49,16 +48,20 @@ public class ComputeCallableExample {
             System.out.println();
             System.out.println(">>> Compute callable example started.");
 
-            Stream<IgniteCallable<Integer>> calls = Stream.of("Count 
characters using callable".split(" ")).map(word ->
-                (IgniteCallable<Integer>)() -> {
+            Collection<IgniteCallable<Integer>> calls = new ArrayList<>();
+
+            // Iterate through all words in the sentence and create callable 
jobs.
+            for (String word : "Count characters using callable".split(" ")) {
+                calls.add(() -> {
                     System.out.println();
                     System.out.println(">>> Printing '" + word + "' on this 
node from ignite job.");
 
                     return word.length();
                 });
+            }
 
             // Execute collection of callables on the ignite.
-            Collection<Integer> res = 
ignite.compute().call(calls.collect(Collectors.toList()));
+            Collection<Integer> res = ignite.compute().call(calls);
 
             int sum = res.stream().mapToInt(i -> i).sum();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdfa726/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeExecutorServiceExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeExecutorServiceExample.java
 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeExecutorServiceExample.java
index 1208ce1..91ea66b 100644
--- 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeExecutorServiceExample.java
+++ 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeExecutorServiceExample.java
@@ -21,7 +21,6 @@ import org.apache.ignite.*;
 import org.apache.ignite.examples.java7.*;
 
 import java.util.concurrent.*;
-import java.util.stream.*;
 
 /**
  * Simple example to demonstrate usage of distributed executor service 
provided by Ignite.
@@ -48,12 +47,14 @@ public final class ComputeExecutorServiceExample {
             // Get ignite-enabled executor service.
             ExecutorService exec = ignite.executorService();
 
-            Stream.of("Print words using runnable".split(" ")).forEach(word -> 
{
+            // Iterate through all words in the sentence and create callable 
jobs.
+            for (String word : "Print words using runnable".split(" ")) {
+                // Execute runnable on some node.
                 exec.submit(() -> {
                     System.out.println();
                     System.out.println(">>> Printing '" + word + "' on this 
node from ignite job.");
                 });
-            });
+            }
 
             exec.shutdown();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdfa726/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeRunnableExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeRunnableExample.java
 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeRunnableExample.java
index a78c863..8abbe93 100644
--- 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeRunnableExample.java
+++ 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeRunnableExample.java
@@ -21,7 +21,7 @@ import org.apache.ignite.*;
 import org.apache.ignite.examples.java7.*;
 import org.apache.ignite.lang.*;
 
-import java.util.stream.*;
+import java.util.*;
 
 /**
  * Demonstrates a simple use of {@link IgniteRunnable}.
@@ -44,20 +44,24 @@ public class ComputeRunnableExample {
             System.out.println();
             System.out.println("Compute runnable example started.");
 
+            Collection<IgniteFuture> futs = new ArrayList<>();
+
             // Enable asynchronous mode.
             IgniteCompute compute = ignite.compute().withAsync();
 
-            Stream.of("Print words using runnable".split(" ")).
-                map(word -> {
-                    // Execute runnable on some node.
-                    compute.run(() -> {
-                        System.out.println();
-                        System.out.println(">>> Printing '" + word + "' on 
this node from ignite job.");
-                    });
+            // Iterate through all words in the sentence and create callable 
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());
+            }
 
-                    return compute.future();
-                }).
-                forEach(IgniteFuture::get);
+            // Wait for all futures to complete.
+            futs.forEach(IgniteFuture::get);
 
             System.out.println();
             System.out.println(">>> Finished printing words using runnable 
execution.");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdfa726/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeTaskSplitExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeTaskSplitExample.java
 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeTaskSplitExample.java
index 0b53ab9..7805728 100644
--- 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeTaskSplitExample.java
+++ 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeTaskSplitExample.java
@@ -23,7 +23,6 @@ import org.apache.ignite.examples.java7.*;
 import org.jetbrains.annotations.*;
 
 import java.util.*;
-import java.util.stream.*;
 
 /**
  * Demonstrates a simple use of Ignite with {@link ComputeTaskSplitAdapter}.
@@ -73,8 +72,10 @@ public class ComputeTaskSplitExample {
          * @return The list of child jobs.
          */
         @Override protected Collection<? extends ComputeJob> split(int 
clusterSize, String arg) {
-            return Stream.of(arg.split(" ")).map(word ->
-                new ComputeJobAdapter() {
+            Collection<ComputeJob> jobs = new LinkedList<>();
+
+            for (final String word : arg.split(" ")) {
+                jobs.add(new ComputeJobAdapter() {
                     @Nullable @Override public Object execute() {
                         System.out.println();
                         System.out.println(">>> Printing '" + word + "' on 
this node from ignite job.");
@@ -82,7 +83,10 @@ public class ComputeTaskSplitExample {
                         // Return number of letters in the word.
                         return word.length();
                     }
-            }).collect(Collectors.toList());
+                });
+            }
+
+            return jobs;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdfa726/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskExample.java
 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskExample.java
index beed5a5..058536a 100644
--- 
a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskExample.java
+++ 
b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/montecarlo/CreditRiskExample.java
@@ -78,7 +78,8 @@ public final class CreditRiskExample {
             // Credit risk crdRisk is the minimal amount that creditor has to 
have
             // available to cover possible defaults.
 
-            double crdRisk = 
ignite.compute().call(jobs(ignite.cluster().nodes().size(), portfolio, horizon, 
iter, percentile),
+            double crdRisk = ignite.compute().call(
+                jobs(ignite.cluster().nodes().size(), portfolio, horizon, 
iter, percentile),
                 new IgniteReducer<Double, Double>() {
                     /** Collected values sum. */
                     private double sum;
@@ -139,13 +140,8 @@ public final class CreditRiskExample {
         for (int i = 0; i < clusterSize; i++) {
             final int nodeIter = i == clusterSize - 1 ? lastNodeIter : 
iterPerNode;
 
-            clos.add(new IgniteCallable<Double>() {
-                /** {@inheritDoc} */
-                @Override public Double call() {
-                    return new 
CreditRiskManager().calculateCreditRiskMonteCarlo(
-                        portfolio, horizon, nodeIter, percentile);
-                }
-            });
+            clos.add(() -> new 
CreditRiskManager().calculateCreditRiskMonteCarlo(
+                portfolio, horizon, nodeIter, percentile));
         }
 
         return clos;

Reply via email to