ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: # ignite-42
Date Tue, 13 Jan 2015 14:19:58 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-42 [created] 5faab665f


# ignite-42


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

Branch: refs/heads/ignite-42
Commit: 5faab665f6df5dea39c8deb7559fc7c20b61b3eb
Parents: bb32d46
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Jan 13 17:19:21 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Jan 13 17:19:21 2015 +0300

----------------------------------------------------------------------
 .../grid/cache/GridCacheConfiguration.java      |   2 +
 .../cache/GridCacheLoaderWriterStore.java       | 211 +++++++++++++++++++
 .../processors/cache/GridCacheProcessor.java    |  21 ++
 .../processors/cache/GridCacheStoreManager.java |   3 +-
 4 files changed, 236 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5faab665/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
index 5a9a675..082a8b1 100644
--- a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
+++ b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
@@ -343,7 +343,9 @@ public class GridCacheConfiguration extends MutableConfiguration {
         atomicityMode = cc.getAtomicityMode();
         atomicWriteOrderMode = cc.getAtomicWriteOrderMode();
         backups = cc.getBackups();
+        cacheLoaderFactory = cc.getCacheLoaderFactory();
         cacheMode = cc.getCacheMode();
+        cacheWriterFactory = cc.getCacheWriterFactory();
         cloner = cc.getCloner();
         dfltLockTimeout = cc.getDefaultLockTimeout();
         dfltQryTimeout = cc.getDefaultQueryTimeout();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5faab665/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheLoaderWriterStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheLoaderWriterStore.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheLoaderWriterStore.java
new file mode 100644
index 0000000..0e7bd01
--- /dev/null
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheLoaderWriterStore.java
@@ -0,0 +1,211 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.gridgain.grid.kernal.processors.cache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.lifecycle.*;
+import org.apache.ignite.transactions.*;
+import org.gridgain.grid.cache.store.*;
+import org.gridgain.grid.util.typedef.*;
+import org.gridgain.grid.util.typedef.internal.*;
+import org.jetbrains.annotations.*;
+
+import javax.cache.*;
+import javax.cache.integration.*;
+import java.util.*;
+
+/**
+ * Store implementation wrapping {@link CacheLoader} and {@link CacheWriter}.
+ */
+class GridCacheLoaderWriterStore<K, V> implements GridCacheStore<K, V>, LifecycleAware
{
+    /** */
+    private final CacheLoader<K, V> ldr;
+
+    /** */
+    private final CacheWriter<K, V> writer;
+
+    /**
+     * @param ldr Loader.
+     * @param writer Writer.
+     */
+    GridCacheLoaderWriterStore(@Nullable CacheLoader<K, V> ldr, @Nullable CacheWriter<K,
V> writer) {
+        assert ldr != null || writer != null;
+
+        this.ldr = ldr;
+        this.writer = writer;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start() throws IgniteCheckedException {
+        if (ldr instanceof LifecycleAware)
+            ((LifecycleAware)ldr).start();
+
+        if (writer instanceof LifecycleAware)
+            ((LifecycleAware)writer).start();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws IgniteCheckedException {
+        if (ldr instanceof LifecycleAware)
+            ((LifecycleAware)ldr).stop();
+
+        if (writer instanceof LifecycleAware)
+            ((LifecycleAware)writer).stop();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void loadCache(IgniteBiInClosure<K, V> clo, @Nullable Object...
args) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public V load(@Nullable IgniteTx tx, K key) throws IgniteCheckedException
{
+        if (ldr == null)
+            return null;
+
+        return ldr.load(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void loadAll(@Nullable IgniteTx tx, Collection<? extends K> keys,
IgniteBiInClosure<K, V> c)
+        throws IgniteCheckedException {
+        if (ldr == null)
+            return;
+
+        Map<K, V> map = ldr.loadAll(keys);
+
+        if (map != null) {
+            for (Map.Entry<K, V> e : map.entrySet())
+                c.apply(e.getKey(), e.getValue());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void put(@Nullable IgniteTx tx, K key, V val) throws IgniteCheckedException
{
+        if (writer == null)
+            return;
+
+        writer.write(new KeyValueEntry<>(key, val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void putAll(@Nullable IgniteTx tx, Map<? extends K, ? extends V>
map)
+        throws IgniteCheckedException {
+        if (writer == null)
+            return;
+
+        Collection<Cache.Entry<? extends K, ? extends V>> col =
+            F.viewReadOnly(map.entrySet(), new C1<Map.Entry<? extends K, ? extends
V>, Cache.Entry<? extends K, ? extends V>>() {
+                @Override
+                public Cache.Entry<? extends K, ? extends V> apply(Map.Entry<? extends
K, ? extends V> e) {
+                    return new MapEntry<>(e);
+                }
+            });
+
+        writer.writeAll(col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove(@Nullable IgniteTx tx, K key) throws IgniteCheckedException
{
+        if (writer == null)
+            return;
+
+        writer.delete(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void removeAll(@Nullable IgniteTx tx, Collection<? extends K>
keys) throws IgniteCheckedException {
+        if (writer == null)
+            return;
+
+        writer.deleteAll(keys);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void txEnd(IgniteTx tx, boolean commit) throws IgniteCheckedException
{
+        // No-op.
+    }
+
+    /**
+     *
+     */
+    private static class KeyValueEntry<K, V> implements Cache.Entry<K, V> {
+        /** */
+        private final K key;
+
+        /** */
+        private final V val;
+
+        /**
+         * @param key Key.
+         * @param val Value.
+         */
+        KeyValueEntry(K key, V val) {
+            this.key = key;
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public K getKey() {
+            return key;
+        }
+
+        /** {@inheritDoc} */
+        @Override public V getValue() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public <T> T unwrap(Class<T> clazz) {
+            throw new IllegalArgumentException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(KeyValueEntry.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    static class MapEntry<K, V> implements Cache.Entry<K, V> {
+        /** */
+        private final Map.Entry<K, V> e;
+
+        /**
+         * @param e Entry.
+         */
+        MapEntry(Map.Entry<K, V> e) {
+            this.e = e;
+        }
+
+        /** {@inheritDoc} */
+        @Override public K getKey() {
+            return e.getKey();
+        }
+
+        /** {@inheritDoc} */
+        @Override public V getValue() {
+            return e.getValue();
+        }
+
+        /** {@inheritDoc} */
+        @Override public <T> T unwrap(Class<T> clazz) {
+            throw new IllegalArgumentException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MapEntry.class, this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5faab665/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheProcessor.java
index 8e9cea0..c7f9c48 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheProcessor.java
@@ -43,6 +43,8 @@ import org.gridgain.grid.util.typedef.*;
 import org.gridgain.grid.util.typedef.internal.*;
 import org.jetbrains.annotations.*;
 
+import javax.cache.configuration.*;
+import javax.cache.integration.*;
 import javax.management.*;
 import java.util.*;
 
@@ -208,6 +210,25 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                     "cacheName=" + cfg.getName() + ']');
             }
         }
+
+        if (cfg.getStore() == null) {
+            Factory<CacheLoader> ldrFactory = cfg.getCacheLoaderFactory();
+
+            CacheLoader ldr = null;
+
+            if (ldrFactory != null)
+                ldr = ldrFactory.create();
+
+            Factory<CacheWriter> writerFactory = cfg.getCacheWriterFactory();
+
+            CacheWriter writer = null;
+
+            if (cfg.isWriteBehindEnabled() && writerFactory != null)
+                writer = writerFactory.create();
+
+            if (ldr != null || writer != null)
+                cfg.setStore(new GridCacheLoaderWriterStore(ldr, writer));
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5faab665/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java
index b6fe4be..eab631d 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheStoreManager.java
@@ -248,7 +248,8 @@ public class GridCacheStoreManager<K, V> extends GridCacheManagerAdapter<K,
V> {
      * @throws IgniteCheckedException If data loading failed.
      */
     @SuppressWarnings({"ErrorNotRethrown", "unchecked"})
-    public boolean loadCache(final GridInClosure3<K, V, GridCacheVersion> vis, Object[]
args) throws IgniteCheckedException {
+    public boolean loadCache(final GridInClosure3<K, V, GridCacheVersion> vis, Object[]
args)
+        throws IgniteCheckedException {
         if (store != null) {
             if (log.isDebugEnabled())
                 log.debug("Loading all values from store.");


Mime
View raw message