ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [04/10] incubator-ignite git commit: ignite-454 predicates becomes lambda
Date Mon, 16 Mar 2015 14:13:29 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingExample.java b/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingExample.java
new file mode 100644
index 0000000..4770b6a
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingExample.java
@@ -0,0 +1,166 @@
+/*
+ * 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.examples8.messaging;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.examples8.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Example that demonstrates how to exchange messages between nodes. Use such
+ * functionality for cases when you need to communicate to other nodes outside
+ * of ignite task.
+ * <p>
+ * To run this example you must have at least one remote node started.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-compute.xml'}.
+ * <p>
+ * Alternatively you can run {@link org.apache.ignite.examples8.ComputeNodeStartup} in another JVM which will start node
+ * with {@code examples/config/example-compute.xml} configuration.
+ */
+public final class MessagingExample {
+    /** Number of messages. */
+    private static final int MESSAGES_NUM = 10;
+
+    /** Message topics. */
+    private enum TOPIC { ORDERED, UNORDERED }
+
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     * @throws IgniteException If example execution failed.
+     */
+    public static void main(String[] args) throws Exception {
+        try (Ignite ignite = Ignition.start("examples/config/example-compute.xml")) {
+            if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2)) {
+                System.out.println();
+                System.out.println(">>> Please start at least 2 cluster nodes to run example.");
+                System.out.println();
+
+                return;
+            }
+
+            System.out.println();
+            System.out.println(">>> Messaging example started.");
+
+            // Group for remote nodes.
+            ClusterGroup rmtGrp = ignite.cluster().forRemotes();
+
+            // Listen for messages from remote nodes to make sure that they received all the messages.
+            int msgCnt = rmtGrp.nodes().size() * MESSAGES_NUM;
+
+            CountDownLatch orderedLatch = new CountDownLatch(msgCnt);
+            CountDownLatch unorderedLatch = new CountDownLatch(msgCnt);
+
+            localListen(ignite.message(ignite.cluster().forLocal()), orderedLatch, unorderedLatch);
+
+            // Register listeners on all cluster nodes.
+            startListening(ignite, ignite.message(rmtGrp));
+
+            // Send unordered messages to all remote nodes.
+            for (int i = 0; i < MESSAGES_NUM; i++)
+                ignite.message(rmtGrp).send(TOPIC.UNORDERED, Integer.toString(i));
+
+            System.out.println(">>> Finished sending unordered messages.");
+
+            // Send ordered messages to all remote nodes.
+            for (int i = 0; i < MESSAGES_NUM; i++)
+                ignite.message(rmtGrp).sendOrdered(TOPIC.ORDERED, Integer.toString(i), 0);
+
+            System.out.println(">>> Finished sending ordered messages.");
+            System.out.println(">>> Check output on all nodes for message printouts.");
+            System.out.println(">>> Will wait for messages acknowledgements from all remote nodes.");
+
+            orderedLatch.await();
+            unorderedLatch.await();
+
+            System.out.println(">>> Messaging example finished.");
+        }
+    }
+
+    /**
+     * Start listening to messages on remote cluster nodes.
+     *
+     * @param ignite Ignite.
+     * @param imsg Ignite messaging.
+     * @throws IgniteException If failed.
+     */
+    private static void startListening(final Ignite ignite, IgniteMessaging imsg) throws IgniteException {
+        // Add ordered message listener.
+        imsg.remoteListen(TOPIC.ORDERED, (nodeId, msg) -> {
+            System.out.println("Received ordered message [msg=" + msg + ", fromNodeId=" + nodeId + ']');
+
+            try {
+                ignite.message(ignite.cluster().forNodeId(nodeId)).send(TOPIC.ORDERED, msg);
+            }
+            catch (IgniteException e) {
+                e.printStackTrace();
+            }
+
+            return true; // Return true to continue listening.
+        });
+
+        // Add unordered message listener.
+        imsg.remoteListen(TOPIC.UNORDERED, (nodeId, msg) -> {
+            System.out.println("Received unordered message [msg=" + msg + ", fromNodeId=" + nodeId + ']');
+
+            try {
+                ignite.message(ignite.cluster().forNodeId(nodeId)).send(TOPIC.UNORDERED, msg);
+            }
+            catch (IgniteException e) {
+                e.printStackTrace();
+            }
+
+            return true; // Return true to continue listening.
+        });
+    }
+
+    /**
+     * Listen for messages from remote nodes.
+     *
+     * @param imsg Ignite messaging.
+     * @param orderedLatch Latch for ordered messages acks.
+     * @param unorderedLatch Latch for unordered messages acks.
+     */
+    private static void localListen(
+        IgniteMessaging imsg,
+        final CountDownLatch orderedLatch,
+        final CountDownLatch unorderedLatch
+    ) {
+        imsg.localListen(TOPIC.ORDERED, (nodeId, msg) -> {
+            orderedLatch.countDown();
+
+            // Return true to continue listening, false to stop.
+            return orderedLatch.getCount() > 0;
+        });
+
+        imsg.localListen(TOPIC.UNORDERED, (nodeId, msg) -> {
+            unorderedLatch.countDown();
+
+            // Return true to continue listening, false to stop.
+            return unorderedLatch.getCount() > 0;
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongExample.java b/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongExample.java
new file mode 100644
index 0000000..84895b4
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongExample.java
@@ -0,0 +1,127 @@
+/*
+ * 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.examples8.messaging;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.examples8.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Demonstrates simple message exchange between local and remote nodes.
+ * <p>
+ * To run this example you must have at least one remote node started.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-compute.xml'}.
+ * <p>
+ * Alternatively you can run {@link org.apache.ignite.examples8.ComputeNodeStartup} in another JVM which will start node
+ * with {@code examples/config/example-compute.xml} configuration.
+ */
+public class MessagingPingPongExample {
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     * @throws Exception If example execution failed.
+     */
+    public static void main(String[] args) throws Exception {
+        // Game is played over the default ignite.
+        try (final Ignite ignite = Ignition.start("examples/config/example-compute.xml")) {
+            if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
+                return;
+
+            System.out.println();
+            System.out.println(">>> Messaging ping-pong example started.");
+
+            // Pick random remote node as a partner.
+            ClusterGroup nodeB = ignite.cluster().forRemotes().forRandom();
+
+            // Note that both nodeA and nodeB will always point to
+            // same nodes regardless of whether they were implicitly
+            // serialized and deserialized on another node as part of
+            // anonymous closure's state during its remote execution.
+
+            // Set up remote player.
+            ignite.message(nodeB).remoteListen(null, (nodeId, msg) -> {
+                    System.out.println("Received message [msg=" + msg + ", sender=" + nodeId + ']');
+
+                    try {
+                        if ("PING".equals(msg)) {
+                            ignite.message(ignite.cluster().forNodeId(nodeId)).send(null, "PONG");
+
+                            return true; // Continue listening.
+                        }
+
+                        return false; // Unsubscribe.
+                    }
+                    catch (IgniteException e) {
+                        throw new GridClosureException(e);
+                    }
+                }
+            );
+
+            int MAX_PLAYS = 10;
+
+            final CountDownLatch cnt = new CountDownLatch(MAX_PLAYS);
+
+            // Set up local player.
+            ignite.message().localListen(null, (nodeId, msg) -> {
+                    System.out.println("Received message [msg=" + msg + ", sender=" + nodeId + ']');
+
+                    try {
+                        if (cnt.getCount() == 1) {
+                            ignite.message(ignite.cluster().forNodeId(nodeId)).send(null, "STOP");
+
+                            cnt.countDown();
+
+                            return false; // Stop listening.
+                        }
+                        else if ("PONG".equals(msg))
+                            ignite.message(ignite.cluster().forNodeId(nodeId)).send(null, "PING");
+                        else
+                            throw new RuntimeException("Received unexpected message: " + msg);
+
+                        cnt.countDown();
+
+                        return true; // Continue listening.
+                    }
+                    catch (IgniteException e) {
+                        throw new GridClosureException(e);
+                    }
+                }
+            );
+
+            // Serve!
+            ignite.message(nodeB).send(null, "PING");
+
+            // Wait til the game is over.
+            try {
+                cnt.await();
+            }
+            catch (InterruptedException e) {
+                System.err.println("Hm... let us finish the game!\n" + e);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongListenActorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongListenActorExample.java b/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongListenActorExample.java
new file mode 100644
index 0000000..61a4dac
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/messaging/MessagingPingPongListenActorExample.java
@@ -0,0 +1,106 @@
+/*
+ * 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.examples8.messaging;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.examples8.*;
+import org.apache.ignite.messaging.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Demonstrates messaging with {@link org.apache.ignite.messaging.MessagingListenActor} convenience adapter.
+ * <p>
+ * To run this example you must have at least one remote node started.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-compute.xml'}.
+ * <p>
+ * Alternatively you can run {@link org.apache.ignite.examples8.ComputeNodeStartup} in another JVM which will start node
+ * with {@code examples/config/example-compute.xml} configuration.
+ */
+public class MessagingPingPongListenActorExample {
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     */
+    public static void main(String[] args) {
+        // Game is played over the default ignite.
+        try (Ignite ignite = Ignition.start("examples/config/example-compute.xml")) {
+            if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
+                return;
+
+            System.out.println();
+            System.out.println(">>> Messaging ping-pong listen actor example started.");
+
+            // Pick first remote node as a partner.
+            Collection<ClusterNode> rmtNodes = ignite.cluster().forRemotes().nodes();
+
+            ClusterGroup nodeB = ignite.cluster().forNode(rmtNodes.iterator().next());
+
+            // Note that both nodeA and nodeB will always point to
+            // same nodes regardless of whether they were implicitly
+            // serialized and deserialized on another node as part of
+            // anonymous closure's state during its remote execution.
+
+            // Set up remote player.
+            ignite.message(nodeB).remoteListen(null, new MessagingListenActor<String>() {
+                @Override public void receive(UUID nodeId, String rcvMsg) {
+                    System.out.println(rcvMsg);
+
+                    if ("PING".equals(rcvMsg))
+                        respond("PONG");
+                    else if ("STOP".equals(rcvMsg))
+                        stop();
+                }
+            });
+
+            int MAX_PLAYS = 10;
+
+            final CountDownLatch cnt = new CountDownLatch(MAX_PLAYS);
+
+            // Set up local player.
+            ignite.message().localListen(null, new MessagingListenActor<String>() {
+                @Override protected void receive(UUID nodeId, String rcvMsg) throws IgniteException {
+                    System.out.println(rcvMsg);
+
+                    if (cnt.getCount() == 1)
+                        stop("STOP");
+                    else if ("PONG".equals(rcvMsg))
+                        respond("PING");
+
+                    cnt.countDown();
+                }
+            });
+
+            // Serve!
+            ignite.message(nodeB).send(null, "PING");
+
+            // Wait til the game is over.
+            try {
+                cnt.await();
+            }
+            catch (InterruptedException e) {
+                System.err.println("Hm... let us finish the game!\n" + e);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/messaging/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/messaging/package.html b/examples/src/main/java8/org/apache/ignite/examples8/messaging/package.html
new file mode 100644
index 0000000..5739367
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/messaging/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. -->
+    Demonstrates how to exchange messages between nodes.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExample.java b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExample.java
new file mode 100644
index 0000000..cb392e8
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExample.java
@@ -0,0 +1,125 @@
+/*
+ * 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.examples8.misc.client.memcache;
+
+import net.spy.memcached.*;
+import org.apache.ignite.*;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+/**
+ * This example shows how to use Memcache client for manipulating Ignite cache.
+ * <p>
+ * Ignite implements Memcache binary protocol and it is available if
+ * REST is enabled on the node.
+ * Remote nodes should always be started using {@link org.apache.ignite.examples8.misc.client.memcache.MemcacheRestExampleNodeStartup}.
+ */
+public class MemcacheRestExample {
+    /** Hostname for client connection. */
+    private static final String host = "localhost";
+
+    /** Port number for client connection. */
+    private static final int port = 11211;
+
+    /**
+     * @param args Command line arguments.
+     * @throws Exception In case of error.
+     */
+    public static void main(String[] args) throws Exception {
+        MemcachedClient client = null;
+
+        try (Ignite ignite = Ignition.start(MemcacheRestExampleNodeStartup.configuration())) {
+            System.out.println();
+            System.out.println(">>> Memcache REST example started.");
+
+            IgniteCache<String, Object> cache = ignite.jcache(null);
+
+            client = startMemcachedClient(host, port);
+
+            // Put string value to cache using Memcache binary protocol.
+            if (client.add("strKey", 0, "strVal").get())
+                System.out.println(">>> Successfully put string value using Memcache client.");
+
+            // Check that string value is actually in cache using traditional
+            // Ignite API and Memcache binary protocol.
+            System.out.println(">>> Getting value for 'strKey' using Ignite cache API: " + cache.get("strKey"));
+            System.out.println(">>> Getting value for 'strKey' using Memcache client: " + client.get("strKey"));
+
+            // Remove string value from cache using Memcache binary protocol.
+            if (client.delete("strKey").get())
+                System.out.println(">>> Successfully removed string value using Memcache client.");
+
+            // Check that cache is empty.
+            System.out.println(">>> Current cache size: " + cache.size() + " (expected: 0).");
+
+            // Put integer value to cache using Memcache binary protocol.
+            if (client.add("intKey", 0, 100).get())
+                System.out.println(">>> Successfully put integer value using Memcache client.");
+
+            // Check that integer value is actually in cache using traditional
+            // Ignite API and Memcache binary protocol.
+            System.out.println(">>> Getting value for 'intKey' using Ignite cache API: " + cache.get("intKey"));
+            System.out.println(">>> Getting value for 'intKey' using Memcache client: " + client.get("intKey"));
+
+            // Remove string value from cache using Memcache binary protocol.
+            if (client.delete("intKey").get())
+                System.out.println(">>> Successfully removed integer value using Memcache client.");
+
+            // Check that cache is empty.
+            System.out.println(">>> Current cache size: " + cache.size() + " (expected: 0).");
+
+            // Create atomic long.
+            IgniteAtomicLong l = ignite.atomicLong("atomicLong", 10, true);
+
+            // Increment atomic long by 5 using Memcache client.
+            if (client.incr("atomicLong", 5, 0) == 15)
+                System.out.println(">>> Successfully incremented atomic long by 5.");
+
+            // Increment atomic long using Ignite API and check that value is correct.
+            System.out.println(">>> New atomic long value: " + l.incrementAndGet() + " (expected: 16).");
+
+            // Decrement atomic long by 3 using Memcache client.
+            if (client.decr("atomicLong", 3, 0) == 13)
+                System.out.println(">>> Successfully decremented atomic long by 3.");
+
+            // Decrement atomic long using Ignite API and check that value is correct.
+            System.out.println(">>> New atomic long value: " + l.decrementAndGet() + " (expected: 12).");
+        }
+        finally {
+            if (client != null)
+                client.shutdown();
+        }
+    }
+
+    /**
+     * Creates Memcache client that uses binary protocol and connects to Ignite.
+     *
+     * @param host Hostname.
+     * @param port Port number.
+     * @return Client.
+     * @throws java.io.IOException If connection failed.
+     */
+    private static MemcachedClient startMemcachedClient(String host, int port) throws IOException {
+        assert host != null;
+        assert port > 0;
+
+        return new MemcachedClient(new BinaryConnectionFactory(), Arrays.asList(new InetSocketAddress(host, port)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExampleNodeStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExampleNodeStartup.java b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExampleNodeStartup.java
new file mode 100644
index 0000000..5565826
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/MemcacheRestExampleNodeStartup.java
@@ -0,0 +1,99 @@
+/*
+ * 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.examples8.misc.client.memcache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.marshaller.optimized.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheRebalanceMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+import static org.apache.ignite.configuration.DeploymentMode.*;
+
+/**
+ * Starts up an empty node with cache configuration that contains default cache.
+ * <p>
+ * The difference is that running this class from IDE adds all example classes to classpath
+ * but running from command line doesn't.
+ */
+public class MemcacheRestExampleNodeStartup {
+    /**
+     * Start up an empty node with specified cache configuration.
+     *
+     * @param args Command line arguments, none required.
+     * @throws org.apache.ignite.IgniteException If example execution failed.
+     */
+    public static void main(String[] args) throws IgniteException {
+        Ignition.start(configuration());
+    }
+
+    /**
+     * Create Ignite configuration with IGFS and enabled IPC.
+     *
+     * @return Ignite configuration.
+     * @throws org.apache.ignite.IgniteException If configuration creation failed.
+     */
+    public static IgniteConfiguration configuration() throws IgniteException {
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        cfg.setLocalHost("127.0.0.1");
+        cfg.setDeploymentMode(SHARED);
+        cfg.setPeerClassLoadingEnabled(true);
+
+        cfg.setConnectorConfiguration(new ConnectorConfiguration());
+
+        OptimizedMarshaller marsh = new OptimizedMarshaller();
+
+        marsh.setRequireSerializable(false);
+
+        cfg.setMarshaller(marsh);
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setAtomicityMode(TRANSACTIONAL);
+        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+        cacheCfg.setRebalanceMode(SYNC);
+        cacheCfg.setAtomicityMode(TRANSACTIONAL);
+
+        CacheQueryConfiguration qryCfg = new CacheQueryConfiguration();
+
+        qryCfg.setIndexPrimitiveKey(true);
+        qryCfg.setIndexFixedTyping(false);
+
+        cacheCfg.setQueryConfiguration(qryCfg);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
+
+        ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
+
+        discoSpi.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/package.html b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/package.html
new file mode 100644
index 0000000..8c392cb
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/memcache/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. -->
+    Demonstrates Java Client usage with Memcache protocol.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/client/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/client/package.html b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/package.html
new file mode 100644
index 0000000..8108727
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/client/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. -->
+    Demonstrates Java Client usage.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/DeploymentExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/DeploymentExample.java b/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/DeploymentExample.java
new file mode 100644
index 0000000..6104d28
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/DeploymentExample.java
@@ -0,0 +1,128 @@
+/*
+ * 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.examples8.misc.deployment;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Demonstrates how to explicitly deploy a task. Note that
+ * it is very rare when you would need such functionality as tasks are
+ * auto-deployed on demand first time you execute them. So in most cases
+ * you would just apply any of the {@code Ignite.execute(...)} methods directly.
+ * However, sometimes a task is not in local class path, so you may not even
+ * know the code it will execute, but you still need to execute it. For example,
+ * you have two independent components in the system, and one loads the task
+ * classes from some external source and deploys it; then another component
+ * can execute it just knowing the name of the task.
+ * <p>
+ * Also note that for simplicity of the example, the task we execute is
+ * in system classpath, so even in this case the deployment step is unnecessary.
+ * <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 org.apache.ignite.examples8.ComputeNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-compute.xml} configuration.
+ */
+public final class DeploymentExample {
+    /** Name of the deployed task. */
+    static final String TASK_NAME = "ExampleTask";
+
+    /**
+     * 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-compute.xml")) {
+            System.out.println();
+            System.out.println(">>> Deployment example started.");
+
+            // This task will be deployed on local node and then peer-loaded
+            // onto remote nodes on demand. For this example this task is
+            // available on the classpath, however in real life that may not
+            // always be the case. In those cases you should use explicit
+            // 'IgniteCompute.localDeployTask(Class, ClassLoader) apply and
+            // then use 'IgniteCompute.execute(String, Object)' method
+            // passing your task name as first parameter.
+            ignite.compute().localDeployTask(ExampleTask.class, ExampleTask.class.getClassLoader());
+
+            for (Map.Entry<String, Class<? extends ComputeTask<?, ?>>> e : ignite.compute().localTasks().entrySet())
+                System.out.println(">>> Found locally deployed task [alias=" + e.getKey() + ", taskCls=" + e.getValue());
+
+            // Execute the task passing its name as a parameter. The system will find
+            // the deployed task by its name and execute it.
+            ignite.compute().execute(TASK_NAME, null);
+
+            // Execute the task passing class name as a parameter. The system will find
+            // the deployed task by its class name and execute it.
+            // g.compute().execute(ExampleTask.class.getName(), null).get();
+
+            // Undeploy task
+            ignite.compute().undeployTask(TASK_NAME);
+
+            System.out.println();
+            System.out.println(">>> Finished executing Ignite Direct Deployment Example.");
+            System.out.println(">>> Check participating nodes output.");
+        }
+    }
+
+    /**
+     * Example task used to demonstrate direct task deployment through API.
+     * For this example this task as available on the classpath, however
+     * in real life that may not always be the case. In those cases
+     * you should use explicit {@link org.apache.ignite.IgniteCompute#localDeployTask(Class, ClassLoader)} apply and
+     * then use {@link org.apache.ignite.IgniteCompute#execute(String, Object)}
+     * method passing your task name as first parameter.
+     * <p>
+     * Note that this task specifies explicit task name. Task name is optional
+     * and is added here for demonstration purpose. If not provided, it will
+     * default to the task class name.
+     */
+    @ComputeTaskName(TASK_NAME)
+    public static class ExampleTask extends ComputeTaskSplitAdapter<String, Object> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int clusterSize, String arg) {
+            Collection<ComputeJob> jobs = new ArrayList<>(clusterSize);
+
+            for (int i = 0; i < clusterSize; i++) {
+                jobs.add(new ComputeJobAdapter() {
+                    @Nullable @Override public Serializable execute() {
+                        System.out.println(">>> Executing deployment example job on this node.");
+
+                        // This job does not return any result.
+                        return null;
+                    }
+                });
+            }
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/package.html b/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/package.html
new file mode 100644
index 0000000..37ec5f4
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/deployment/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. -->
+    Deployment examples for direct deployments.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/LifecycleExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/LifecycleExample.java b/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/LifecycleExample.java
new file mode 100644
index 0000000..28ab498
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/LifecycleExample.java
@@ -0,0 +1,92 @@
+/*
+ * 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.examples8.misc.lifecycle;
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.lifecycle.*;
+import org.apache.ignite.resources.*;
+
+import static org.apache.ignite.lifecycle.LifecycleEventType.*;
+
+/**
+ * This example shows how to provide your own {@link org.apache.ignite.lifecycle.LifecycleBean} implementation
+ * to be able to hook into Ignite lifecycle. The {@link LifecycleExampleBean} bean
+ * will output occurred lifecycle events to the console.
+ * <p>
+ * This example does not require remote nodes to be started.
+ */
+public final class LifecycleExample {
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     * @throws org.apache.ignite.IgniteException If example execution failed.
+     */
+    public static void main(String[] args) throws IgniteException {
+        System.out.println();
+        System.out.println(">>> Lifecycle example started.");
+
+        // Create new configuration.
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        LifecycleExampleBean bean = new LifecycleExampleBean();
+
+        // Provide lifecycle bean to configuration.
+        cfg.setLifecycleBeans(bean);
+
+        try (Ignite ignite  = Ignition.start(cfg)) {
+            // Make sure that lifecycle bean was notified about ignite startup.
+            assert bean.isStarted();
+        }
+
+        // Make sure that lifecycle bean was notified about ignite stop.
+        assert !bean.isStarted();
+    }
+
+    /**
+     * Simple {@link org.apache.ignite.lifecycle.LifecycleBean} implementation that outputs event type when it is occurred.
+     */
+    public static class LifecycleExampleBean implements LifecycleBean {
+        /** Auto-inject ignite instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** Started flag. */
+        private boolean isStarted;
+
+        /** {@inheritDoc} */
+        @Override public void onLifecycleEvent(LifecycleEventType evt) {
+            System.out.println();
+            System.out.println(">>> Lifecycle event occurred: " + evt);
+            System.out.println(">>> Ignite name: " + ignite.name());
+
+            if (evt == AFTER_NODE_START)
+                isStarted = true;
+            else if (evt == AFTER_NODE_STOP)
+                isStarted = false;
+        }
+
+        /**
+         * @return {@code True} if ignite has been started.
+         */
+        public boolean isStarted() {
+            return isStarted;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/package.html b/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/package.html
new file mode 100644
index 0000000..3fc32be
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/lifecycle/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. -->
+    Demonstrates how to write and use lifecycle beans.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/package.html b/examples/src/main/java8/org/apache/ignite/examples8/misc/package.html
new file mode 100644
index 0000000..55d7ffc
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/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. -->
+    Contains examples taht are common across all editions.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/SpringBeanExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/SpringBeanExample.java b/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/SpringBeanExample.java
new file mode 100644
index 0000000..dfdde0b
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/SpringBeanExample.java
@@ -0,0 +1,85 @@
+/*
+ * 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.examples8.misc.springbean;
+
+import org.apache.ignite.*;
+import org.springframework.context.support.*;
+
+import java.util.concurrent.*;
+
+/**
+ * Demonstrates a simple use of Ignite configured with Spring.
+ * <p>
+ * String "Hello World." is printed out by Callable passed into
+ * the executor service provided by Ignite. This statement could be printed
+ * out on any node in the cluster.
+ * <p>
+ * The major point of this example is to show ignite injection by Spring
+ * framework. Ignite bean is described in {@code spring-bean.xml} file and instantiated
+ * by Spring context. Once application completed its execution Spring will
+ * apply ignite bean destructor and stop the ignite.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-compute.xml'}.
+ * <p>
+ * Alternatively you can run {@link org.apache.ignite.examples8.ComputeNodeStartup} in another JVM which will start node
+ * with {@code examples/config/example-compute.xml} configuration.
+ */
+public final class SpringBeanExample {
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     * @throws Exception If example execution failed.
+     */
+    public static void main(String[] args) throws Exception {
+        System.out.println();
+        System.out.println(">>> Spring bean example started.");
+
+        // Initialize Spring factory.
+        ClassPathXmlApplicationContext ctx =
+            new ClassPathXmlApplicationContext("org/apache/ignite/examples/misc/springbean/spring-bean.xml");
+
+        try {
+            // Get ignite from Spring (note that local cluster node is already started).
+            Ignite ignite = (Ignite)ctx.getBean("mySpringBean");
+
+            // Execute any method on the retrieved ignite instance.
+            ExecutorService exec = ignite.executorService();
+
+            Future<String> res = exec.submit(() -> {
+                System.out.println("Hello world!");
+
+                return null;
+            });
+
+            // Wait for callable completion.
+            res.get();
+
+            System.out.println(">>>");
+            System.out.println(">>> Finished executing Ignite \"Spring bean\" example.");
+            System.out.println(">>> You should see printed out of 'Hello world' on one of the nodes.");
+            System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
+            System.out.println(">>>");
+        }
+        finally {
+            // Stop local cluster node.
+            ctx.destroy();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/package.html b/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/package.html
new file mode 100644
index 0000000..dfef333
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/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. -->
+    HelloWorld example that accesses ignite started directly from Spring bean.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/spring-bean.xml
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/spring-bean.xml b/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/spring-bean.xml
new file mode 100644
index 0000000..393b9cf
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/misc/springbean/spring-bean.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!--
+    Command line (default) ignite configuration.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+    <description>Main Spring file for ignite configuration.</description>
+
+    <!-- Example of bean definition with given configuration. -->
+    <bean id="mySpringBean" class="org.apache.ignite.IgniteSpringBean">
+        <property name="configuration">
+            <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+                <!-- Set to true to enable ignite-aware class loading for examples, default is false. -->
+                <property name="peerClassLoadingEnabled" value="true"/>
+
+                <property name="marshaller">
+                    <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+                        <!-- Set to false to allow non-serializable objects in examples, default is true. -->
+                        <property name="requireSerializable" value="false"/>
+                    </bean>
+                </property>
+
+                <!-- Enable task execution events for examples. -->
+                <property name="includeEventTypes">
+                    <util:constant static-field="org.apache.ignite.events.EventType.EVTS_TASK_EXECUTION"/>
+                </property>
+
+                <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+                <property name="discoverySpi">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                        <property name="ipFinder">
+                            <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
+                            <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
+                            <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
+                                <property name="addresses">
+                                    <list>
+                                        <!-- In distributed environment, replace with actual host IP address. -->
+                                        <value>127.0.0.1:47500..47509</value>
+                                    </list>
+                                </property>
+                            </bean>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/package.html
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/package.html b/examples/src/main/java8/org/apache/ignite/examples8/package.html
new file mode 100644
index 0000000..46e16d7
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/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. -->
+    Basic examples for ignite functionality.
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/ServicesExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/ServicesExample.java b/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/ServicesExample.java
new file mode 100644
index 0000000..f39f4a7
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/ServicesExample.java
@@ -0,0 +1,167 @@
+/*
+ * 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.examples8.servicegrid;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.examples8.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
+
+import java.util.*;
+
+/**
+ * Example that demonstrates how to deploy distributed services in Ignite.
+ * Distributed services are especially useful when deploying singletons on the ignite,
+ * be that cluster-singleton, or per-node-singleton, etc...
+ * <p>
+ * To start remote nodes, you must run {@link org.apache.ignite.examples8.ComputeNodeStartup} in another JVM
+ * which will start node with {@code examples/config/example-compute.xml} configuration.
+ * <p>
+ * NOTE:<br/>
+ * Starting {@code ignite.sh} directly will not work, as distributed services
+ * cannot be peer-deployed and classes must be on the classpath for every node.
+ */
+public class ServicesExample {
+    /**
+     * 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-compute.xml")) {
+            ClusterGroup rmts = ignite.cluster().forRemotes();
+
+            if (rmts.nodes().isEmpty()) {
+                System.err.println(">>>");
+                System.err.println(">>> Must start at least one remote node using " +
+                    ComputeNodeStartup.class.getSimpleName() + '.');
+                System.err.println(">>>");
+
+                return;
+            }
+
+            IgniteServices svcs = ignite.services(rmts);
+
+            try {
+                // Deploy cluster singleton.
+                svcs.deployClusterSingleton("myClusterSingletonService", new SimpleMapServiceImpl());
+
+                // Deploy node singleton.
+                svcs.deployNodeSingleton("myNodeSingletonService", new SimpleMapServiceImpl());
+
+                // Deploy 2 instances, regardless of number nodes.
+                svcs.deployMultiple("myMultiService", new SimpleMapServiceImpl(), 2 /*total number*/, 0 /*0 for unlimited*/);
+
+                // Example for using a service proxy
+                // to access a remotely deployed service.
+                serviceProxyExample(ignite);
+
+                // Example for auto-injecting service proxy
+                // into remote closure execution.
+                serviceInjectionExample(ignite);
+            }
+            finally {
+                // Undeploy all services.
+                ignite.services().cancelAll();
+            }
+        }
+    }
+
+    /**
+     * Simple example to demonstrate service proxy invocation of a remotely deployed service.
+     *
+     * @param ignite Ignite instance.
+     * @throws Exception If failed.
+     */
+    private static void serviceProxyExample(Ignite ignite) throws Exception {
+        System.out.println(">>>");
+        System.out.println(">>> Starting service proxy example.");
+        System.out.println(">>>");
+
+        // Get a sticky proxy for node-singleton map service.
+        SimpleMapService<Integer, String> mapSvc = ignite.services().serviceProxy("myNodeSingletonService", SimpleMapService.class, true);
+
+        int cnt = 10;
+
+        // Each service invocation will go over a proxy to some remote node.
+        // Since service proxy is sticky, we will always be contacting the same remote node.
+        for (int i = 0; i < cnt; i++)
+            mapSvc.put(i, Integer.toString(i));
+
+        // Get size from remotely deployed service instance.
+        int mapSize = mapSvc.size();
+
+        System.out.println("Map service size: " + mapSize);
+
+        if (mapSize != cnt)
+            throw new Exception("Invalid map size [expected=" + cnt + ", actual=" + mapSize + ']');
+    }
+
+    /**
+     * Simple example to demonstrate how to inject service proxy into distributed closures.
+     *
+     * @param ignite Ignite instance.
+     * @throws Exception If failed.
+     */
+    private static void serviceInjectionExample(Ignite ignite) throws Exception {
+        System.out.println(">>>");
+        System.out.println(">>> Starting service injection example.");
+        System.out.println(">>>");
+
+        // Get a sticky proxy for cluster-singleton map service.
+        SimpleMapService<Integer, String> mapSvc = ignite.services().serviceProxy("myClusterSingletonService", SimpleMapService.class, true);
+
+        int cnt = 10;
+
+        // Each service invocation will go over a proxy to the remote cluster-singleton instance.
+        for (int i = 0; i < cnt; i++)
+            mapSvc.put(i, Integer.toString(i));
+
+        // Broadcast closure to every node.
+        final Collection<Integer> mapSizes = ignite.compute().broadcast(new SimpleClosure());
+
+        System.out.println("Closure execution result: " + mapSizes);
+
+        // Since we invoked the same cluster-singleton service instance
+        // from all the remote closure executions, they should all return
+        // the same size equal to 'cnt' value.
+        for (int mapSize : mapSizes)
+            if (mapSize != cnt)
+                throw new Exception("Invalid map size [expected=" + cnt + ", actual=" + mapSize + ']');
+    }
+
+    /**
+     * Simple closure to demonstrate auto-injection of the service proxy.
+     */
+    private static class SimpleClosure implements IgniteCallable<Integer> {
+        // Auto-inject service proxy.
+        @ServiceResource(serviceName = "myClusterSingletonService", proxyInterface = SimpleMapService.class)
+        private transient SimpleMapService mapSvc;
+
+        /** {@inheritDoc} */
+        @Override public Integer call() throws Exception {
+            int mapSize = mapSvc.size();
+
+            System.out.println("Executing closure [mapSize=" + mapSize + ']');
+
+            return mapSize;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapService.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapService.java b/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapService.java
new file mode 100644
index 0000000..73db411
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapService.java
@@ -0,0 +1,49 @@
+/*
+ * 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.examples8.servicegrid;
+
+/**
+ * Simple map service.
+ */
+public interface SimpleMapService<K, V> {
+    /**
+     * Puts key-value pair into map.
+     *
+     * @param key Key.
+     * @param val Value.
+     */
+    void put(K key, V val);
+
+    /**
+     * Gets value based on key.
+     *
+     * @param key Key.
+     * @return Value.
+     */
+    V get(K key);
+
+    /**
+     * Clears map.
+     */
+    void clear();
+
+    /**
+     * @return Map size.
+     */
+    int size();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28720c44/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapServiceImpl.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapServiceImpl.java b/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapServiceImpl.java
new file mode 100644
index 0000000..2aee6f1
--- /dev/null
+++ b/examples/src/main/java8/org/apache/ignite/examples8/servicegrid/SimpleMapServiceImpl.java
@@ -0,0 +1,71 @@
+/*
+ * 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.examples8.servicegrid;
+
+import org.apache.ignite.services.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Simple service which loops infinitely and prints out a counter.
+ */
+public class SimpleMapServiceImpl<K, V> implements Service, SimpleMapService<K, V> {
+    /** Serial version UID. */
+    private static final long serialVersionUID = 0L;
+
+    /** Underlying cache map. */
+    private Map<K, V> map;
+
+    /** {@inheritDoc} */
+    @Override public void put(K key, V val) {
+        map.put(key, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public V get(K key) {
+        return map.get(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() {
+        map.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return map.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void cancel(ServiceContext ctx) {
+        System.out.println("Service was cancelled: " + ctx.name());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void init(ServiceContext ctx) throws Exception {
+        System.out.println("Service was initialized: " + ctx.name());
+
+        map = new ConcurrentHashMap<>();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void execute(ServiceContext ctx) throws Exception {
+        System.out.println("Executing distributed service: " + ctx.name());
+    }
+}


Mime
View raw message