ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsetrak...@apache.org
Subject [4/6] incubator-ignite git commit: sprint-1 - Renaming ManagedServices to IgniteServices.
Date Fri, 06 Feb 2015 00:32:15 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/CreditRiskManager.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/CreditRiskManager.java b/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/CreditRiskManager.java
new file mode 100644
index 0000000..051b782
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/CreditRiskManager.java
@@ -0,0 +1,143 @@
+/*
+ * 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.computegrid.montecarlo;
+
+import java.util.*;
+
+/**
+ * This class abstracts out the calculation of risk for a credit portfolio.
+ */
+@SuppressWarnings({"FloatingPointEquality"})
+public class CreditRiskManager {
+    /**
+     * Default randomizer with normal distribution.
+     * Note that since every JVM on the cluster will have its own random
+     * generator (independently initialized) the Monte-Carlo simulation
+     * will be slightly skewed when performed on the ignite cluster due to skewed
+     * normal distribution of the sub-jobs comparing to execution on the
+     * local node only with single random generator. Real-life applications
+     * may want to provide its own implementation of distributed random
+     * generator.
+     */
+    private static Random rndGen = new Random();
+
+    /**
+     * Calculates credit risk for a given credit portfolio. This calculation uses
+     * Monte-Carlo Simulation to produce risk value.
+     *
+     * @param portfolio Credit portfolio.
+     * @param horizon Forecast horizon (in days).
+     * @param num Number of Monte-Carlo iterations.
+     * @param percentile Cutoff level.
+     * @return Credit risk value, i.e. the minimal amount that creditor has to
+     *      have available to cover possible defaults.
+     */
+    public double calculateCreditRiskMonteCarlo(Credit[] portfolio, int horizon, int num, double percentile) {
+        System.out.println(">>> Calculating credit risk for portfolio [size=" + portfolio.length + ", horizon=" +
+            horizon + ", percentile=" + percentile + ", iterations=" + num + "] <<<");
+
+        long start = System.currentTimeMillis();
+
+        double[] losses = calculateLosses(portfolio, horizon, num);
+
+        Arrays.sort(losses);
+
+        double[] lossProbs = new double[losses.length];
+
+        // Count variational numbers.
+        // Every next one either has the same value or previous one plus probability of loss.
+        for (int i = 0; i < losses.length; i++)
+            if (i == 0)
+                // First time it's just a probability of first value.
+                lossProbs[i] = getLossProbability(losses, 0);
+            else if (losses[i] != losses[i - 1])
+                // Probability of this loss plus previous one.
+                lossProbs[i] = getLossProbability(losses, i) + lossProbs[i - 1];
+            else
+                // The same loss the same probability.
+                lossProbs[i] = lossProbs[i - 1];
+
+        // Count percentile.
+        double crdRisk = 0;
+
+        for (int i = 0; i < lossProbs.length; i++)
+            if (lossProbs[i] > percentile) {
+                crdRisk = losses[i - 1];
+
+                break;
+            }
+
+        System.out.println(">>> Finished calculating portfolio risk [risk=" + crdRisk +
+            ", time=" + (System.currentTimeMillis() - start) + "ms]");
+
+        return crdRisk;
+    }
+
+    /**
+     * Calculates losses for the given credit portfolio using Monte-Carlo Simulation.
+     * Simulates probability of default only.
+     *
+     * @param portfolio Credit portfolio.
+     * @param horizon Forecast horizon.
+     * @param num Number of Monte-Carlo iterations.
+     * @return Losses array simulated by Monte Carlo method.
+     */
+    private double[] calculateLosses(Credit[] portfolio, int horizon, int num) {
+        double[] losses = new double[num];
+
+        // Count losses using Monte-Carlo method. We generate random probability of default,
+        // if it exceeds certain credit default value we count losses - otherwise count income.
+        for (int i = 0; i < num; i++)
+            for (Credit crd : portfolio) {
+                int remDays = Math.min(crd.getRemainingTerm(), horizon);
+
+                if (rndGen.nextDouble() >= 1 - crd.getDefaultProbability(remDays))
+                    // (1 + 'r' * min(H, W) / 365) * S.
+                    // Where W is a horizon, H is a remaining crediting term, 'r' is an annual credit rate,
+                    // S is a remaining credit amount.
+                    losses[i] += (1 + crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365)
+                        * crd.getRemainingAmount();
+                else
+                    // - 'r' * min(H,W) / 365 * S
+                    // Where W is a horizon, H is a remaining crediting term, 'r' is a annual credit rate,
+                    // S is a remaining credit amount.
+                    losses[i] -= crd.getAnnualRate() * Math.min(horizon, crd.getRemainingTerm()) / 365 *
+                        crd.getRemainingAmount();
+            }
+
+        return losses;
+    }
+
+    /**
+     * Calculates probability of certain loss in array of losses.
+     *
+     * @param losses Array of losses.
+     * @param i Index of certain loss in array.
+     * @return Probability of loss with given index.
+     */
+    private double getLossProbability(double[] losses, int i) {
+        double cnt = 0;
+        double loss = losses[i];
+
+        for (double tmp : losses)
+            if (loss == tmp)
+                cnt++;
+
+        return cnt / losses.length;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/package.html b/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/package.html
new file mode 100644
index 0000000..c52f593
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/computegrid/montecarlo/package.html
@@ -0,0 +1,24 @@
+<!--
+  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.
+  -->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<body>
+    <!-- Package description. -->
+    Monte-Carlo simulation example.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/computegrid/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/computegrid/package.html b/examples/src/main/java/org/apache/ignite/examples/computegrid/package.html
new file mode 100644
index 0000000..5e8d2e2
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/computegrid/package.html
@@ -0,0 +1,23 @@
+<!--
+  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.
+  -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<body>
+    <!-- Package description. -->
+    Basic examples for computational ignite functionality.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicLongExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicLongExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicLongExample.java
deleted file mode 100644
index ed01289..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicLongExample.java
+++ /dev/null
@@ -1,74 +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.datagrid.datastructures;
-
-import org.apache.ignite.*;
-import org.apache.ignite.examples.datagrid.*;
-import org.apache.ignite.lang.*;
-
-import java.util.*;
-
-/**
- * Demonstrates a simple usage of distributed atomic long.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
- * <p>
- * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-cache.xml} configuration.
- */
-public final class IgniteAtomicLongExample {
-    /** Number of retries */
-    private static final int RETRIES = 20;
-
-    /**
-     * 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-cache.xml")) {
-            System.out.println();
-            System.out.println(">>> Atomic long example started.");
-
-            // Make name for atomic long (by which it will be known in the cluster).
-            String atomicName = UUID.randomUUID().toString();
-
-            // Initialize atomic long.
-            final IgniteAtomicLong atomicLong = ignite.atomicLong(atomicName, 0, true);
-
-            System.out.println();
-            System.out.println("Atomic long initial value : " + atomicLong.get() + '.');
-
-            // Try increment atomic long from all nodes.
-            // Note that this node is also part of the ignite cluster.
-            ignite.compute().broadcast(new IgniteCallable<Object>() {
-                @Override public Object call() {
-                    for (int i = 0; i < RETRIES; i++)
-                        System.out.println("AtomicLong value has been incremented: " + atomicLong.incrementAndGet());
-
-                    return null;
-                }
-            });
-
-            System.out.println();
-            System.out.println("Atomic long value after successful CAS: " + atomicLong.get());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicReferenceExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicReferenceExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicReferenceExample.java
deleted file mode 100644
index f2dc2b6..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicReferenceExample.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.datagrid.datastructures;
-
-import org.apache.ignite.*;
-import org.apache.ignite.examples.datagrid.*;
-import org.apache.ignite.lang.*;
-
-import java.util.*;
-
-/**
- * Demonstrates a simple usage of distributed atomic reference.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
- * <p>
- * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-cache.xml} configuration.
- */
-public final class IgniteAtomicReferenceExample {
-    /**
-     * 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-cache.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.
-            Runnable 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.");
-
-            ref.compareAndSet("WRONG EXPECTED VALUE", newVal); // Won't change.
-
-            // 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).");
-    }
-
-    /**
-     * Obtains atomic reference.
-     */
-    private static class ReferenceClosure implements IgniteRunnable {
-        /** Reference name. */
-        private final String refName;
-
-        /**
-         * @param refName Reference name.
-         */
-        ReferenceClosure(String refName) {
-            this.refName = refName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void run() {
-            IgniteAtomicReference<String> ref = Ignition.ignite().atomicReference(refName, null, true);
-
-            System.out.println("Atomic reference value is " + ref.get() + '.');
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicSequenceExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicSequenceExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicSequenceExample.java
deleted file mode 100644
index cec267b..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicSequenceExample.java
+++ /dev/null
@@ -1,96 +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.datagrid.datastructures;
-
-import org.apache.ignite.*;
-import org.apache.ignite.examples.datagrid.*;
-import org.apache.ignite.lang.*;
-
-import java.util.*;
-
-/**
- * Demonstrates a simple usage of distributed atomic sequence.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
- * <p>
- * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-cache.xml} configuration.
- */
-public final class IgniteAtomicSequenceExample {
-    /** Number of retries */
-    private static final int RETRIES = 20;
-
-    /**
-     * 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-cache.xml")) {
-            System.out.println();
-            System.out.println(">>> Cache atomic sequence example started.");
-
-            // Make name of sequence.
-            final String seqName = UUID.randomUUID().toString();
-
-            // Initialize atomic sequence.
-            IgniteAtomicSequence seq = ignite.atomicSequence(seqName, 0, true);
-
-            // First value of atomic sequence on this node.
-            long firstVal = seq.get();
-
-            System.out.println("Sequence initial value: " + firstVal);
-
-            // Try increment atomic sequence on all cluster nodes. Note that this node is also part of the cluster.
-            ignite.compute().broadcast(new SequenceClosure(seqName));
-
-            System.out.println("Sequence after incrementing [expected=" + (firstVal + RETRIES) + ", actual=" +
-                seq.get() + ']');
-        }
-
-        System.out.println();
-        System.out.println("Finished atomic sequence example...");
-        System.out.println("Check all nodes for output (this node is also part of the cluster).");
-    }
-
-    /**
-     * Obtains atomic sequence.
-     */
-    private static class SequenceClosure implements IgniteRunnable {
-        /** Sequence name. */
-        private final String seqName;
-
-        /**
-         * @param seqName Sequence name.
-         */
-        SequenceClosure(String seqName) {
-            this.seqName = seqName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void run() {
-            IgniteAtomicSequence seq = Ignition.ignite().atomicSequence(seqName, 0, true);
-
-            for (int i = 0; i < RETRIES; i++)
-                System.out.println("Sequence [currentValue=" + seq.get() + ", afterIncrement=" +
-                    seq.incrementAndGet() + ']');
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicStampedExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicStampedExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicStampedExample.java
deleted file mode 100644
index 30a2f66..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteAtomicStampedExample.java
+++ /dev/null
@@ -1,117 +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.datagrid.datastructures;
-
-import org.apache.ignite.*;
-import org.apache.ignite.examples.datagrid.*;
-import org.apache.ignite.lang.*;
-
-import java.util.*;
-
-/**
- * Demonstrates a simple usage of distributed atomic stamped.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
- * <p>
- * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-cache.xml} configuration.
- */
-public final class IgniteAtomicStampedExample {
-    /**
-     * 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-cache.xml")) {
-            System.out.println();
-            System.out.println(">>> Atomic stamped example started.");
-
-            // Make name of atomic stamped.
-            String stampedName = UUID.randomUUID().toString();
-
-            // Make value of atomic stamped.
-            String val = UUID.randomUUID().toString();
-
-            // Make stamp of atomic stamped.
-            String stamp = UUID.randomUUID().toString();
-
-            // Initialize atomic stamped.
-            IgniteAtomicStamped<String, String> stamped = ignite.atomicStamped(stampedName, val, stamp, true);
-
-            System.out.println("Atomic stamped initial [value=" + stamped.value() + ", stamp=" + stamped.stamp() + ']');
-
-            // Make closure for checking atomic stamped.
-            Runnable c = new StampedUpdateClosure(stampedName);
-
-            // Check atomic stamped on all cluster nodes.
-            ignite.compute().broadcast(c);
-
-            // Make new value of atomic stamped.
-            String newVal = UUID.randomUUID().toString();
-
-            // Make new stamp of atomic stamped.
-            String newStamp = UUID.randomUUID().toString();
-
-            System.out.println("Try to change value and stamp of atomic stamped with wrong expected value and stamp.");
-
-            stamped.compareAndSet("WRONG EXPECTED VALUE", newVal, "WRONG EXPECTED STAMP", newStamp);
-
-            // Check atomic stamped on all cluster nodes.
-            // Atomic stamped value and stamp shouldn't be changed.
-            ignite.compute().run(c);
-
-            System.out.println("Try to change value and stamp of atomic stamped with correct value and stamp.");
-
-            stamped.compareAndSet(val, newVal, stamp, newStamp);
-
-            // Check atomic stamped on all cluster nodes.
-            // Atomic stamped value and stamp should be changed.
-            ignite.compute().run(c);
-        }
-
-        System.out.println();
-        System.out.println("Finished atomic stamped example...");
-        System.out.println("Check all nodes for output (this node is also part of the cluster).");
-    }
-
-    /**
-     * Performs update of on an atomic stamped variable in cache.
-     */
-    private static class StampedUpdateClosure implements IgniteRunnable {
-        /** Atomic stamped variable name. */
-        private final String stampedName;
-
-        /**
-         * @param stampedName Atomic stamped variable name.
-         */
-        StampedUpdateClosure(String stampedName) {
-            this.stampedName = stampedName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void run() {
-            IgniteAtomicStamped<String, String> stamped = Ignition.ignite().
-                atomicStamped(stampedName, null, null, true);
-
-            System.out.println("Atomic stamped [value=" + stamped.value() + ", stamp=" + stamped.stamp() + ']');
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteCountDownLatchExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteCountDownLatchExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteCountDownLatchExample.java
deleted file mode 100644
index f7a282c..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteCountDownLatchExample.java
+++ /dev/null
@@ -1,96 +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.datagrid.datastructures;
-
-import org.apache.ignite.*;
-import org.apache.ignite.examples.datagrid.*;
-import org.apache.ignite.lang.*;
-
-import java.util.*;
-
-/**
- * Demonstrates a simple usage of distributed count down latch.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
- * <p>
- * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-cache.xml} configuration.
- */
-public class IgniteCountDownLatchExample {
-    /** Number of latch initial count */
-    private static final int INITIAL_COUNT = 10;
-
-    /**
-     * Executes example.
-     *
-     * @param args Command line arguments, none required.
-     * @throws IgniteCheckedException If example execution failed.
-     */
-    public static void main(String[] args) throws IgniteCheckedException {
-        try (Ignite ignite = Ignition.start("examples/config/example-cache.xml")) {
-            System.out.println();
-            System.out.println(">>> Cache atomic countdown latch example started.");
-
-            // Make name of count down latch.
-            final String latchName = UUID.randomUUID().toString();
-
-            // Initialize count down latch.
-            IgniteCountDownLatch latch = ignite.countDownLatch(latchName, INITIAL_COUNT, false, true);
-
-            System.out.println("Latch initial value: " + latch.count());
-
-            // Start waiting on the latch on all cluster nodes.
-            for (int i = 0; i < INITIAL_COUNT; i++)
-                ignite.compute().run(new LatchClosure(latchName));
-
-            // Wait for latch to go down which essentially means that all remote closures completed.
-            latch.await();
-
-            System.out.println("All latch closures have completed.");
-        }
-
-        System.out.println();
-        System.out.println("Finished count down latch example...");
-        System.out.println("Check all nodes for output (this node is also part of the cluster).");
-    }
-
-    /**
-     * Closure which simply waits on the latch on all nodes.
-     */
-    private static class LatchClosure implements IgniteRunnable {
-        /** Latch name. */
-        private final String latchName;
-
-        /**
-         * @param latchName Latch name.
-         */
-        LatchClosure(String latchName) {
-            this.latchName = latchName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void run() {
-            IgniteCountDownLatch latch = Ignition.ignite().countDownLatch(latchName, 1, false, true);
-
-            int newCnt = latch.countDown();
-
-            System.out.println("Counted down [newCnt=" + newCnt + ", nodeId=" + Ignition.ignite().cluster().localNode().id() + ']');
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteQueueExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteQueueExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteQueueExample.java
deleted file mode 100644
index 6f27451..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteQueueExample.java
+++ /dev/null
@@ -1,206 +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.datagrid.datastructures;
-
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.examples.datagrid.*;
-import org.apache.ignite.lang.*;
-
-import java.util.*;
-
-/**
- * Ignite cache distributed queue example. This example demonstrates {@code FIFO} unbounded
- * cache queue.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
- * <p>
- * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-cache.xml} configuration.
- */
-public class IgniteQueueExample {
-    /** Cache name. */
-    private static final String CACHE_NAME = "partitioned_tx";
-
-    /** Number of retries */
-    private static final int RETRIES = 20;
-
-    /** Queue instance. */
-    private static IgniteQueue<String> queue;
-
-    /**
-     * 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-cache.xml")) {
-            System.out.println();
-            System.out.println(">>> Ignite queue example started.");
-
-            // Make queue name.
-            String queueName = UUID.randomUUID().toString();
-
-            queue = initializeQueue(ignite, queueName);
-
-            readFromQueue(ignite);
-
-            writeToQueue(ignite);
-
-            clearAndRemoveQueue();
-        }
-
-        System.out.println("Cache queue example finished.");
-    }
-
-    /**
-     * Initialize queue.
-     *
-     * @param ignite Ignite.
-     * @param queueName Name of queue.
-     * @return Queue.
-     * @throws IgniteException If execution failed.
-     */
-    private static IgniteQueue<String> initializeQueue(Ignite ignite, String queueName) throws IgniteException {
-        IgniteCollectionConfiguration colCfg = new IgniteCollectionConfiguration();
-
-        colCfg.setCacheName(CACHE_NAME);
-
-        // Initialize new FIFO queue.
-        IgniteQueue<String> queue = ignite.queue(queueName, 0, colCfg);
-
-        // Initialize queue items.
-        // We will be use blocking operation and queue size must be appropriated.
-        for (int i = 0; i < ignite.cluster().nodes().size() * RETRIES * 2; i++)
-            queue.put(Integer.toString(i));
-
-        System.out.println("Queue size after initializing: " + queue.size());
-
-        return queue;
-    }
-
-    /**
-     * Read items from head and tail of queue.
-     *
-     * @param ignite Ignite.
-     * @throws IgniteException If failed.
-     */
-    private static void readFromQueue(Ignite ignite) throws IgniteException {
-        final String queueName = queue.name();
-
-        // Read queue items on each node.
-        ignite.compute().broadcast(new QueueClosure(queueName, false));
-
-        System.out.println("Queue size after reading [expected=0, actual=" + queue.size() + ']');
-    }
-
-    /**
-     * Write items into queue.
-     *
-     * @param ignite Ignite.
-     * @throws IgniteException If failed.
-     */
-    private static void writeToQueue(Ignite ignite) throws IgniteException {
-        final String queueName = queue.name();
-
-        // Write queue items on each node.
-        ignite.compute().run(new QueueClosure(queueName, true));
-
-        System.out.println("Queue size after writing [expected=" + ignite.cluster().nodes().size() * RETRIES +
-            ", actual=" + queue.size() + ']');
-
-        System.out.println("Iterate over queue.");
-
-        // Iterate over queue.
-        for (String item : queue)
-            System.out.println("Queue item: " + item);
-    }
-
-    /**
-     * Clear and remove queue.
-     *
-     * @throws IgniteException If execution failed.
-     */
-    private static void clearAndRemoveQueue() throws IgniteException {
-        System.out.println("Queue size before clearing: " + queue.size());
-
-        // Clear queue.
-        queue.clear();
-
-        System.out.println("Queue size after clearing: " + queue.size());
-
-        // Remove queue.
-        queue.close();
-
-        // Try to work with removed queue.
-        try {
-            queue.poll();
-        }
-        catch (IgniteException expected) {
-            System.out.println("Expected exception - " + expected.getMessage());
-        }
-    }
-
-    /**
-     * Closure to populate or poll the queue.
-     */
-    private static class QueueClosure implements IgniteRunnable {
-        /** Queue name. */
-        private final String queueName;
-
-        /** Flag indicating whether to put or poll. */
-        private final boolean put;
-
-        /**
-         * @param queueName Queue name.
-         * @param put Flag indicating whether to put or poll.
-         */
-        QueueClosure(String queueName, boolean put) {
-            this.queueName = queueName;
-            this.put = put;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void run() {
-            IgniteQueue<String> queue = Ignition.ignite().queue(queueName, 0, null);
-
-            if (put) {
-                UUID locId = Ignition.ignite().cluster().localNode().id();
-
-                for (int i = 0; i < RETRIES; i++) {
-                    String item = locId + "_" + Integer.toString(i);
-
-                    queue.put(item);
-
-                    System.out.println("Queue item has been added: " + item);
-                }
-            }
-            else {
-                // Take items from queue head.
-                for (int i = 0; i < RETRIES; i++)
-                    System.out.println("Queue item has been read from queue head: " + queue.take());
-
-                // Take items from queue head once again.
-                for (int i = 0; i < RETRIES; i++)
-                    System.out.println("Queue item has been read from queue head: " + queue.poll());
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteSetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteSetExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteSetExample.java
deleted file mode 100644
index e8e6b78..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteSetExample.java
+++ /dev/null
@@ -1,186 +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.datagrid.datastructures;
-
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.examples.datagrid.*;
-import org.apache.ignite.lang.*;
-
-import java.util.*;
-
-/**
- * Ignite cache distributed set example.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
- * <p>
- * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
- * start node with {@code examples/config/example-cache.xml} configuration.
- */
-public class IgniteSetExample {
-    /** Cache name. */
-    private static final String CACHE_NAME = "partitioned_tx";
-
-    /** Set instance. */
-    private static IgniteSet<String> set;
-
-    /**
-     * 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-cache.xml")) {
-            System.out.println();
-            System.out.println(">>> Ignite set example started.");
-
-            // Make set name.
-            String setName = UUID.randomUUID().toString();
-
-            set = initializeSet(ignite, setName);
-
-            writeToSet(ignite);
-
-            clearAndRemoveSet();
-        }
-
-        System.out.println("Ignite set example finished.");
-    }
-
-    /**
-     * Initialize set.
-     *
-     * @param ignite Ignite.
-     * @param setName Name of set.
-     * @return Set.
-     * @throws IgniteException If execution failed.
-     */
-    private static IgniteSet<String> initializeSet(Ignite ignite, String setName) throws IgniteException {
-        IgniteCollectionConfiguration setCfg = new IgniteCollectionConfiguration();
-
-        setCfg.setCacheName(CACHE_NAME);
-
-        // Initialize new set.
-        IgniteSet<String> set = ignite.set(setName, setCfg);
-
-        // Initialize set items.
-        for (int i = 0; i < 10; i++)
-            set.add(Integer.toString(i));
-
-        System.out.println("Set size after initializing: " + set.size());
-
-        return set;
-    }
-
-    /**
-     * Write items into set.
-     *
-     * @param ignite Ignite.
-     * @throws IgniteException If failed.
-     */
-    private static void writeToSet(Ignite ignite) throws IgniteException {
-        final String setName = set.name();
-
-        // Write set items on each node.
-        ignite.compute().broadcast(new SetClosure(setName));
-
-        System.out.println("Set size after writing [expected=" + (10 + ignite.cluster().nodes().size() * 5) +
-            ", actual=" + set.size() + ']');
-
-        System.out.println("Iterate over set.");
-
-        // Iterate over set.
-        for (String item : set)
-            System.out.println("Set item: " + item);
-
-        // Set API usage examples.
-        if (!set.contains("0"))
-            throw new RuntimeException("Set should contain '0' among its elements.");
-
-        if (set.add("0"))
-            throw new RuntimeException("Set should not allow duplicates.");
-
-        if (!set.remove("0"))
-            throw new RuntimeException("Set should correctly remove elements.");
-
-        if (set.contains("0"))
-            throw new RuntimeException("Set should not contain '0' among its elements.");
-
-        if (!set.add("0"))
-            throw new RuntimeException("Set should correctly add new elements.");
-    }
-
-    /**
-     * Clear and remove set.
-     *
-     * @throws IgniteException If execution failed.
-     */
-    private static void clearAndRemoveSet() throws IgniteException {
-        System.out.println("Set size before clearing: " + set.size());
-
-        // Clear set.
-        set.clear();
-
-        System.out.println("Set size after clearing: " + set.size());
-
-        // Remove set.
-        set.close();
-
-        System.out.println("Set was removed: " + set.removed());
-
-        // Try to work with removed set.
-        try {
-            set.contains("1");
-        }
-        catch (IgniteException expected) {
-            System.out.println("Expected exception - " + expected.getMessage());
-        }
-    }
-
-    /**
-     * Closure to populate the set.
-     */
-    private static class SetClosure implements IgniteRunnable {
-        /** Set name. */
-        private final String setName;
-
-        /**
-         * @param setName Set name.
-         */
-        SetClosure(String setName) {
-            this.setName = setName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void run() {
-            IgniteSet<String> set = Ignition.ignite().set(setName, null);
-
-            UUID locId = Ignition.ignite().cluster().localNode().id();
-
-            for (int i = 0; i < 5; i++) {
-                String item = locId + "_" + Integer.toString(i);
-
-                set.add(item);
-
-                System.out.println("Set item has been added: " + item);
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/package.html b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/package.html
deleted file mode 100644
index f9c708f..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/package.html
+++ /dev/null
@@ -1,23 +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.
-  -->
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<body>
-    <!-- Package description. -->
-    Demonstrates using of blocking and non-blocking queues and atomic data structures.
-</body>
-</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicLongExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicLongExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicLongExample.java
new file mode 100644
index 0000000..6548f94
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicLongExample.java
@@ -0,0 +1,74 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.examples.datagrid.*;
+import org.apache.ignite.lang.*;
+
+import java.util.*;
+
+/**
+ * Demonstrates a simple usage of distributed atomic long.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
+ * <p>
+ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-cache.xml} configuration.
+ */
+public final class IgniteAtomicLongExample {
+    /** Number of retries */
+    private static final int RETRIES = 20;
+
+    /**
+     * 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-cache.xml")) {
+            System.out.println();
+            System.out.println(">>> Atomic long example started.");
+
+            // Make name for atomic long (by which it will be known in the cluster).
+            String atomicName = UUID.randomUUID().toString();
+
+            // Initialize atomic long.
+            final IgniteAtomicLong atomicLong = ignite.atomicLong(atomicName, 0, true);
+
+            System.out.println();
+            System.out.println("Atomic long initial value : " + atomicLong.get() + '.');
+
+            // Try increment atomic long from all nodes.
+            // Note that this node is also part of the ignite cluster.
+            ignite.compute().broadcast(new IgniteCallable<Object>() {
+                @Override public Object call() {
+                    for (int i = 0; i < RETRIES; i++)
+                        System.out.println("AtomicLong value has been incremented: " + atomicLong.incrementAndGet());
+
+                    return null;
+                }
+            });
+
+            System.out.println();
+            System.out.println("Atomic long value after successful CAS: " + atomicLong.get());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicReferenceExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicReferenceExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicReferenceExample.java
new file mode 100644
index 0000000..9b5e3d8
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicReferenceExample.java
@@ -0,0 +1,110 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.examples.datagrid.*;
+import org.apache.ignite.lang.*;
+
+import java.util.*;
+
+/**
+ * Demonstrates a simple usage of distributed atomic reference.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
+ * <p>
+ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-cache.xml} configuration.
+ */
+public final class IgniteAtomicReferenceExample {
+    /**
+     * 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-cache.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.
+            Runnable 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.");
+
+            ref.compareAndSet("WRONG EXPECTED VALUE", newVal); // Won't change.
+
+            // 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).");
+    }
+
+    /**
+     * Obtains atomic reference.
+     */
+    private static class ReferenceClosure implements IgniteRunnable {
+        /** Reference name. */
+        private final String refName;
+
+        /**
+         * @param refName Reference name.
+         */
+        ReferenceClosure(String refName) {
+            this.refName = refName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            IgniteAtomicReference<String> ref = Ignition.ignite().atomicReference(refName, null, true);
+
+            System.out.println("Atomic reference value is " + ref.get() + '.');
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicSequenceExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicSequenceExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicSequenceExample.java
new file mode 100644
index 0000000..ac2aec5
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicSequenceExample.java
@@ -0,0 +1,96 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.examples.datagrid.*;
+import org.apache.ignite.lang.*;
+
+import java.util.*;
+
+/**
+ * Demonstrates a simple usage of distributed atomic sequence.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
+ * <p>
+ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-cache.xml} configuration.
+ */
+public final class IgniteAtomicSequenceExample {
+    /** Number of retries */
+    private static final int RETRIES = 20;
+
+    /**
+     * 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-cache.xml")) {
+            System.out.println();
+            System.out.println(">>> Cache atomic sequence example started.");
+
+            // Make name of sequence.
+            final String seqName = UUID.randomUUID().toString();
+
+            // Initialize atomic sequence.
+            IgniteAtomicSequence seq = ignite.atomicSequence(seqName, 0, true);
+
+            // First value of atomic sequence on this node.
+            long firstVal = seq.get();
+
+            System.out.println("Sequence initial value: " + firstVal);
+
+            // Try increment atomic sequence on all cluster nodes. Note that this node is also part of the cluster.
+            ignite.compute().broadcast(new SequenceClosure(seqName));
+
+            System.out.println("Sequence after incrementing [expected=" + (firstVal + RETRIES) + ", actual=" +
+                seq.get() + ']');
+        }
+
+        System.out.println();
+        System.out.println("Finished atomic sequence example...");
+        System.out.println("Check all nodes for output (this node is also part of the cluster).");
+    }
+
+    /**
+     * Obtains atomic sequence.
+     */
+    private static class SequenceClosure implements IgniteRunnable {
+        /** Sequence name. */
+        private final String seqName;
+
+        /**
+         * @param seqName Sequence name.
+         */
+        SequenceClosure(String seqName) {
+            this.seqName = seqName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            IgniteAtomicSequence seq = Ignition.ignite().atomicSequence(seqName, 0, true);
+
+            for (int i = 0; i < RETRIES; i++)
+                System.out.println("Sequence [currentValue=" + seq.get() + ", afterIncrement=" +
+                    seq.incrementAndGet() + ']');
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicStampedExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicStampedExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicStampedExample.java
new file mode 100644
index 0000000..ed38282
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteAtomicStampedExample.java
@@ -0,0 +1,117 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.examples.datagrid.*;
+import org.apache.ignite.lang.*;
+
+import java.util.*;
+
+/**
+ * Demonstrates a simple usage of distributed atomic stamped.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
+ * <p>
+ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-cache.xml} configuration.
+ */
+public final class IgniteAtomicStampedExample {
+    /**
+     * 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-cache.xml")) {
+            System.out.println();
+            System.out.println(">>> Atomic stamped example started.");
+
+            // Make name of atomic stamped.
+            String stampedName = UUID.randomUUID().toString();
+
+            // Make value of atomic stamped.
+            String val = UUID.randomUUID().toString();
+
+            // Make stamp of atomic stamped.
+            String stamp = UUID.randomUUID().toString();
+
+            // Initialize atomic stamped.
+            IgniteAtomicStamped<String, String> stamped = ignite.atomicStamped(stampedName, val, stamp, true);
+
+            System.out.println("Atomic stamped initial [value=" + stamped.value() + ", stamp=" + stamped.stamp() + ']');
+
+            // Make closure for checking atomic stamped.
+            Runnable c = new StampedUpdateClosure(stampedName);
+
+            // Check atomic stamped on all cluster nodes.
+            ignite.compute().broadcast(c);
+
+            // Make new value of atomic stamped.
+            String newVal = UUID.randomUUID().toString();
+
+            // Make new stamp of atomic stamped.
+            String newStamp = UUID.randomUUID().toString();
+
+            System.out.println("Try to change value and stamp of atomic stamped with wrong expected value and stamp.");
+
+            stamped.compareAndSet("WRONG EXPECTED VALUE", newVal, "WRONG EXPECTED STAMP", newStamp);
+
+            // Check atomic stamped on all cluster nodes.
+            // Atomic stamped value and stamp shouldn't be changed.
+            ignite.compute().run(c);
+
+            System.out.println("Try to change value and stamp of atomic stamped with correct value and stamp.");
+
+            stamped.compareAndSet(val, newVal, stamp, newStamp);
+
+            // Check atomic stamped on all cluster nodes.
+            // Atomic stamped value and stamp should be changed.
+            ignite.compute().run(c);
+        }
+
+        System.out.println();
+        System.out.println("Finished atomic stamped example...");
+        System.out.println("Check all nodes for output (this node is also part of the cluster).");
+    }
+
+    /**
+     * Performs update of on an atomic stamped variable in cache.
+     */
+    private static class StampedUpdateClosure implements IgniteRunnable {
+        /** Atomic stamped variable name. */
+        private final String stampedName;
+
+        /**
+         * @param stampedName Atomic stamped variable name.
+         */
+        StampedUpdateClosure(String stampedName) {
+            this.stampedName = stampedName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            IgniteAtomicStamped<String, String> stamped = Ignition.ignite().
+                atomicStamped(stampedName, null, null, true);
+
+            System.out.println("Atomic stamped [value=" + stamped.value() + ", stamp=" + stamped.stamp() + ']');
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteCountDownLatchExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteCountDownLatchExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteCountDownLatchExample.java
new file mode 100644
index 0000000..8cca611
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteCountDownLatchExample.java
@@ -0,0 +1,96 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.examples.datagrid.*;
+import org.apache.ignite.lang.*;
+
+import java.util.*;
+
+/**
+ * Demonstrates a simple usage of distributed count down latch.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
+ * <p>
+ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-cache.xml} configuration.
+ */
+public class IgniteCountDownLatchExample {
+    /** Number of latch initial count */
+    private static final int INITIAL_COUNT = 10;
+
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     * @throws IgniteCheckedException If example execution failed.
+     */
+    public static void main(String[] args) throws IgniteCheckedException {
+        try (Ignite ignite = Ignition.start("examples/config/example-cache.xml")) {
+            System.out.println();
+            System.out.println(">>> Cache atomic countdown latch example started.");
+
+            // Make name of count down latch.
+            final String latchName = UUID.randomUUID().toString();
+
+            // Initialize count down latch.
+            IgniteCountDownLatch latch = ignite.countDownLatch(latchName, INITIAL_COUNT, false, true);
+
+            System.out.println("Latch initial value: " + latch.count());
+
+            // Start waiting on the latch on all cluster nodes.
+            for (int i = 0; i < INITIAL_COUNT; i++)
+                ignite.compute().run(new LatchClosure(latchName));
+
+            // Wait for latch to go down which essentially means that all remote closures completed.
+            latch.await();
+
+            System.out.println("All latch closures have completed.");
+        }
+
+        System.out.println();
+        System.out.println("Finished count down latch example...");
+        System.out.println("Check all nodes for output (this node is also part of the cluster).");
+    }
+
+    /**
+     * Closure which simply waits on the latch on all nodes.
+     */
+    private static class LatchClosure implements IgniteRunnable {
+        /** Latch name. */
+        private final String latchName;
+
+        /**
+         * @param latchName Latch name.
+         */
+        LatchClosure(String latchName) {
+            this.latchName = latchName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            IgniteCountDownLatch latch = Ignition.ignite().countDownLatch(latchName, 1, false, true);
+
+            int newCnt = latch.countDown();
+
+            System.out.println("Counted down [newCnt=" + newCnt + ", nodeId=" + Ignition.ignite().cluster().localNode().id() + ']');
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
new file mode 100644
index 0000000..9dd101b
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
@@ -0,0 +1,206 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.examples.datagrid.*;
+import org.apache.ignite.lang.*;
+
+import java.util.*;
+
+/**
+ * Ignite cache distributed queue example. This example demonstrates {@code FIFO} unbounded
+ * cache queue.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
+ * <p>
+ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-cache.xml} configuration.
+ */
+public class IgniteQueueExample {
+    /** Cache name. */
+    private static final String CACHE_NAME = "partitioned_tx";
+
+    /** Number of retries */
+    private static final int RETRIES = 20;
+
+    /** Queue instance. */
+    private static IgniteQueue<String> queue;
+
+    /**
+     * 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-cache.xml")) {
+            System.out.println();
+            System.out.println(">>> Ignite queue example started.");
+
+            // Make queue name.
+            String queueName = UUID.randomUUID().toString();
+
+            queue = initializeQueue(ignite, queueName);
+
+            readFromQueue(ignite);
+
+            writeToQueue(ignite);
+
+            clearAndRemoveQueue();
+        }
+
+        System.out.println("Cache queue example finished.");
+    }
+
+    /**
+     * Initialize queue.
+     *
+     * @param ignite Ignite.
+     * @param queueName Name of queue.
+     * @return Queue.
+     * @throws IgniteException If execution failed.
+     */
+    private static IgniteQueue<String> initializeQueue(Ignite ignite, String queueName) throws IgniteException {
+        IgniteCollectionConfiguration colCfg = new IgniteCollectionConfiguration();
+
+        colCfg.setCacheName(CACHE_NAME);
+
+        // Initialize new FIFO queue.
+        IgniteQueue<String> queue = ignite.queue(queueName, 0, colCfg);
+
+        // Initialize queue items.
+        // We will be use blocking operation and queue size must be appropriated.
+        for (int i = 0; i < ignite.cluster().nodes().size() * RETRIES * 2; i++)
+            queue.put(Integer.toString(i));
+
+        System.out.println("Queue size after initializing: " + queue.size());
+
+        return queue;
+    }
+
+    /**
+     * Read items from head and tail of queue.
+     *
+     * @param ignite Ignite.
+     * @throws IgniteException If failed.
+     */
+    private static void readFromQueue(Ignite ignite) throws IgniteException {
+        final String queueName = queue.name();
+
+        // Read queue items on each node.
+        ignite.compute().broadcast(new QueueClosure(queueName, false));
+
+        System.out.println("Queue size after reading [expected=0, actual=" + queue.size() + ']');
+    }
+
+    /**
+     * Write items into queue.
+     *
+     * @param ignite Ignite.
+     * @throws IgniteException If failed.
+     */
+    private static void writeToQueue(Ignite ignite) throws IgniteException {
+        final String queueName = queue.name();
+
+        // Write queue items on each node.
+        ignite.compute().run(new QueueClosure(queueName, true));
+
+        System.out.println("Queue size after writing [expected=" + ignite.cluster().nodes().size() * RETRIES +
+            ", actual=" + queue.size() + ']');
+
+        System.out.println("Iterate over queue.");
+
+        // Iterate over queue.
+        for (String item : queue)
+            System.out.println("Queue item: " + item);
+    }
+
+    /**
+     * Clear and remove queue.
+     *
+     * @throws IgniteException If execution failed.
+     */
+    private static void clearAndRemoveQueue() throws IgniteException {
+        System.out.println("Queue size before clearing: " + queue.size());
+
+        // Clear queue.
+        queue.clear();
+
+        System.out.println("Queue size after clearing: " + queue.size());
+
+        // Remove queue.
+        queue.close();
+
+        // Try to work with removed queue.
+        try {
+            queue.poll();
+        }
+        catch (IgniteException expected) {
+            System.out.println("Expected exception - " + expected.getMessage());
+        }
+    }
+
+    /**
+     * Closure to populate or poll the queue.
+     */
+    private static class QueueClosure implements IgniteRunnable {
+        /** Queue name. */
+        private final String queueName;
+
+        /** Flag indicating whether to put or poll. */
+        private final boolean put;
+
+        /**
+         * @param queueName Queue name.
+         * @param put Flag indicating whether to put or poll.
+         */
+        QueueClosure(String queueName, boolean put) {
+            this.queueName = queueName;
+            this.put = put;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            IgniteQueue<String> queue = Ignition.ignite().queue(queueName, 0, null);
+
+            if (put) {
+                UUID locId = Ignition.ignite().cluster().localNode().id();
+
+                for (int i = 0; i < RETRIES; i++) {
+                    String item = locId + "_" + Integer.toString(i);
+
+                    queue.put(item);
+
+                    System.out.println("Queue item has been added: " + item);
+                }
+            }
+            else {
+                // Take items from queue head.
+                for (int i = 0; i < RETRIES; i++)
+                    System.out.println("Queue item has been read from queue head: " + queue.take());
+
+                // Take items from queue head once again.
+                for (int i = 0; i < RETRIES; i++)
+                    System.out.println("Queue item has been read from queue head: " + queue.poll());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
new file mode 100644
index 0000000..7ebaaac
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
@@ -0,0 +1,186 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.examples.datagrid.*;
+import org.apache.ignite.lang.*;
+
+import java.util.*;
+
+/**
+ * Ignite cache distributed set example.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}.
+ * <p>
+ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-cache.xml} configuration.
+ */
+public class IgniteSetExample {
+    /** Cache name. */
+    private static final String CACHE_NAME = "partitioned_tx";
+
+    /** Set instance. */
+    private static IgniteSet<String> set;
+
+    /**
+     * 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-cache.xml")) {
+            System.out.println();
+            System.out.println(">>> Ignite set example started.");
+
+            // Make set name.
+            String setName = UUID.randomUUID().toString();
+
+            set = initializeSet(ignite, setName);
+
+            writeToSet(ignite);
+
+            clearAndRemoveSet();
+        }
+
+        System.out.println("Ignite set example finished.");
+    }
+
+    /**
+     * Initialize set.
+     *
+     * @param ignite Ignite.
+     * @param setName Name of set.
+     * @return Set.
+     * @throws IgniteException If execution failed.
+     */
+    private static IgniteSet<String> initializeSet(Ignite ignite, String setName) throws IgniteException {
+        IgniteCollectionConfiguration setCfg = new IgniteCollectionConfiguration();
+
+        setCfg.setCacheName(CACHE_NAME);
+
+        // Initialize new set.
+        IgniteSet<String> set = ignite.set(setName, setCfg);
+
+        // Initialize set items.
+        for (int i = 0; i < 10; i++)
+            set.add(Integer.toString(i));
+
+        System.out.println("Set size after initializing: " + set.size());
+
+        return set;
+    }
+
+    /**
+     * Write items into set.
+     *
+     * @param ignite Ignite.
+     * @throws IgniteException If failed.
+     */
+    private static void writeToSet(Ignite ignite) throws IgniteException {
+        final String setName = set.name();
+
+        // Write set items on each node.
+        ignite.compute().broadcast(new SetClosure(setName));
+
+        System.out.println("Set size after writing [expected=" + (10 + ignite.cluster().nodes().size() * 5) +
+            ", actual=" + set.size() + ']');
+
+        System.out.println("Iterate over set.");
+
+        // Iterate over set.
+        for (String item : set)
+            System.out.println("Set item: " + item);
+
+        // Set API usage examples.
+        if (!set.contains("0"))
+            throw new RuntimeException("Set should contain '0' among its elements.");
+
+        if (set.add("0"))
+            throw new RuntimeException("Set should not allow duplicates.");
+
+        if (!set.remove("0"))
+            throw new RuntimeException("Set should correctly remove elements.");
+
+        if (set.contains("0"))
+            throw new RuntimeException("Set should not contain '0' among its elements.");
+
+        if (!set.add("0"))
+            throw new RuntimeException("Set should correctly add new elements.");
+    }
+
+    /**
+     * Clear and remove set.
+     *
+     * @throws IgniteException If execution failed.
+     */
+    private static void clearAndRemoveSet() throws IgniteException {
+        System.out.println("Set size before clearing: " + set.size());
+
+        // Clear set.
+        set.clear();
+
+        System.out.println("Set size after clearing: " + set.size());
+
+        // Remove set.
+        set.close();
+
+        System.out.println("Set was removed: " + set.removed());
+
+        // Try to work with removed set.
+        try {
+            set.contains("1");
+        }
+        catch (IgniteException expected) {
+            System.out.println("Expected exception - " + expected.getMessage());
+        }
+    }
+
+    /**
+     * Closure to populate the set.
+     */
+    private static class SetClosure implements IgniteRunnable {
+        /** Set name. */
+        private final String setName;
+
+        /**
+         * @param setName Set name.
+         */
+        SetClosure(String setName) {
+            this.setName = setName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            IgniteSet<String> set = Ignition.ignite().set(setName, null);
+
+            UUID locId = Ignition.ignite().cluster().localNode().id();
+
+            for (int i = 0; i < 5; i++) {
+                String item = locId + "_" + Integer.toString(i);
+
+                set.add(item);
+
+                System.out.println("Set item has been added: " + item);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9200ef5e/examples/src/main/java/org/apache/ignite/examples/datastructures/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/package.html b/examples/src/main/java/org/apache/ignite/examples/datastructures/package.html
new file mode 100644
index 0000000..f9c708f
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/package.html
@@ -0,0 +1,23 @@
+<!--
+  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.
+  -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<body>
+    <!-- Package description. -->
+    Demonstrates using of blocking and non-blocking queues and atomic data structures.
+</body>
+</html>


Mime
View raw message