You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2018/01/17 12:23:17 UTC
[19/43] ignite git commit: IGNITE-7203 Java 8 by default
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/DistributedLinearRegressionExampleWithSGDTrainer.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/DistributedLinearRegressionExampleWithSGDTrainer.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/DistributedLinearRegressionExampleWithSGDTrainer.java
new file mode 100644
index 0000000..3f61762
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/DistributedLinearRegressionExampleWithSGDTrainer.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.regression.linear;
+
+import java.util.Arrays;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.examples.ml.math.matrix.SparseDistributedMatrixExample;
+import org.apache.ignite.ml.Trainer;
+import org.apache.ignite.ml.math.Matrix;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
+import org.apache.ignite.ml.math.impls.vector.SparseDistributedVector;
+import org.apache.ignite.ml.regressions.linear.LinearRegressionModel;
+import org.apache.ignite.ml.regressions.linear.LinearRegressionQRTrainer;
+import org.apache.ignite.ml.regressions.linear.LinearRegressionSGDTrainer;
+import org.apache.ignite.thread.IgniteThread;
+
+/**
+ * Run linear regression model over distributed matrix.
+ *
+ * @see LinearRegressionQRTrainer
+ */
+public class DistributedLinearRegressionExampleWithSGDTrainer {
+ /** */
+ private static final double[][] data = {
+ {8, 78, 284, 9.100000381, 109},
+ {9.300000191, 68, 433, 8.699999809, 144},
+ {7.5, 70, 739, 7.199999809, 113},
+ {8.899999619, 96, 1792, 8.899999619, 97},
+ {10.19999981, 74, 477, 8.300000191, 206},
+ {8.300000191, 111, 362, 10.89999962, 124},
+ {8.800000191, 77, 671, 10, 152},
+ {8.800000191, 168, 636, 9.100000381, 162},
+ {10.69999981, 82, 329, 8.699999809, 150},
+ {11.69999981, 89, 634, 7.599999905, 134},
+ {8.5, 149, 631, 10.80000019, 292},
+ {8.300000191, 60, 257, 9.5, 108},
+ {8.199999809, 96, 284, 8.800000191, 111},
+ {7.900000095, 83, 603, 9.5, 182},
+ {10.30000019, 130, 686, 8.699999809, 129},
+ {7.400000095, 145, 345, 11.19999981, 158},
+ {9.600000381, 112, 1357, 9.699999809, 186},
+ {9.300000191, 131, 544, 9.600000381, 177},
+ {10.60000038, 80, 205, 9.100000381, 127},
+ {9.699999809, 130, 1264, 9.199999809, 179},
+ {11.60000038, 140, 688, 8.300000191, 80},
+ {8.100000381, 154, 354, 8.399999619, 103},
+ {9.800000191, 118, 1632, 9.399999619, 101},
+ {7.400000095, 94, 348, 9.800000191, 117},
+ {9.399999619, 119, 370, 10.39999962, 88},
+ {11.19999981, 153, 648, 9.899999619, 78},
+ {9.100000381, 116, 366, 9.199999809, 102},
+ {10.5, 97, 540, 10.30000019, 95},
+ {11.89999962, 176, 680, 8.899999619, 80},
+ {8.399999619, 75, 345, 9.600000381, 92},
+ {5, 134, 525, 10.30000019, 126},
+ {9.800000191, 161, 870, 10.39999962, 108},
+ {9.800000191, 111, 669, 9.699999809, 77},
+ {10.80000019, 114, 452, 9.600000381, 60},
+ {10.10000038, 142, 430, 10.69999981, 71},
+ {10.89999962, 238, 822, 10.30000019, 86},
+ {9.199999809, 78, 190, 10.69999981, 93},
+ {8.300000191, 196, 867, 9.600000381, 106},
+ {7.300000191, 125, 969, 10.5, 162},
+ {9.399999619, 82, 499, 7.699999809, 95},
+ {9.399999619, 125, 925, 10.19999981, 91},
+ {9.800000191, 129, 353, 9.899999619, 52},
+ {3.599999905, 84, 288, 8.399999619, 110},
+ {8.399999619, 183, 718, 10.39999962, 69},
+ {10.80000019, 119, 540, 9.199999809, 57},
+ {10.10000038, 180, 668, 13, 106},
+ {9, 82, 347, 8.800000191, 40},
+ {10, 71, 345, 9.199999809, 50},
+ {11.30000019, 118, 463, 7.800000191, 35},
+ {11.30000019, 121, 728, 8.199999809, 86},
+ {12.80000019, 68, 383, 7.400000095, 57},
+ {10, 112, 316, 10.39999962, 57},
+ {6.699999809, 109, 388, 8.899999619, 94}
+ };
+
+ /** Run example. */
+ public static void main(String[] args) throws InterruptedException {
+ System.out.println();
+ System.out.println(">>> Linear regression model over sparse distributed matrix API usage example started.");
+ // Start ignite grid.
+ try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+ System.out.println(">>> Ignite grid started.");
+ // Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread
+ // because we create ignite cache internally.
+ IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(),
+ SparseDistributedMatrixExample.class.getSimpleName(), () -> {
+
+ // Create SparseDistributedMatrix, new cache will be created automagically.
+ System.out.println(">>> Create new SparseDistributedMatrix inside IgniteThread.");
+ SparseDistributedMatrix distributedMatrix = new SparseDistributedMatrix(data);
+
+ System.out.println(">>> Create new linear regression trainer object.");
+ Trainer<LinearRegressionModel, Matrix> trainer = new LinearRegressionSGDTrainer(100_000, 1e-12);
+
+ System.out.println(">>> Perform the training to get the model.");
+ LinearRegressionModel model = trainer.train(distributedMatrix);
+ System.out.println(">>> Linear regression model: " + model);
+
+ System.out.println(">>> ---------------------------------");
+ System.out.println(">>> | Prediction\t| Ground Truth\t|");
+ System.out.println(">>> ---------------------------------");
+ for (double[] observation : data) {
+ Vector inputs = new SparseDistributedVector(Arrays.copyOfRange(observation, 1, observation.length));
+ double prediction = model.apply(inputs);
+ double groundTruth = observation[0];
+ System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", prediction, groundTruth);
+ }
+ System.out.println(">>> ---------------------------------");
+ });
+
+ igniteThread.start();
+
+ igniteThread.join();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java
new file mode 100644
index 0000000..d0441a4
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * ML linear regression examples.
+ */
+package org.apache.ignite.examples.ml.regression.linear;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java
new file mode 100644
index 0000000..c89c80c
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/regression/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * ML regression examples.
+ */
+package org.apache.ignite.examples.ml.regression;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/ml/trees/MNISTExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/trees/MNISTExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/trees/MNISTExample.java
new file mode 100644
index 0000000..6ff121e
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/trees/MNISTExample.java
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.trees;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Random;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.examples.ExampleNodeStartup;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.ml.Model;
+import org.apache.ignite.ml.estimators.Estimators;
+import org.apache.ignite.ml.math.Vector;
+import org.apache.ignite.ml.math.functions.IgniteTriFunction;
+import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
+import org.apache.ignite.ml.trees.models.DecisionTreeModel;
+import org.apache.ignite.ml.trees.trainers.columnbased.BiIndex;
+import org.apache.ignite.ml.trees.trainers.columnbased.BiIndexedCacheColumnDecisionTreeTrainerInput;
+import org.apache.ignite.ml.trees.trainers.columnbased.ColumnDecisionTreeTrainer;
+import org.apache.ignite.ml.trees.trainers.columnbased.contsplitcalcs.ContinuousSplitCalculators;
+import org.apache.ignite.ml.trees.trainers.columnbased.contsplitcalcs.GiniSplitCalculator;
+import org.apache.ignite.ml.trees.trainers.columnbased.regcalcs.RegionCalculators;
+import org.apache.ignite.ml.util.MnistUtils;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * <p>
+ * Example of usage of decision trees algorithm for MNIST dataset
+ * (it can be found here: http://yann.lecun.com/exdb/mnist/). </p>
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p>
+ * <p>
+ * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
+ * with {@code examples/config/example-ignite.xml} configuration.</p>
+ * <p>
+ * It is recommended to start at least one node prior to launching this example if you intend
+ * to run it with default memory settings.</p>
+ * <p>
+ * This example should with program arguments, for example
+ * -ts_i /path/to/train-images-idx3-ubyte
+ * -ts_l /path/to/train-labels-idx1-ubyte
+ * -tss_i /path/to/t10k-images-idx3-ubyte
+ * -tss_l /path/to/t10k-labels-idx1-ubyte
+ * -cfg examples/config/example-ignite.xml.</p>
+ * <p>
+ * -ts_i specifies path to training set images of MNIST;
+ * -ts_l specifies path to training set labels of MNIST;
+ * -tss_i specifies path to test set images of MNIST;
+ * -tss_l specifies path to test set labels of MNIST;
+ * -cfg specifies path to a config path.</p>
+ */
+public class MNISTExample {
+ /** Name of parameter specifying path to training set images. */
+ private static final String MNIST_TRAINING_IMAGES_PATH = "ts_i";
+
+ /** Name of parameter specifying path to training set labels. */
+ private static final String MNIST_TRAINING_LABELS_PATH = "ts_l";
+
+ /** Name of parameter specifying path to test set images. */
+ private static final String MNIST_TEST_IMAGES_PATH = "tss_i";
+
+ /** Name of parameter specifying path to test set labels. */
+ private static final String MNIST_TEST_LABELS_PATH = "tss_l";
+
+ /** Name of parameter specifying path of Ignite config. */
+ private static final String CONFIG = "cfg";
+
+ /** Default config path. */
+ private static final String DEFAULT_CONFIG = "examples/config/example-ignite.xml";
+
+ /**
+ * Launches example.
+ *
+ * @param args Program arguments.
+ */
+ public static void main(String[] args) {
+ String igniteCfgPath;
+
+ CommandLineParser parser = new BasicParser();
+
+ String trainingImagesPath;
+ String trainingLabelsPath;
+
+ String testImagesPath;
+ String testLabelsPath;
+
+ try {
+ // Parse the command line arguments.
+ CommandLine line = parser.parse(buildOptions(), args);
+
+ trainingImagesPath = line.getOptionValue(MNIST_TRAINING_IMAGES_PATH);
+ trainingLabelsPath = line.getOptionValue(MNIST_TRAINING_LABELS_PATH);
+ testImagesPath = line.getOptionValue(MNIST_TEST_IMAGES_PATH);
+ testLabelsPath = line.getOptionValue(MNIST_TEST_LABELS_PATH);
+ igniteCfgPath = line.getOptionValue(CONFIG, DEFAULT_CONFIG);
+ }
+ catch (ParseException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ try (Ignite ignite = Ignition.start(igniteCfgPath)) {
+ IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
+
+ int ptsCnt = 60000;
+ int featCnt = 28 * 28;
+
+ Stream<DenseLocalOnHeapVector> trainingMnistStream = MnistUtils.mnist(trainingImagesPath, trainingLabelsPath, new Random(123L), ptsCnt);
+ Stream<DenseLocalOnHeapVector> testMnistStream = MnistUtils.mnist(testImagesPath, testLabelsPath, new Random(123L), 10_000);
+
+ IgniteCache<BiIndex, Double> cache = createBiIndexedCache(ignite);
+
+ loadVectorsIntoBiIndexedCache(cache.getName(), trainingMnistStream.iterator(), featCnt + 1, ignite);
+
+ ColumnDecisionTreeTrainer<GiniSplitCalculator.GiniData> trainer =
+ new ColumnDecisionTreeTrainer<>(10, ContinuousSplitCalculators.GINI.apply(ignite), RegionCalculators.GINI, RegionCalculators.MOST_COMMON, ignite);
+
+ System.out.println(">>> Training started");
+ long before = System.currentTimeMillis();
+ DecisionTreeModel mdl = trainer.train(new BiIndexedCacheColumnDecisionTreeTrainerInput(cache, new HashMap<>(), ptsCnt, featCnt));
+ System.out.println(">>> Training finished in " + (System.currentTimeMillis() - before));
+
+ IgniteTriFunction<Model<Vector, Double>, Stream<IgniteBiTuple<Vector, Double>>, Function<Double, Double>, Double> mse = Estimators.errorsPercentage();
+ Double accuracy = mse.apply(mdl, testMnistStream.map(v -> new IgniteBiTuple<>(v.viewPart(0, featCnt), v.getX(featCnt))), Function.identity());
+ System.out.println(">>> Errs percentage: " + accuracy);
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Build cli options.
+ */
+ @NotNull private static Options buildOptions() {
+ Options options = new Options();
+
+ Option trsImagesPathOpt = OptionBuilder.withArgName(MNIST_TRAINING_IMAGES_PATH).withLongOpt(MNIST_TRAINING_IMAGES_PATH).hasArg()
+ .withDescription("Path to the MNIST training set.")
+ .isRequired(true).create();
+
+ Option trsLabelsPathOpt = OptionBuilder.withArgName(MNIST_TRAINING_LABELS_PATH).withLongOpt(MNIST_TRAINING_LABELS_PATH).hasArg()
+ .withDescription("Path to the MNIST training set.")
+ .isRequired(true).create();
+
+ Option tssImagesPathOpt = OptionBuilder.withArgName(MNIST_TEST_IMAGES_PATH).withLongOpt(MNIST_TEST_IMAGES_PATH).hasArg()
+ .withDescription("Path to the MNIST test set.")
+ .isRequired(true).create();
+
+ Option tssLabelsPathOpt = OptionBuilder.withArgName(MNIST_TEST_LABELS_PATH).withLongOpt(MNIST_TEST_LABELS_PATH).hasArg()
+ .withDescription("Path to the MNIST test set.")
+ .isRequired(true).create();
+
+ Option configOpt = OptionBuilder.withArgName(CONFIG).withLongOpt(CONFIG).hasArg()
+ .withDescription("Path to the config.")
+ .isRequired(false).create();
+
+ options.addOption(trsImagesPathOpt);
+ options.addOption(trsLabelsPathOpt);
+ options.addOption(tssImagesPathOpt);
+ options.addOption(tssLabelsPathOpt);
+ options.addOption(configOpt);
+
+ return options;
+ }
+
+ /**
+ * Creates cache where data for training is stored.
+ *
+ * @param ignite Ignite instance.
+ * @return cache where data for training is stored.
+ */
+ private static IgniteCache<BiIndex, Double> createBiIndexedCache(Ignite ignite) {
+ CacheConfiguration<BiIndex, Double> cfg = new CacheConfiguration<>();
+
+ // Write to primary.
+ cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC);
+
+ // Atomic transactions only.
+ cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+ // No eviction.
+ cfg.setEvictionPolicy(null);
+
+ // No copying of values.
+ cfg.setCopyOnRead(false);
+
+ // Cache is partitioned.
+ cfg.setCacheMode(CacheMode.PARTITIONED);
+
+ cfg.setBackups(0);
+
+ cfg.setName("TMP_BI_INDEXED_CACHE");
+
+ return ignite.getOrCreateCache(cfg);
+ }
+
+ /**
+ * Loads vectors into cache.
+ *
+ * @param cacheName Name of cache.
+ * @param vectorsIterator Iterator over vectors to load.
+ * @param vectorSize Size of vector.
+ * @param ignite Ignite instance.
+ */
+ private static void loadVectorsIntoBiIndexedCache(String cacheName, Iterator<? extends Vector> vectorsIterator,
+ int vectorSize, Ignite ignite) {
+ try (IgniteDataStreamer<BiIndex, Double> streamer =
+ ignite.dataStreamer(cacheName)) {
+ int sampleIdx = 0;
+
+ streamer.perNodeBufferSize(10000);
+
+ while (vectorsIterator.hasNext()) {
+ org.apache.ignite.ml.math.Vector next = vectorsIterator.next();
+
+ for (int i = 0; i < vectorSize; i++)
+ streamer.addData(new BiIndex(sampleIdx, i), next.getX(i));
+
+ sampleIdx++;
+
+ if (sampleIdx % 1000 == 0)
+ System.out.println("Loaded " + sampleIdx + " vectors.");
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/ml/trees/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/trees/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/trees/package-info.java
new file mode 100644
index 0000000..d944f60
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/trees/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Decision trees examples.
+ */
+package org.apache.ignite.examples.ml.trees;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
index 6934ac3..c89cfbd 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java
@@ -19,7 +19,6 @@ package org.apache.ignite.examples.streaming;
import java.util.List;
import java.util.Random;
-import javax.cache.processor.MutableEntry;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteDataStreamer;
@@ -34,9 +33,11 @@ import org.apache.ignite.stream.StreamTransformer;
* Stream random numbers into the streaming cache.
* To start the example, you should:
* <ul>
- * <li>Start a few nodes using {@link ExampleNodeStartup}.</li>
+ * <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
* <li>Start streaming using {@link StreamTransformerExample}.</li>
* </ul>
+ * <p>
+ * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM.
*/
public class StreamTransformerExample {
/** Random number generator. */
@@ -45,6 +46,9 @@ public class StreamTransformerExample {
/** Range within which to generate numbers. */
private static final int RANGE = 1000;
+ /** Cache name. */
+ private static final String CACHE_NAME = "randomNumbers";
+
public static void main(String[] args) throws Exception {
// Mark this cluster member as client.
Ignition.setClientMode(true);
@@ -53,7 +57,7 @@ public class StreamTransformerExample {
if (!ExamplesUtils.hasServerNodes(ignite))
return;
- CacheConfiguration<Integer, Long> cfg = new CacheConfiguration<>("randomNumbers");
+ CacheConfiguration<Integer, Long> cfg = new CacheConfiguration<>(CACHE_NAME);
// Index key and value.
cfg.setIndexedTypes(Integer.class, Long.class);
@@ -65,17 +69,15 @@ public class StreamTransformerExample {
stmr.allowOverwrite(true);
// Configure data transformation to count random numbers added to the stream.
- stmr.receiver(new StreamTransformer<Integer, Long>() {
- @Override public Object process(MutableEntry<Integer, Long> e, Object... args) {
- // Get current count.
- Long val = e.getValue();
+ stmr.receiver(StreamTransformer.from((e, arg) -> {
+ // Get current count.
+ Long val = e.getValue();
- // Increment count by 1.
- e.setValue(val == null ? 1L : val + 1);
+ // Increment count by 1.
+ e.setValue(val == null ? 1L : val + 1);
- return null;
- }
- });
+ return null;
+ }));
// Stream 10 million of random numbers into the streamer cache.
for (int i = 1; i <= 10_000_000; i++) {
@@ -99,7 +101,7 @@ public class StreamTransformerExample {
}
finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
- ignite.destroyCache(cfg.getName());
+ ignite.destroyCache(CACHE_NAME);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
index c3d8c64..c8438d2 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java
@@ -19,14 +19,11 @@ package org.apache.ignite.examples.streaming;
import java.io.Serializable;
import java.util.List;
-import java.util.Map;
import java.util.Random;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteDataStreamer;
import org.apache.ignite.Ignition;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectBuilder;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -35,16 +32,14 @@ import org.apache.ignite.examples.ExamplesUtils;
import org.apache.ignite.stream.StreamVisitor;
/**
- * This examples demonstrates the stream visitor which allows to customize the processing
- * of the streamed data on the server side. Instead of populating the cache for which the
- * streamer is created, we will calculate aggregated data on the fly and save results in
- * another cache.
+ * Stream random numbers into the streaming cache.
+ * To start the example, you should:
+ * <ul>
+ * <li>Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.</li>
+ * <li>Start streaming using {@link StreamVisitorExample}.</li>
+ * </ul>
* <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-ignite.xml} configuration.
+ * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM.
*/
public class StreamVisitorExample {
/** Random number generator. */
@@ -56,10 +51,6 @@ public class StreamVisitorExample {
/** The list of initial instrument prices. */
private static final double[] INITIAL_PRICES = {194.9, 893.49, 34.21, 23.24, 57.93, 45.03, 44.41, 28.44, 378.49, 69.50};
- /** Caches' names. */
- private static final String INSTRUMENTS_CACHE_NAME = "instCache";
- private static final String MARKET_TICKS_CACHE_NAME = "marketTicks";
-
public static void main(String[] args) throws Exception {
// Mark this cluster member as client.
Ignition.setClientMode(true);
@@ -68,8 +59,11 @@ public class StreamVisitorExample {
if (!ExamplesUtils.hasServerNodes(ignite))
return;
+ // Market data cache with default configuration.
+ CacheConfiguration<String, Double> mktDataCfg = new CacheConfiguration<>("marketTicks");
+
// Financial instrument cache configuration.
- CacheConfiguration<String, Instrument> instCfg = new CacheConfiguration<>(INSTRUMENTS_CACHE_NAME);
+ CacheConfiguration<String, Instrument> instCfg = new CacheConfiguration<>("instCache");
// Index key and value for querying financial instruments.
// Note that Instrument class has @QuerySqlField annotation for secondary field indexing.
@@ -77,54 +71,28 @@ public class StreamVisitorExample {
// Auto-close caches at the end of the example.
try (
- IgniteCache<String, Double> mktCache = ignite.getOrCreateCache(MARKET_TICKS_CACHE_NAME); // Default config.
+ IgniteCache<String, Double> mktCache = ignite.getOrCreateCache(mktDataCfg);
IgniteCache<String, Instrument> instCache = ignite.getOrCreateCache(instCfg)
) {
try (IgniteDataStreamer<String, Double> mktStmr = ignite.dataStreamer(mktCache.getName())) {
- // To achieve proper indexing we should use fully-qualified name
- // of the class as a type name when binary object is created.
- final String instTypeName = Instrument.class.getName();
-
// Note that we receive market data, but do not populate 'mktCache' (it remains empty).
// Instead we update the instruments in the 'instCache'.
// Since both, 'instCache' and 'mktCache' use the same key, updates are collocated.
- mktStmr.receiver(new StreamVisitor<String, Double>() {
- @Override public void apply(IgniteCache<String, Double> cache, Map.Entry<String, Double> e) {
- String symbol = e.getKey();
- Double tick = e.getValue();
-
- IgniteCache<String, BinaryObject> binInstCache =
- ignite.cache(INSTRUMENTS_CACHE_NAME).withKeepBinary();
-
- BinaryObject inst = binInstCache.get(symbol);
-
- BinaryObjectBuilder instBuilder;
-
- if (inst == null) {
- instBuilder = ignite.binary().builder(instTypeName);
-
- // Constructor logic.
- instBuilder.setField(
- "symbol",
- symbol);
- }
- else
- instBuilder = inst.toBuilder();
-
- // Instrument.update() logic.
- Double open = instBuilder.<Double>getField("open");
+ mktStmr.receiver(StreamVisitor.from((cache, e) -> {
+ String symbol = e.getKey();
+ Double tick = e.getValue();
- if (open == null || open == 0)
- instBuilder.setField("open", tick);
+ Instrument inst = instCache.get(symbol);
- instBuilder.setField("latest", tick);
+ if (inst == null)
+ inst = new Instrument(symbol);
- // Build instrument object.
- inst = instBuilder.build();
+ // Don't populate market cache, as we don't use it for querying.
+ // Update cached instrument based on the latest market tick.
+ inst.update(tick);
- binInstCache.put(symbol, inst);
- }
- });
+ instCache.put(symbol, inst);
+ }));
// Stream 10 million market data ticks into the system.
for (int i = 1; i <= 10_000_000; i++) {
@@ -155,8 +123,8 @@ public class StreamVisitorExample {
}
finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
- ignite.destroyCache(INSTRUMENTS_CACHE_NAME);
- ignite.destroyCache(MARKET_TICKS_CACHE_NAME);
+ ignite.destroyCache(mktDataCfg.getName());
+ ignite.destroyCache(instCfg.getName());
}
}
}
@@ -206,4 +174,4 @@ public class StreamVisitorExample {
this.latest = price;
}
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java b/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
index 7cd31d1..f9e84ef 100644
--- a/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
+++ b/examples/src/main/java/org/apache/ignite/examples/streaming/package-info.java
@@ -16,6 +16,7 @@
*/
/**
+ * <!-- Package description. -->
* Demonstrates usage of data streamer.
*/
package org.apache.ignite.examples.streaming;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java
deleted file mode 100644
index 751032b..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.cluster;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCluster;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cluster.ClusterGroup;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ExamplesUtils;
-
-/**
- * Demonstrates new functional APIs.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
- * with {@code examples/config/example-ignite.xml} configuration.
- */
-public class ClusterGroupExample {
- /**
- * 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")) {
- if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
- return;
-
- System.out.println();
- System.out.println("Compute example started.");
-
- IgniteCluster cluster = ignite.cluster();
-
- // Say hello to all nodes in the cluster, including local node.
- sayHello(ignite, cluster);
-
- // Say hello to all remote nodes.
- sayHello(ignite, cluster.forRemotes());
-
- // Pick random node out of remote nodes.
- ClusterGroup randomNode = cluster.forRemotes().forRandom();
-
- // Say hello to a random node.
- sayHello(ignite, randomNode);
-
- // Say hello to all nodes residing on the same host with random node.
- sayHello(ignite, cluster.forHost(randomNode.node()));
-
- // Say hello to all nodes that have current CPU load less than 50%.
- sayHello(ignite, cluster.forPredicate(n -> n.metrics().getCurrentCpuLoad() < 0.5));
- }
- }
-
- /**
- * Print 'Hello' message on remote nodes.
- *
- * @param ignite Ignite.
- * @param grp Cluster group.
- * @throws IgniteException If failed.
- */
- private static void sayHello(Ignite ignite, final ClusterGroup grp) throws IgniteException {
- // Print out hello message on all cluster nodes.
- ignite.compute(grp).broadcast(
- () -> System.out.println(">>> Hello Node: " + grp.ignite().cluster().localNode().id()));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java
deleted file mode 100644
index 618e844..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Cluster group example.
- */
-package org.apache.ignite.examples.java8.cluster;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeAsyncExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeAsyncExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeAsyncExample.java
deleted file mode 100644
index 77d1ac2..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeAsyncExample.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.computegrid;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCompute;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.lang.IgniteFuture;
-import org.apache.ignite.lang.IgniteRunnable;
-
-/**
- * Demonstrates a simple use of {@link IgniteRunnable}.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
- * with {@code examples/config/example-ignite.xml} configuration.
- */
-public class ComputeAsyncExample {
- /**
- * 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).");
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeBroadcastExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeBroadcastExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeBroadcastExample.java
deleted file mode 100644
index f839911..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeBroadcastExample.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.computegrid;
-
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.ExampleNodeStartup;
-
-/**
- * Demonstrates broadcasting computations within cluster.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
- * with {@code examples/config/example-ignite.xml} configuration.
- */
-public class ComputeBroadcastExample {
- /**
- * 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 broadcast example started.");
-
- // Print hello message on all nodes.
- hello(ignite);
-
- // Gather system info from all nodes.
- gatherSystemInfo(ignite);
- }
- }
-
- /**
- * Print 'Hello' message on all nodes.
- *
- * @param ignite Ignite instance.
- * @throws IgniteException If failed.
- */
- private static void hello(Ignite ignite) throws IgniteException {
- // Print out hello message on all nodes.
- ignite.compute().broadcast(() -> {
- System.out.println();
- System.out.println(">>> Hello Node! :)");
- });
-
- System.out.println();
- System.out.println(">>> Check all nodes for hello message output.");
- }
-
- /**
- * Gather system info from all nodes and print it out.
- *
- * @param ignite Ignite instance.
- * @throws IgniteException if failed.
- */
- private static void gatherSystemInfo(Ignite ignite) throws IgniteException {
- // Gather system info from all nodes.
- Collection<String> res = ignite.compute().broadcast(() -> {
- System.out.println();
- System.out.println("Executing task on node: " + ignite.cluster().localNode().id());
-
- return "Node ID: " + ignite.cluster().localNode().id() + "\n" +
- "OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " +
- System.getProperty("os.arch") + "\n" +
- "User: " + System.getProperty("user.name") + "\n" +
- "JRE: " + System.getProperty("java.runtime.name") + " " +
- System.getProperty("java.runtime.version");
- });
-
- // Print result.
- System.out.println();
- System.out.println("Nodes system information:");
- System.out.println();
-
- res.forEach(r -> {
- System.out.println(r);
- System.out.println();
- });
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 2cbece8..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeCallableExample.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.computegrid;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.lang.IgniteCallable;
-
-/**
- * Demonstrates using of {@link IgniteCallable} job execution on the cluster.
- * <p>
- * This example takes a sentence composed of multiple words and counts number of non-space
- * characters in the sentence by having each compute job count characters in each individual
- * word.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
- * with {@code examples/config/example-ignite.xml} configuration.
- */
-public class ComputeCallableExample {
- /**
- * 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 callable example started.");
-
- 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);
-
- int sum = res.stream().mapToInt(i -> i).sum();
-
- System.out.println();
- System.out.println(">>> Total number of characters in the phrase is '" + sum + "'.");
- System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClosureExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClosureExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClosureExample.java
deleted file mode 100644
index fc7564f..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClosureExample.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.computegrid;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.ExampleNodeStartup;
-
-/**
- * Demonstrates a simple use of Ignite with reduce closure.
- * <p>
- * This example splits a phrase into collection of words, computes their length on different
- * nodes and then computes total amount of non-whitespaces characters in the phrase.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
- * with {@code examples/config/example-ignite.xml} configuration.
- */
-public class ComputeClosureExample {
- /**
- * 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 closure example started.");
-
- // Execute closure on all cluster nodes.
- Collection<Integer> res = ignite.compute().apply(
- (String word) -> {
- System.out.println();
- System.out.println(">>> Printing '" + word + "' on this node from ignite job.");
-
- // Return number of letters in the word.
- return word.length();
- },
- // Job parameters. Ignite will create as many jobs as there are parameters.
- Arrays.asList("Count characters using closure".split(" "))
- );
-
- int sum = res.stream().mapToInt(i -> i).sum();
-
- System.out.println();
- System.out.println(">>> Total number of characters in the phrase is '" + sum + "'.");
- System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 4dc7c5f..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeRunnableExample.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.computegrid;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCompute;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.lang.IgniteRunnable;
-
-/**
- * Demonstrates a simple use of {@link IgniteRunnable}.
- * <p>
- * Remote nodes should always be 0started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
- * with {@code examples/config/example-ignite.xml} configuration.
- */
-public class ComputeRunnableExample {
- /**
- * 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).");
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/package-info.java
deleted file mode 100644
index a293faa..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Basic examples for computational ignite functionality.
- */
-package org.apache.ignite.examples.java8.computegrid;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAffinityExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAffinityExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAffinityExample.java
deleted file mode 100644
index 2867bf1..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAffinityExample.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.datagrid;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteCompute;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.lang.IgniteRunnable;
-
-/**
- * This example demonstrates the simplest code that populates the distributed cache
- * and co-locates simple closure execution with each key. The goal of this particular
- * example is to provide the simplest code example of this logic.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-ignite.xml} configuration.
- */
-public final class CacheAffinityExample {
- /** Cache name. */
- private static final String CACHE_NAME = CacheAffinityExample.class.getSimpleName();
-
- /** Number of keys. */
- private static final int KEY_CNT = 20;
-
- /**
- * 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.");
-
- CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
-
- cfg.setCacheMode(CacheMode.PARTITIONED);
- cfg.setName(CACHE_NAME);
-
- // Auto-close cache at the end of the example.
- try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
- 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);
- }
- }
- }
-
- /**
- * Collocates jobs with keys they need to work on using
- * {@link IgniteCompute#affinityRun(String, Object, IgniteRunnable)} method.
- */
- private static void visitUsingAffinityRun() {
- Ignite ignite = Ignition.ignite();
-
- final IgniteCache<Integer, String> cache = ignite.cache(CACHE_NAME);
-
- for (int i = 0; i < KEY_CNT; i++) {
- int key = i;
-
- // This runnable will execute on the remote node where
- // data with the given key is located. Since it will be co-located
- // we can use local 'peek' operation safely.
- ignite.compute().affinityRun(CACHE_NAME, key,
- () -> System.out.println("Co-located using affinityRun [key= " + key + ", value=" + cache.localPeek(key) + ']'));
- }
- }
-
- /**
- * Collocates jobs with keys they need to work on using {@link Affinity#mapKeysToNodes(Collection)}
- * method. The difference from {@code affinityRun(...)} method is that here we process multiple keys
- * in a single job.
- */
- private static void visitUsingMapKeysToNodes() {
- final Ignite ignite = Ignition.ignite();
-
- Collection<Integer> keys = new ArrayList<>(KEY_CNT);
-
- for (int i = 0; i < KEY_CNT; i++)
- keys.add(i);
-
- // Map all keys to nodes.
- Map<ClusterNode, Collection<Integer>> mappings = ignite.<Integer>affinity(CACHE_NAME).mapKeysToNodes(keys);
-
- for (Map.Entry<ClusterNode, Collection<Integer>> mapping : mappings.entrySet()) {
- ClusterNode node = mapping.getKey();
-
- final Collection<Integer> mappedKeys = mapping.getValue();
-
- if (node != null) {
- // Bring computations to the nodes where the data resides (i.e. collocation).
- ignite.compute(ignite.cluster().forNode(node)).run(() -> {
- IgniteCache<Integer, String> cache = ignite.cache(CACHE_NAME);
-
- // Peek is a local memory lookup, however, value should never be 'null'
- // as we are co-located with node that has a given key.
- for (Integer key : mappedKeys)
- System.out.println("Co-located using mapKeysToNodes [key= " + key +
- ", value=" + cache.localPeek(key) + ']');
- });
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheApiExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheApiExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheApiExample.java
deleted file mode 100644
index b78003b..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheApiExample.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.datagrid;
-
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-
-/**
- * This example demonstrates some of the cache rich API capabilities.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-ignite.xml} configuration.
- */
-public class CacheApiExample {
- /** Cache name. */
- private static final String CACHE_NAME = CacheApiExample.class.getSimpleName();
-
- /**
- * 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 API example started.");
-
- CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
-
- cfg.setCacheMode(CacheMode.PARTITIONED);
- cfg.setName(CACHE_NAME);
-
- // Auto-close cache at the end of the example.
- try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
- // Demonstrate atomic map operations.
- atomicMapOperations(cache);
- }
- finally {
- // Distributed cache could be removed from cluster only by #destroyCache() call.
- ignite.destroyCache(CACHE_NAME);
- }
- }
- }
-
- /**
- * Demonstrates cache operations similar to {@link ConcurrentMap} API. Note that
- * cache API is a lot richer than the JDK {@link ConcurrentMap}.
- *
- * @throws IgniteException If failed.
- */
- private static void atomicMapOperations(final IgniteCache<Integer, String> cache) throws IgniteException {
- System.out.println();
- System.out.println(">>> Cache atomic map operation examples.");
-
- // Put and return previous value.
- String v = cache.getAndPut(1, "1");
- assert v == null;
-
- // Put and do not return previous value (all methods ending with 'x' return boolean).
- // Performs better when previous value is not needed.
- cache.put(2, "2");
-
- // Put-if-absent.
- boolean b1 = cache.putIfAbsent(4, "4");
- boolean b2 = cache.putIfAbsent(4, "44");
- assert b1 && !b2;
-
- // Invoke - assign new value based on previous value.
- cache.put(6, "6");
-
- cache.invoke(6, (entry, args) -> {
- String val = entry.getValue();
-
- entry.setValue(val + "6"); // Set new value based on previous value.
-
- return null;
- });
-
- // Replace.
- cache.put(7, "7");
- b1 = cache.replace(7, "7", "77");
- b2 = cache.replace(7, "7", "777");
- assert b1 & !b2;
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAsyncApiExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAsyncApiExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAsyncApiExample.java
deleted file mode 100644
index ac80fb6..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheAsyncApiExample.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.datagrid;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.lang.IgniteFuture;
-
-/**
- * This example demonstrates some of the cache rich API capabilities.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-ignite.xml} configuration.
- */
-public class CacheAsyncApiExample {
- /** Cache name. */
- private static final String CACHE_NAME = CacheAsyncApiExample.class.getSimpleName();
-
- /**
- * 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 asynchronous API example started.");
-
- CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
-
- cfg.setCacheMode(CacheMode.PARTITIONED);
- cfg.setName(CACHE_NAME);
-
- // Auto-close cache at the end of the example.
- try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
- // Enable asynchronous mode.
- IgniteCache<Integer, String> asyncCache = cache.withAsync();
-
- Collection<IgniteFuture<?>> futs = new ArrayList<>();
-
- // Execute several puts asynchronously.
- for (int i = 0; i < 10; i++) {
- asyncCache.put(i, String.valueOf(i));
-
- futs.add(asyncCache.future());
- }
-
- // Wait for completion of all futures.
- futs.forEach(IgniteFuture::get);
-
- // Execute get operation asynchronously.
- asyncCache.get(1);
-
- // Asynchronously wait for result.
- asyncCache.<String>future().listen(fut ->
- System.out.println("Get operation completed [value=" + fut.get() + ']'));
- }
- finally {
- // Distributed cache could be removed from cluster only by #destroyCache() call.
- ignite.destroyCache(CACHE_NAME);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheEntryProcessorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheEntryProcessorExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheEntryProcessorExample.java
deleted file mode 100644
index 24633a8..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/CacheEntryProcessorExample.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.java8.datagrid;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import javax.cache.processor.EntryProcessor;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.ExampleNodeStartup;
-
-/**
- * This example demonstrates the simplest code that populates the distributed cache and co-locates simple closure
- * execution with each key. The goal of this particular example is to provide the simplest code example of this logic
- * using EntryProcessor.
- * <p>
- * Remote nodes should always be started with special configuration file which enables P2P
- * class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node with
- * {@code examples/config/example-ignite.xml} configuration.
- */
-public class CacheEntryProcessorExample {
- /** Cache name. */
- private static final String CACHE_NAME = CacheEntryProcessorExample.class.getSimpleName();
-
- /** Number of keys. */
- private static final int KEY_CNT = 20;
-
- /** Set of predefined keys. */
- private static final Set<Integer> KEYS_SET;
-
- /**
- * Initializes keys set that is used in bulked operations in the example.
- */
- static {
- KEYS_SET = new HashSet<>();
-
- for (int i = 0; i < KEY_CNT; i++)
- KEYS_SET.add(i);
- }
-
- /**
- * 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(">>> Entry processor example started.");
-
- // Auto-close cache at the end of the example.
- try (IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(CACHE_NAME)) {
- // Demonstrates usage of EntryProcessor.invoke(...) method.
- populateEntriesWithInvoke(cache);
-
- // Demonstrates usage of EntryProcessor.invokeAll(...) method.
- incrementEntriesWithInvokeAll(cache);
- }
- finally {
- // Distributed cache could be removed from cluster only by #destroyCache() call.
- ignite.destroyCache(CACHE_NAME);
- }
- }
- }
-
- /**
- * Populates cache with values using {@link IgniteCache#invoke(Object, EntryProcessor, Object...)} method.
- *
- * @param cache Cache that must be populated.
- */
- private static void populateEntriesWithInvoke(IgniteCache<Integer, Integer> cache) {
- // Must be no entry in the cache at this point.
- printCacheEntries(cache);
-
- System.out.println("");
- System.out.println(">> Populating the cache using EntryProcessor.");
-
- // Invokes EntryProcessor for every key sequentially.
- for (int i = 0; i < KEY_CNT; i++) {
- cache.invoke(i, (entry, object) -> {
- // Initializes entry's value if it's not set.
- if (entry.getValue() == null)
- entry.setValue((entry.getKey() + 1) * 10);
- return null;
- });
- }
-
- // Print outs entries that are set using the EntryProcessor above.
- printCacheEntries(cache);
- }
-
- /**
- * Increments values of entries stored in the cache using {@link IgniteCache#invokeAll(Set, EntryProcessor,
- * Object...)} method.
- *
- * @param cache Cache instance.
- */
- private static void incrementEntriesWithInvokeAll(IgniteCache<Integer, Integer> cache) {
- System.out.println("");
- System.out.println(">> Incrementing values in the cache using EntryProcessor.");
-
- // Using EntryProcessor.invokeAll to increment every value in place.
- cache.invokeAll(KEYS_SET, (entry, object) -> {
- entry.setValue(entry.getValue() + 5);
-
- return null;
- });
-
- // Print outs entries that are incremented using the EntryProcessor above.
- printCacheEntries(cache);
- }
-
- /**
- * Prints out all the entries that are stored in a cache.
- *
- * @param cache Cache.
- */
- private static void printCacheEntries(IgniteCache<Integer, Integer> cache) {
- System.out.println();
- System.out.println(">>> Entries in the cache.");
-
- Map<Integer, Integer> entries = cache.getAll(KEYS_SET);
-
- if (entries.isEmpty())
- System.out.println("No entries in the cache.");
- else {
- for (Map.Entry<Integer, Integer> entry : entries.entrySet())
- System.out.println("Entry [key=" + entry.getKey() + ", value=" + entry.getValue() + ']');
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java
deleted file mode 100644
index d8c45d6..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/datagrid/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Demonstrates data ignite cache usage.
- */
-package org.apache.ignite.examples.java8.datagrid;
\ No newline at end of file