ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [01/43] incubator-ignite git commit: #IGNITE-106: Change cache Api in examples.
Date Wed, 04 Feb 2015 09:35:47 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/sprint-1 20d0d3f7f -> d23eb01e8


#IGNITE-106: Change cache Api in examples.


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

Branch: refs/heads/sprint-1
Commit: 72b94af4b78f3cbfadc05e069a235f4c2497d026
Parents: 88514f7
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Feb 2 13:52:00 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Feb 2 13:52:00 2015 +0300

----------------------------------------------------------------------
 .../examples/datagrid/CacheAffinityExample.java | 14 +++---
 .../examples/datagrid/CacheApiExample.java      | 53 +-------------------
 .../datagrid/CacheDataLoaderExample.java        |  2 +-
 .../examples/datagrid/CacheEventsExample.java   |  8 +--
 .../datagrid/CachePopularNumbersExample.java    |  2 +-
 .../examples/datagrid/CachePutGetExample.java   |  8 +--
 .../examples/datagrid/CacheQueryExample.java    |  2 +-
 .../datagrid/CacheTransactionExample.java       | 18 +++----
 .../starschema/CacheStarSchemaExample.java      |  6 +--
 .../datagrid/store/CacheStoreExample.java       | 10 ++--
 .../store/CacheStoreLoadDataExample.java        |  4 +-
 .../store/dummy/CacheDummyPersonStore.java      |  5 +-
 12 files changed, 38 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheAffinityExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheAffinityExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheAffinityExample.java
index 8d6b275..aa99368 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheAffinityExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheAffinityExample.java
@@ -53,13 +53,13 @@ public final class CacheAffinityExample {
             System.out.println();
             System.out.println(">>> Cache affinity example started.");
 
-            GridCache<Integer, String> cache = g.cache(CACHE_NAME);
+            IgniteCache<Integer, String> cache = g.jcache(CACHE_NAME);
 
             // Clean up caches on all nodes before run.
-            cache.globalClearAll(0);
+            cache.clear();
 
             for (int i = 0; i < KEY_CNT; i++)
-                cache.putx(i, Integer.toString(i));
+                cache.put(i, Integer.toString(i));
 
             // Co-locates jobs with data using GridCompute.affinityRun(...) method.
             visitUsingAffinityRun();
@@ -78,7 +78,7 @@ public final class CacheAffinityExample {
     private static void visitUsingAffinityRun() throws IgniteCheckedException {
         Ignite g = Ignition.ignite();
 
-        final GridCache<Integer, String> cache = g.cache(CACHE_NAME);
+        final IgniteCache<Integer, String> cache = g.jcache(CACHE_NAME);
 
         for (int i = 0; i < KEY_CNT; i++) {
             final int key = i;
@@ -90,7 +90,7 @@ public final class CacheAffinityExample {
                 @Override public void run() {
                     // Peek is a local memory lookup, however, value should never be 'null'
                     // as we are co-located with node that has a given key.
-                    System.out.println("Co-located using affinityRun [key= " + key + ", value="
+ cache.peek(key) + ']');
+                    System.out.println("Co-located using affinityRun [key= " + key + ", value="
+ cache.localPeek(key) + ']');
                 }
             });
         }
@@ -123,13 +123,13 @@ public final class CacheAffinityExample {
                 // Bring computations to the nodes where the data resides (i.e. collocation).
                 g.compute(g.cluster().forNode(node)).run(new IgniteRunnable() {
                     @Override public void run() {
-                        GridCache<Integer, String> cache = g.cache(CACHE_NAME);
+                        IgniteCache<Integer, String> cache = g.jcache(CACHE_NAME);
 
                         // Peek is a local memory lookup, however, value should never be
'null'
                         // as we are co-located with node that has a given key.
                         for (Integer key : mappedKeys)
                             System.out.println("Co-located using mapKeysToNodes [key= " +
key +
-                                ", value=" + cache.peek(key) + ']');
+                                ", value=" + cache.localPeek(key) + ']');
                     }
                 });
             }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheApiExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheApiExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheApiExample.java
index 26057c5..269d841 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheApiExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheApiExample.java
@@ -49,13 +49,10 @@ public class CacheApiExample {
             System.out.println(">>> Cache API example started.");
 
             // Clean up caches on all nodes before run.
-            g.cache(CACHE_NAME).globalClearAll(0);
+            g.jcache(CACHE_NAME).clear();
 
             // Demonstrate atomic map operations.
             atomicMapOperations();
-
-            // Demonstrate various ways to iterate over locally cached values.
-            localIterators();
         }
     }
 
@@ -119,52 +116,4 @@ public class CacheApiExample {
         b2 = cache.replace(7, "7", "777");
         assert b1 & !b2;
     }
-
-    /**
-     * Demonstrates various iteration methods over locally cached values.
-     */
-    private static void localIterators() {
-        System.out.println();
-        System.out.println(">>> Local iterator examples.");
-
-        GridCache<Integer, String> cache = Ignition.ignite().cache(CACHE_NAME);
-
-        // Iterate over whole cache.
-        for (CacheEntry<Integer, String> e : cache)
-            System.out.println("Basic cache iteration [key=" + e.getKey() + ", val=" + e.getValue()
+ ']');
-
-        // Iterate over cache projection for all keys below 5.
-        CacheProjection<Integer, String> keysBelow5 = cache.projection(
-            new IgnitePredicate<CacheEntry<Integer, String>>() {
-                @Override public boolean apply(CacheEntry<Integer, String> e) {
-                    return e.getKey() < 5;
-                }
-            }
-        );
-
-        for (CacheEntry<Integer, String> e : keysBelow5)
-            System.out.println("Cache projection iteration [key=" + e.getKey() + ", val="
+ e.getValue() + ']');
-
-        // Iterate over each element using 'forEach' construct.
-        cache.forEach(new IgniteInClosure<CacheEntry<Integer, String>>() {
-            @Override public void apply(CacheEntry<Integer, String> e) {
-                System.out.println("forEach iteration [key=" + e.getKey() + ", val=" + e.getValue()
+ ']');
-            }
-        });
-
-        // Search cache for element with value "1" using 'forAll' construct.
-        cache.forAll(new IgnitePredicate<CacheEntry<Integer, String>>() {
-            @Override public boolean apply(CacheEntry<Integer, String> e) {
-                String v = e.peek();
-
-                if ("1".equals(v)) {
-                    System.out.println("Found cache value '1' using forEach iteration.");
-
-                    return false; // Stop iteration.
-                }
-
-                return true; // Continue iteration.
-            }
-        });
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheDataLoaderExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheDataLoaderExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheDataLoaderExample.java
index b13b625..0fdd3db 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheDataLoaderExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheDataLoaderExample.java
@@ -56,7 +56,7 @@ public class CacheDataLoaderExample {
             System.out.println(">>> Cache data loader example started.");
 
             // Clean up caches on all nodes before run.
-            g.cache(CACHE_NAME).globalClearAll(0);
+            g.jcache(CACHE_NAME).clear();
 
             System.out.println();
             System.out.println(">>> Cache clear finished.");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheEventsExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheEventsExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheEventsExample.java
index 80b4217..dd7ab89 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheEventsExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheEventsExample.java
@@ -51,10 +51,10 @@ public class CacheEventsExample {
             System.out.println();
             System.out.println(">>> Cache events example started.");
 
-            final GridCache<Integer, String> cache = g.cache(CACHE_NAME);
+            final IgniteCache<Integer, String> cache = g.jcache(CACHE_NAME);
 
             // Clean up caches on all nodes before run.
-            cache.globalClearAll(0);
+            cache.clear();
 
             // This optional local callback is called for each event notification
             // that passed remote predicate listener.
@@ -75,7 +75,7 @@ public class CacheEventsExample {
 
                     int key = evt.key();
 
-                    return key >= 10 && cache.affinity().isPrimary(g.cluster().localNode(),
key);
+                    return key >= 10 && g.affinity(CACHE_NAME).isPrimary(g.cluster().localNode(),
key);
                 }
             };
 
@@ -86,7 +86,7 @@ public class CacheEventsExample {
 
             // Generate cache events.
             for (int i = 0; i < 20; i++)
-                cache.putx(i, Integer.toString(i));
+                cache.put(i, Integer.toString(i));
 
             // Wait for a while while callback is notified about remaining puts.
             Thread.sleep(2000);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/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 1617662..51cc3b7 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
@@ -65,7 +65,7 @@ public class CachePopularNumbersExample {
             System.out.println(">>> Cache popular numbers example started.");
 
             // Clean up caches on all nodes before run.
-            g.cache(CACHE_NAME).globalClearAll(0);
+            g.jcache(CACHE_NAME).clear();
 
             ClusterGroup prj = g.cluster().forCache(CACHE_NAME);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePutGetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePutGetExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePutGetExample.java
index 9df8fe5..231abbb 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePutGetExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePutGetExample.java
@@ -44,7 +44,7 @@ public class CachePutGetExample {
     public static void main(String[] args) throws Exception {
         try (Ignite g = Ignition.start("examples/config/example-cache.xml")) {
             // Clean up caches on all nodes before run.
-            g.cache(CACHE_NAME).globalClearAll(0);
+            g.jcache(CACHE_NAME).clear();
 
             // Individual puts and gets.
             putGet();
@@ -65,13 +65,13 @@ public class CachePutGetExample {
 
         Ignite g = Ignition.ignite();
 
-        final GridCache<Integer, String> cache = g.cache(CACHE_NAME);
+        final IgniteCache<Integer, String> cache = g.jcache(CACHE_NAME);
 
         final int keyCnt = 20;
 
         // Store keys in cache.
         for (int i = 0; i < keyCnt; i++)
-            cache.putx(i, Integer.toString(i));
+            cache.put(i, Integer.toString(i));
 
         System.out.println(">>> Stored values in cache.");
 
@@ -90,7 +90,7 @@ public class CachePutGetExample {
 
         Ignite g = Ignition.ignite();
 
-        final GridCache<Integer, String> cache = g.cache(CACHE_NAME);
+        final IgniteCache<Integer, String> cache = g.jcache(CACHE_NAME);
 
         final int keyCnt = 20;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
index a0205d6..3237348 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
@@ -80,7 +80,7 @@ public class CacheQueryExample {
             System.out.println(">>> Cache query example started.");
 
             // Clean up caches on all nodes before run.
-            g.cache(CACHE_NAME).globalClearAll(0);
+            g.jcache(CACHE_NAME).clear();
 
             // Populate cache.
             initialize();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheTransactionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheTransactionExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheTransactionExample.java
index 1e1793f..ee52b79 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheTransactionExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheTransactionExample.java
@@ -52,13 +52,13 @@ public class CacheTransactionExample {
             System.out.println(">>> Cache transaction example started.");
 
             // Clean up caches on all nodes before run.
-            g.cache(CACHE_NAME).globalClearAll(0);
+            g.jcache(CACHE_NAME).clear();
 
-            GridCache<Integer, Account> cache = g.cache(CACHE_NAME);
+            IgniteCache<Integer, Account> cache = g.jcache(CACHE_NAME);
 
             // Initialize.
-            cache.putx(1, new Account(1, 100));
-            cache.putx(2, new Account(1, 200));
+            cache.put(1, new Account(1, 100));
+            cache.put(2, new Account(1, 200));
 
             System.out.println();
             System.out.println(">>> Accounts before deposit: ");
@@ -87,18 +87,18 @@ public class CacheTransactionExample {
      */
     private static void deposit(int acctId, double amount) throws IgniteCheckedException
{
         // Clone every object we get from cache, so we can freely update it.
-        CacheProjection<Integer, Account> cache = Ignition.ignite().<Integer, Account>cache(CACHE_NAME).flagsOn(CLONE);
+        IgniteCache<Integer, Account> cache = Ignition.ignite().jcache(CACHE_NAME);
 
-        try (IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) {
-            Account acct = cache.get(acctId);
+        try (IgniteTx tx = Ignition.ignite().transactions().txStart(PESSIMISTIC, REPEATABLE_READ))
{
+            assert cache.get(acctId) != null;
 
-            assert acct != null;
+            Account acct = new Account(cache.get(acctId).id, cache.get(acctId).balance);
 
             // Deposit into account.
             acct.update(amount);
 
             // Store updated account in cache.
-            cache.putx(acctId, acct);
+            cache.put(acctId, acct);
 
             tx.commit();
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
index e5a79d4..b1413dc 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
@@ -70,8 +70,8 @@ public class CacheStarSchemaExample {
         System.out.println(">>> Cache star schema example started.");
 
         // Clean up caches on all nodes before run.
-        g.cache(PARTITIONED_CACHE_NAME).globalClearAll(0);
-        g.cache(REPLICATED_CACHE_NAME).globalClearAll(0);
+        g.jcache(PARTITIONED_CACHE_NAME).clear();
+        g.jcache(REPLICATED_CACHE_NAME).clear();
 
         try {
             populateDimensions();
@@ -92,7 +92,7 @@ public class CacheStarSchemaExample {
      * @throws IgniteCheckedException If failed.
      */
     private static void populateDimensions() throws IgniteCheckedException {
-        GridCache<Integer, Object> cache = Ignition.ignite().cache(REPLICATED_CACHE_NAME);
+        IgniteCache<Integer, Object> cache = Ignition.ignite().jcache(REPLICATED_CACHE_NAME);
 
         DimStore store1 = new DimStore(idGen++, "Store1", "12345", "321 Chilly Dr, NY");
         DimStore store2 = new DimStore(idGen++, "Store2", "54321", "123 Windy Dr, San Francisco");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreExample.java
index 9eb6d43..06b2ab8 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreExample.java
@@ -49,19 +49,17 @@ public class CacheStoreExample {
             System.out.println();
             System.out.println(">>> Cache store example started.");
 
-            GridCache<Long, Person> cache = g.cache(null);
+            IgniteCache<Long, Person> cache = g.jcache(null);
 
             // Clean up caches on all nodes before run.
-            cache.globalClearAll(0);
+            cache.clear();
 
-            try (IgniteTx tx = cache.txStart()) {
+            try (IgniteTx tx = g.transactions().txStart()) {
                 Person val = cache.get(id);
 
                 System.out.println("Read value: " + val);
 
-                val = cache.put(id, person(id, "Isaac", "Newton"));
-
-                System.out.println("Overwrote old value: " + val);
+                cache.put(id, person(id, "Isaac", "Newton"));
 
                 val = cache.get(id);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreLoadDataExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreLoadDataExample.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreLoadDataExample.java
index 7fded3c..907d789 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreLoadDataExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/CacheStoreLoadDataExample.java
@@ -51,10 +51,10 @@ public class CacheStoreLoadDataExample {
             System.out.println();
             System.out.println(">>> Cache store load data example started.");
 
-            final GridCache<String, Integer> cache = g.cache(null);
+            final IgniteCache<String, Integer> cache = g.jcache(null);
 
             // Clean up caches on all nodes before run.
-            cache.globalClearAll(0);
+            cache.clear();
 
             long start = System.currentTimeMillis();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/72b94af4/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
index ed47df0..f5c54f5 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.examples.datagrid.store.dummy;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.GridCache;
 import org.apache.ignite.cache.store.*;
 import org.apache.ignite.examples.datagrid.store.*;
 import org.apache.ignite.lang.*;
@@ -80,8 +79,6 @@ public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person>
{
 
         System.out.println(">>> Store loadCache for entry count: " + cnt);
 
-        GridCache<Long, Person> cache = ignite.cache(cacheName);
-
         for (int i = 0; i < cnt; i++) {
             // Generate dummy person on the fly.
             Person p = new Person(i, "first-" + i, "last-" + 1);
@@ -90,7 +87,7 @@ public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person>
{
             // but we check if local node is primary or backup anyway just to demonstrate
that we can.
             // Ideally, partition ID of a key would be stored  in the database and only keys
             // for partitions that belong on this node would be loaded from database.
-            if (cache.affinity().isPrimaryOrBackup(ignite.cluster().localNode(), p.getId()))
{
+            if (ignite.affinity(cacheName).isPrimaryOrBackup(ignite.cluster().localNode(),
p.getId())) {
                 // Update dummy database.
                 // In real life data would be loaded from database.
                 dummyDB.put(p.getId(), p);


Mime
View raw message