ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [3/8] incubator-ignite git commit: # IGNITE-421 MAke CacheManager use new start cache API.
Date Mon, 16 Mar 2015 12:29:44 GMT
# IGNITE-421 MAke CacheManager use new start cache API.


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

Branch: refs/heads/ignite-45
Commit: e4e9c35123203b238e51de5bf78064cb68d11de2
Parents: cba2edf
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Wed Mar 11 14:28:25 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Wed Mar 11 14:28:25 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/CacheManager.java   | 44 +++++++++++---------
 .../processors/cache/IgniteCacheProxy.java      | 20 +++++----
 2 files changed, 37 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e4e9c351/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java
index b181f99..3658810 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java
@@ -22,7 +22,6 @@ import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.mxbean.*;
 import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 
 import javax.cache.*;
@@ -118,12 +117,15 @@ public class CacheManager implements javax.cache.CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        CacheConfiguration igniteCacheCfg;
+        if (getCache0(cacheName) != null)
+            throw new CacheException("Cache already exists [cacheName=" + cacheName + ",
manager=" + uri + ']');
+
+        CacheConfiguration<K, V> igniteCacheCfg;
 
         if (cacheCfg instanceof CompleteConfiguration)
-            igniteCacheCfg = new CacheConfiguration((CompleteConfiguration)cacheCfg);
+            igniteCacheCfg = new CacheConfiguration<>((CompleteConfiguration<K,
V>)cacheCfg);
         else {
-            igniteCacheCfg = new CacheConfiguration();
+            igniteCacheCfg = new CacheConfiguration<>();
 
             igniteCacheCfg.setTypes(cacheCfg.getKeyType(), cacheCfg.getValueType());
             igniteCacheCfg.setStoreValueBytes(cacheCfg.isStoreByValue());
@@ -131,17 +133,7 @@ public class CacheManager implements javax.cache.CacheManager {
 
         igniteCacheCfg.setName(cacheName);
 
-        IgniteInternalFuture<?> fut = ignite.context().cache().dynamicStartCache(igniteCacheCfg,
new GridNodePredicate(
-            Collections.singleton(ignite.getLocalNodeId())));
-
-        try {
-            fut.get();
-        }
-        catch (IgniteCheckedException e) {
-            throw CU.convertToCacheException(e);
-        }
-
-        IgniteCache<K, V> res = ignite.jcache(cacheName);
+        IgniteCache<K, V> res = ignite.createCache(igniteCacheCfg);
 
         ((IgniteCacheProxy<K, V>)res).setCacheManager(this);
 
@@ -161,7 +153,7 @@ public class CacheManager implements javax.cache.CacheManager {
     @Override public <K, V> Cache<K, V> getCache(String cacheName, Class<K>
keyType, Class<V> valType) {
         ensureNotClosed();
 
-        Cache<K, V> cache = ignite.jcache(cacheName);
+        Cache<K, V> cache = getCache0(cacheName);
 
         if (cache != null) {
             if(!keyType.isAssignableFrom(cache.getConfiguration(Configuration.class).getKeyType()))
@@ -178,7 +170,7 @@ public class CacheManager implements javax.cache.CacheManager {
     @Override public <K, V> Cache<K, V> getCache(String cacheName) {
         ensureNotClosed();
 
-        IgniteCache<K, V> cache = ignite.jcache(cacheName);
+        IgniteCache<K, V> cache = getCache0(cacheName);
 
         if (cache != null) {
             if(cache.getConfiguration(Configuration.class).getKeyType() != Object.class)
@@ -191,6 +183,18 @@ public class CacheManager implements javax.cache.CacheManager {
         return cache;
     }
 
+    /**
+     * @param cacheName Cache name.
+     */
+    private <K, V> IgniteCache<K, V> getCache0(String cacheName) {
+        try {
+            return ignite.jcache(cacheName);
+        }
+        catch (IllegalArgumentException ignored) {
+            return null;
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public Iterable<String> getCacheNames() {
         if (isClosed())
@@ -212,7 +216,7 @@ public class CacheManager implements javax.cache.CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        IgniteCache<?, ?> cache = ignite.jcache(cacheName);
+        IgniteCache<?, ?> cache = getCache0(cacheName);
 
         if (cache != null)
             cache.close();
@@ -241,7 +245,7 @@ public class CacheManager implements javax.cache.CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        IgniteCache<?, ?> cache = ignite.jcache(cacheName);
+        IgniteCache<?, ?> cache = getCache0(cacheName);
 
         if (cache == null)
             throw new CacheException("Cache not found: " + cacheName);
@@ -261,7 +265,7 @@ public class CacheManager implements javax.cache.CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        IgniteCache<?, ?> cache = ignite.jcache(cacheName);
+        IgniteCache<?, ?> cache = getCache0(cacheName);
 
         if (cache == null)
             throw new CacheException("Cache not found: " + cacheName);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e4e9c351/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 030e53a..4d5f955 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
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.cache;
 
 import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.CacheManager;
 import org.apache.ignite.cache.query.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
@@ -40,6 +41,7 @@ import javax.cache.integration.*;
 import javax.cache.processor.*;
 import java.io.*;
 import java.util.*;
+import java.util.concurrent.atomic.*;
 import java.util.concurrent.locks.*;
 
 /**
@@ -66,6 +68,9 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K,
V
     /** */
     private CacheManager cacheMgr;
 
+    /** */
+    private final AtomicBoolean closed = new AtomicBoolean();
+
     /**
      * Empty constructor required for {@link Externalizable}.
      */
@@ -1239,18 +1244,19 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K,
V
 
     /** {@inheritDoc} */
     @Override public void close() {
-        try {
-            ctx.kernalContext().cache().dynamicStopCache(ctx.name()).get();
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
+        if (closed.compareAndSet(false, true)) {
+            try {
+                ctx.kernalContext().cache().dynamicStopCache(ctx.name()).get();
+            }
+            catch (IgniteCheckedException e) {
+                throw new CacheException(e);
+            }
         }
     }
 
     /** {@inheritDoc} */
     @Override public boolean isClosed() {
-        // TODO IGNITE-45 (Support start/close/destroy cache correctly)
-        return cacheMgr != null && cacheMgr.isClosed();
+        return closed.get() || cacheMgr != null && cacheMgr.isClosed();
     }
 
     /**


Mime
View raw message