ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [01/48] incubator-ignite git commit: IGNITE-53: Add distributed Cache.iterator
Date Fri, 23 Jan 2015 17:17:35 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/sprint-1 e9ea63e23 -> 906b55cb6


IGNITE-53: Add distributed Cache.iterator


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

Branch: refs/heads/sprint-1
Commit: 0054c0d3e31854a9633a7a8601fdf4c1ca266d47
Parents: aceb586
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Wed Jan 14 11:10:25 2015 +0400
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Wed Jan 14 11:10:25 2015 +0400

----------------------------------------------------------------------
 .../processors/cache/IgniteCacheProxy.java      | 66 +++++++++++++++++++-
 .../cache/IgniteCacheProxyApiTest.java          |  7 +++
 2 files changed, 70 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0054c0d3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index a985fde..67797cf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -14,6 +14,8 @@ import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.query.*;
 import org.apache.ignite.lang.*;
 import org.gridgain.grid.cache.*;
+import org.gridgain.grid.cache.query.GridCacheQuery;
+import org.gridgain.grid.cache.query.GridCacheQueryFuture;
 import org.gridgain.grid.kernal.*;
 import org.gridgain.grid.kernal.processors.cache.*;
 import org.gridgain.grid.util.tostring.*;
@@ -777,9 +779,9 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
     }
 
     /** {@inheritDoc} */
-    @Override public Iterator<Cache.Entry<K, V>> iterator() {
-        // TODO IGNITE-1.
-        throw new UnsupportedOperationException();
+    @Override
+    public Iterator<Cache.Entry<K, V>> iterator() {
+        return new IgniteCacheIterator();
     }
 
     /** {@inheritDoc} */
@@ -922,4 +924,62 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
     @Override public String toString() {
         return S.toString(IgniteCacheProxy.class, this);
     }
+
+    /**
+     * Iterator over the IgniteCacheProxy
+     */
+    private class IgniteCacheIterator implements Iterator<Cache.Entry<K, V>>
{
+
+        /** Cache query future for all entries in distributed ignite cache. */
+        private final GridCacheQueryFuture<Map.Entry<K, V>> fut;
+
+        /** Current element from all entries in distributed ignite cache. */
+        private Map.Entry<K, V> curIter;
+
+        public IgniteCacheIterator() {
+            fut = delegate.queries().createScanQuery(null).execute();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean hasNext() {
+            try {
+                curIter = fut.next();
+                return curIter != null;
+            } catch (IgniteCheckedException e) {
+                e.printStackTrace();
+                //TODO: ????
+            }
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Entry<K, V> next() {
+            return new Cache.Entry<K, V>() {
+                /** {@inheritDoc} */
+                @Override public K getKey() {
+                    return curIter.getKey();
+                }
+
+                /** {@inheritDoc} */
+                @Override public V getValue() {
+                    return curIter.getValue();
+                }
+
+                /** {@inheritDoc} */
+                @Override public <T> T unwrap(Class<T> clazz) {
+                    throw new IllegalArgumentException();
+                }
+            };
+        }
+
+        /** {@inheritDoc} */
+        @Override public void remove() {
+            try {
+                delegate.remove(curIter.getKey(), curIter.getValue());
+            } catch (IgniteCheckedException e) {
+                //TODO: ???
+                e.printStackTrace();
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0054c0d3/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java
new file mode 100644
index 0000000..17c4c9d
--- /dev/null
+++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java
@@ -0,0 +1,7 @@
+package org.gridgain.grid.kernal.processors.cache;
+
+/**
+ * Created by GridGain on 13.01.2015.
+ */
+public class IgniteCacheProxyApiTest {
+}


Mime
View raw message