ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [12/50] [abbrv] incubator-ignite git commit: # IGNITE-441 Review.
Date Fri, 13 Mar 2015 01:48:15 GMT
# IGNITE-441 Review.


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

Branch: refs/heads/ignite-sql-tests
Commit: 532c58d6a6a3b86a861ed130d850b2e47d5a8ae3
Parents: cad3d1f
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Thu Mar 12 15:10:59 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Thu Mar 12 15:10:59 2015 +0700

----------------------------------------------------------------------
 .../datagrid/CachePopularNumbersExample.java    |  2 +-
 .../ScalarCachePopularNumbersExample.scala      | 41 ++++++++++++++++----
 2 files changed, 34 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532c58d6/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
index 0f71681..646ee89 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
@@ -141,7 +141,7 @@ public class CachePopularNumbersExample {
      * Increments value for key.
      */
     private static class IncrementingUpdater implements IgniteDataLoader.Updater<Integer,
Long> {
-        /** */
+        /** Process entries to increase value by entry key. */
         private static final EntryProcessor<Integer, Long, Void> INC = new EntryProcessor<Integer,
Long, Void>() {
             @Override public Void process(MutableEntry<Integer, Long> e, Object...
args) {
                 Long val = e.getValue();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/532c58d6/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCachePopularNumbersExample.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCachePopularNumbersExample.scala
b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCachePopularNumbersExample.scala
index 98d9637..80a3ce8 100644
--- a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCachePopularNumbersExample.scala
+++ b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCachePopularNumbersExample.scala
@@ -17,15 +17,19 @@
 
 package org.apache.ignite.scalar.examples
 
-import java.util.Timer
-
-import org.apache.ignite.IgniteException
 import org.apache.ignite.examples.datagrid.CacheNodeStartup
+import org.apache.ignite.internal.util.scala.impl
 import org.apache.ignite.scalar.scalar
 import org.apache.ignite.scalar.scalar._
+import org.apache.ignite.{IgniteCache, IgniteDataLoader, IgniteException}
+
+import javax.cache.processor.{EntryProcessor, MutableEntry}
+import java.util
+import java.util.Map.Entry
+import java.util.Timer
 
+import scala.collection.JavaConversions._
 import scala.util.Random
-import collection.JavaConversions._
 
 /**
  * Real time popular number counter.
@@ -46,11 +50,14 @@ object ScalarCachePopularNumbersExample extends App {
     /** Count of most popular numbers to retrieve from cluster. */
     private final val POPULAR_NUMBERS_CNT = 10
 
+    /** Random number generator. */
+    private final val RAND = new Random()
+
     /** Range within which to generate numbers. */
     private final val RANGE = 1000
 
     /** Count of total numbers to generate. */
-    private final val CNT = 100000
+    private final val CNT = 1000000
 
     scalar("examples/config/example-cache.xml") {
         // Clean up caches on all nodes before run.
@@ -62,7 +69,7 @@ object ScalarCachePopularNumbersExample extends App {
         val prj = ignite$.cluster().forCacheNodes(CACHE_NAME)
 
         if (prj.nodes().isEmpty)
-            println("Ignite does not have cache configured: " + CACHE_NAME);
+            println("Ignite does not have cache configured: " + CACHE_NAME)
         else {
             val popularNumbersQryTimer = new Timer("numbers-query-worker")
 
@@ -94,9 +101,9 @@ object ScalarCachePopularNumbersExample extends App {
         // Reduce parallel operations since we running the whole ignite cluster locally under
heavy load.
         val ldr = dataLoader$[Int, Long](CACHE_NAME, 2048)
 
-        // TODO IGNITE-44: restore invoke.
+        ldr.updater(new IncrementingUpdater())
 
-        (0 until CNT) foreach (_ => ldr.addData(Random.nextInt(RANGE), 1L))
+        (0 until CNT) foreach (_ => ldr.addData(RAND.nextInt(RANGE), 1L))
 
         ldr.close(false)
     }
@@ -115,4 +122,22 @@ object ScalarCachePopularNumbersExample extends App {
 
         println("------------------")
     }
+
+    /**
+     * Increments value for key.
+     */
+    private class IncrementingUpdater extends IgniteDataLoader.Updater[Int, Long] {
+        private[this] final val INC = new EntryProcessor[Int, Long, Object]() {
+            /** Process entries to increase value by entry key. */
+            override def process(e: MutableEntry[Int, Long], args: AnyRef*): Object = {
+                e.setValue(Option(e.getValue).map(_ + 1).getOrElse(1L))
+
+                null
+            }
+        }
+
+        @impl def update(cache: IgniteCache[Int, Long], entries: util.Collection[Entry[Int,
Long]]) {
+            entries.foreach(entry => cache.invoke(entry.getKey, INC))
+        }
+    }
 }


Mime
View raw message