ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject incubator-ignite git commit: # IGNITE-421 Need to make JCache manager compliant with new dynamic cache start functionality
Date Mon, 09 Mar 2015 19:29:38 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-421 [created] 210d5ca13


# IGNITE-421 Need to make JCache manager compliant with new dynamic cache start functionality


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

Branch: refs/heads/ignite-421
Commit: 210d5ca137f590f3010dba2ce19a129f6bed136d
Parents: a847b8b
Author: sevdokimov <sergey.evdokimov@jetbrains.com>
Authored: Mon Mar 9 22:29:27 2015 +0300
Committer: sevdokimov <sergey.evdokimov@jetbrains.com>
Committed: Mon Mar 9 22:29:27 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/CacheManager.java   | 242 +++++++------------
 .../apache/ignite/cache/CachingProvider.java    | 155 +++++++++---
 .../processors/cache/IgniteCacheProxy.java      |  27 +--
 3 files changed, 218 insertions(+), 206 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/210d5ca1/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 3316ff5..b181f99 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
@@ -19,7 +19,11 @@ package org.apache.ignite.cache;
 
 import org.apache.ignite.*;
 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.*;
 import javax.cache.configuration.*;
@@ -40,9 +44,6 @@ public class CacheManager implements javax.cache.CacheManager {
     private static final String CACHE_CONFIGURATION = "CacheConfiguration";
 
     /** */
-    private final Map<String, Ignite> igniteMap = new HashMap<>();
-
-    /** */
     private final URI uri;
 
     /** */
@@ -58,7 +59,7 @@ public class CacheManager implements javax.cache.CacheManager {
     private final AtomicBoolean closed = new AtomicBoolean();
 
     /** */
-    private final AtomicInteger mgrIdx = new AtomicInteger();
+    private final IgniteKernal ignite;
 
     /**
      * @param uri Uri.
@@ -71,6 +72,19 @@ public class CacheManager implements javax.cache.CacheManager {
         this.cachingProvider = cachingProvider;
         this.clsLdr = clsLdr;
         this.props = props;
+
+        try {
+            if (uri.equals(cachingProvider.getDefaultURI()))
+                ignite = (IgniteKernal)IgnitionEx.start();
+            else
+                ignite = (IgniteKernal)IgnitionEx.start(uri.toURL());
+        }
+        catch (IgniteCheckedException e) {
+            throw CU.convertToCacheException(e);
+        }
+        catch (MalformedURLException e) {
+            throw new CacheException(e);
+        }
     }
 
     /** {@inheritDoc} */
@@ -117,34 +131,22 @@ public class CacheManager implements javax.cache.CacheManager {
 
         igniteCacheCfg.setName(cacheName);
 
-        IgniteCache<K, V> res;
-
-        synchronized (igniteMap) {
-            if (igniteMap.containsKey(cacheName))
-                throw new CacheException("Cache already exists [cacheName=" + cacheName +
", manager=" + uri + ']');
-
-            Ignite ignite;
+        IgniteInternalFuture<?> fut = ignite.context().cache().dynamicStartCache(igniteCacheCfg,
new GridNodePredicate(
+            Collections.singleton(ignite.getLocalNodeId())));
 
-            if (uri.equals(cachingProvider.getDefaultURI())) {
-                IgniteConfiguration cfg = new IgniteConfiguration();
-                cfg.setGridName(mgrIdx.incrementAndGet() + "-grid-for-" + cacheName);
-
-                cfg.setCacheConfiguration(igniteCacheCfg);
+        try {
+            fut.get();
+        }
+        catch (IgniteCheckedException e) {
+            throw CU.convertToCacheException(e);
+        }
 
-                try {
-                    ignite = Ignition.start(cfg);
-                }
-                catch (IgniteException e) {
-                    throw new CacheException(e);
-                }
-            }
-            else
-                throw new UnsupportedOperationException();
+        IgniteCache<K, V> res = ignite.jcache(cacheName);
 
-            res = ignite.jcache(cacheName);
+        ((IgniteCacheProxy<K, V>)res).setCacheManager(this);
 
-            igniteMap.put(cacheName, ignite);
-        }
+        if (res == null)
+            throw new CacheException();
 
         if (igniteCacheCfg.isManagementEnabled())
             enableManagement(cacheName, true);
@@ -155,27 +157,11 @@ public class CacheManager implements javax.cache.CacheManager {
         return res;
     }
 
-    /**
-     * @param cacheName Cache name.
-     */
-    private <K, V> IgniteCache<K, V> findCache(String cacheName) {
-        Ignite ignite;
-
-        synchronized (igniteMap) {
-            ignite = igniteMap.get(cacheName);
-        }
-
-        if (ignite == null)
-            return null;
-
-        return ignite.jcache(cacheName);
-    }
-
     /** {@inheritDoc} */
     @Override public <K, V> Cache<K, V> getCache(String cacheName, Class<K>
keyType, Class<V> valType) {
         ensureNotClosed();
 
-        Cache<K, V> cache = findCache(cacheName);
+        Cache<K, V> cache = ignite.jcache(cacheName);
 
         if (cache != null) {
             if(!keyType.isAssignableFrom(cache.getConfiguration(Configuration.class).getKeyType()))
@@ -192,7 +178,7 @@ public class CacheManager implements javax.cache.CacheManager {
     @Override public <K, V> Cache<K, V> getCache(String cacheName) {
         ensureNotClosed();
 
-        IgniteCache<K, V> cache = findCache(cacheName);
+        IgniteCache<K, V> cache = ignite.jcache(cacheName);
 
         if (cache != null) {
             if(cache.getConfiguration(Configuration.class).getKeyType() != Object.class)
@@ -211,27 +197,12 @@ public class CacheManager implements javax.cache.CacheManager {
             return Collections.emptySet(); // javadoc of #getCacheNames() says that IllegalStateException
should be
                                            // thrown but CacheManagerTest.close_cachesEmpty()
require empty collection.
 
-        String[] resArr;
+        Collection<String> res = new ArrayList<>();
 
-        synchronized (igniteMap) {
-            resArr = igniteMap.keySet().toArray(new String[igniteMap.keySet().size()]);
-        }
+        for (GridCache<?, ?> cache : ignite.caches())
+            res.add(cache.name());
 
-        return Collections.unmodifiableCollection(Arrays.asList(resArr));
-    }
-
-    /**
-     * @param ignite Ignite.
-     */
-    public boolean isManagedIgnite(Ignite ignite) {
-        synchronized (igniteMap) {
-            for (Ignite instance : igniteMap.values()) {
-                if (ignite.equals(instance))
-                    return true;
-            }
-        }
-
-        return false;
+        return Collections.unmodifiableCollection(res);
     }
 
     /** {@inheritDoc} */
@@ -241,33 +212,17 @@ public class CacheManager implements javax.cache.CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        Ignite ignite;
-
-        synchronized (igniteMap) {
-            ignite = igniteMap.remove(cacheName);
-        }
-
-        if (ignite != null) {
-            try {
-                ignite.close();
-            }
-            catch (Exception ignored) {
-                // No-op.
-            }
-
-            MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();
-
-            unregisterCacheObject(mBeanSrv, cacheName, CACHE_STATISTICS);
+        IgniteCache<?, ?> cache = ignite.jcache(cacheName);
 
-            unregisterCacheObject(mBeanSrv, cacheName, CACHE_CONFIGURATION);
-        }
+        if (cache != null)
+            cache.close();
     }
 
     /**
      * @param cacheName Cache name.
      */
-    private ObjectName getObjectName(String cacheName, String objectName) {
-        String mBeanName = "javax.cache:type=" + objectName + ",CacheManager="
+    private ObjectName getObjectName(String cacheName, String objName) {
+        String mBeanName = "javax.cache:type=" + objName + ",CacheManager="
             + uri.toString().replaceAll(",|:|=|\n", ".")
             + ",Cache=" + cacheName.replaceAll(",|:|=|\n", ".");
 
@@ -286,27 +241,19 @@ public class CacheManager implements javax.cache.CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        Ignite ignite;
-
-        synchronized (igniteMap) {
-            ignite = igniteMap.get(cacheName);
-        }
-
-        MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();
+        IgniteCache<?, ?> cache = ignite.jcache(cacheName);
 
-        if (enabled) {
-            registerCacheObject(mBeanSrv, ignite.jcache(cacheName).mxBean(), cacheName, CACHE_CONFIGURATION);
+        if (cache == null)
+            throw new CacheException("Cache not found: " + cacheName);
 
-            ignite.jcache(cacheName).getConfiguration(CacheConfiguration.class).setManagementEnabled(true);
-        }
-        else {
-            unregisterCacheObject(mBeanSrv, cacheName, CACHE_CONFIGURATION);
+        if (enabled)
+            registerCacheObject(cache.mxBean(), cacheName, CACHE_CONFIGURATION);
+        else
+            unregisterCacheObject(cacheName, CACHE_CONFIGURATION);
 
-            ignite.jcache(cacheName).getConfiguration(CacheConfiguration.class).setManagementEnabled(false);
-        }
+        cache.getConfiguration(CacheConfiguration.class).setManagementEnabled(enabled);
     }
 
-
     /** {@inheritDoc} */
     @Override public void enableStatistics(String cacheName, boolean enabled) {
         ensureNotClosed();
@@ -314,46 +261,38 @@ public class CacheManager implements javax.cache.CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        Ignite ignite;
-
-        synchronized (igniteMap) {
-            ignite = igniteMap.get(cacheName);
-        }
+        IgniteCache<?, ?> cache = ignite.jcache(cacheName);
 
-        IgniteCache<Object, Object> cache = ignite.jcache(cacheName);
+        if (cache == null)
+            throw new CacheException("Cache not found: " + cacheName);
 
         CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
 
-        MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();
-
-        if (enabled) {
-            registerCacheObject(mBeanSrv, cache.mxBean(), cacheName, CACHE_STATISTICS);
+        if (enabled)
+            registerCacheObject(cache.mxBean(), cacheName, CACHE_STATISTICS);
+        else
+            unregisterCacheObject(cacheName, CACHE_STATISTICS);
 
-            cfg.setStatisticsEnabled(true);
-        }
-        else {
-            unregisterCacheObject(mBeanSrv, cacheName, CACHE_STATISTICS);
-
-            cfg.setStatisticsEnabled(false);
-        }
+        cfg.setStatisticsEnabled(enabled);
     }
 
     /**
      * @param mxbean MXBean.
      * @param name cache name.
      */
-    public void registerCacheObject(MBeanServer mBeanServer, Object mxbean, String name,
String objectName) {
-        ObjectName registeredObjName = getObjectName(name, objectName);
+    public void registerCacheObject(Object mxbean, String name, String beanType) {
+        MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();
+
+        ObjectName registeredObjName = getObjectName(name, beanType);
 
         try {
-            if (!isRegistered(mBeanServer, registeredObjName))
-                if (objectName.equals(CACHE_CONFIGURATION))
-                    mBeanServer.registerMBean(new IgniteStandardMXBean((CacheMXBean)mxbean,
CacheMXBean.class),
-                        registeredObjName);
-                else
-                    mBeanServer.registerMBean(
-                        new IgniteStandardMXBean((CacheStatisticsMXBean)mxbean, CacheStatisticsMXBean.class),
-                        registeredObjName);
+            if (mBeanSrv.queryNames(registeredObjName, null).isEmpty()) {
+                IgniteStandardMXBean bean = beanType.equals(CACHE_CONFIGURATION)
+                    ? new IgniteStandardMXBean((CacheMXBean)mxbean, CacheMXBean.class)
+                    : new IgniteStandardMXBean((CacheStatisticsMXBean)mxbean, CacheStatisticsMXBean.class);
+
+                mBeanSrv.registerMBean(bean, registeredObjName);
+            }
         }
         catch (Exception e) {
             throw new CacheException("Failed to register MBean: " + registeredObjName, e);
@@ -361,28 +300,18 @@ public class CacheManager implements javax.cache.CacheManager {
     }
 
     /**
-     * @return {@code True} if MBean registered.
-     */
-    private static boolean isRegistered(MBeanServer mBeanServer, ObjectName objectName) {
-        return !mBeanServer.queryNames(objectName, null).isEmpty();
-    }
-
-    /**
      * UnRegisters the mxbean if registered already.
      *
-     * @param mBeanSrv MBean server
      * @param name Cache name.
-     * @param objectName Mxbean name.
+     * @param beanType Mxbean name.
      */
-    public void unregisterCacheObject(MBeanServer mBeanSrv, String name, String objectName)
{
-        Set<ObjectName> registeredObjectNames;
-
-        ObjectName objName = getObjectName(name, objectName);
+    private void unregisterCacheObject(String name, String beanType) {
+        MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();
 
-        registeredObjectNames = mBeanSrv.queryNames(objName, null);
+        Set<ObjectName> registeredObjNames = mBeanSrv.queryNames(getObjectName(name,
beanType), null);
 
         //should just be one
-        for (ObjectName registeredObjectName : registeredObjectNames) {
+        for (ObjectName registeredObjectName : registeredObjNames) {
             try {
                 mBeanSrv.unregisterMBean(registeredObjectName);
             }
@@ -404,21 +333,14 @@ public class CacheManager implements javax.cache.CacheManager {
     /** {@inheritDoc} */
     @Override public void close() {
         if (closed.compareAndSet(false, true)) {
-            Ignite[] ignites;
-
-            synchronized (igniteMap) {
-                ignites = igniteMap.values().toArray(new Ignite[igniteMap.values().size()]);
-
-                igniteMap.clear();
+            try {
+                ignite.close();
             }
-
-            for (Ignite ignite : ignites) {
-                try {
-                    ignite.close();
-                }
-                catch (Exception ignored) {
-                    // Ignore any exceptions according to javadoc of javax.cache.CacheManager#close()
-                }
+            catch (Exception ignored) {
+                // Ignore any exceptions according to javadoc of javax.cache.CacheManager#close()
+            }
+            finally {
+                cachingProvider.removeClosedManager(this);
             }
         }
     }
@@ -433,8 +355,8 @@ public class CacheManager implements javax.cache.CacheManager {
         if(clazz.isAssignableFrom(getClass()))
             return clazz.cast(this);
 
-//        if(clazz.isAssignableFrom(ignite.getClass()))
-//            return clazz.cast(ignite);
+        if(clazz.isAssignableFrom(ignite.getClass()))
+            return clazz.cast(ignite);
 
         throw new IllegalArgumentException();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/210d5ca1/modules/core/src/main/java/org/apache/ignite/cache/CachingProvider.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CachingProvider.java b/modules/core/src/main/java/org/apache/ignite/cache/CachingProvider.java
index 4dcef0b..ae02792 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CachingProvider.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CachingProvider.java
@@ -19,9 +19,11 @@ package org.apache.ignite.cache;
 
 import org.apache.ignite.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.future.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.jetbrains.annotations.*;
 
+import javax.cache.*;
 import javax.cache.configuration.*;
 import java.net.*;
 import java.util.*;
@@ -59,18 +61,25 @@ public class CachingProvider implements javax.cache.spi.CachingProvider
{
     public static final Properties DFLT_PROPS = new Properties();
 
     /** */
-    private final Map<ClassLoader, Map<URI, CacheManager>> cacheManagers = new
WeakHashMap<>();
+    private final Map<ClassLoader, Map<URI, GridFutureAdapter<CacheManager>>>
cacheManagers = new WeakHashMap<>();
 
     /** {@inheritDoc} */
-    @Override public javax.cache.CacheManager getCacheManager(@Nullable URI uri, ClassLoader
clsLdr, Properties props) {
+    @Override public javax.cache.CacheManager getCacheManager(@Nullable URI uri, ClassLoader
clsLdr, Properties props)
+        throws CacheException {
         if (uri == null)
             uri = getDefaultURI();
 
         if (clsLdr == null)
             clsLdr = getDefaultClassLoader();
 
+        GridFutureAdapter<CacheManager> fut;
+
+        boolean needStartMgr = false;
+
+        Map<URI, GridFutureAdapter<CacheManager>> uriMap;
+
         synchronized (cacheManagers) {
-            Map<URI, CacheManager> uriMap = cacheManagers.get(clsLdr);
+            uriMap = cacheManagers.get(clsLdr);
 
             if (uriMap == null) {
                 uriMap = new HashMap<>();
@@ -78,15 +87,42 @@ public class CachingProvider implements javax.cache.spi.CachingProvider
{
                 cacheManagers.put(clsLdr, uriMap);
             }
 
-            CacheManager mgr = uriMap.get(uri);
+            fut = uriMap.get(uri);
+
+            if (fut == null) {
+                needStartMgr = true;
+
+                fut = new GridFutureAdapter<>();
+
+                uriMap.put(uri, fut);
+            }
+        }
+
+        if (needStartMgr) {
+            try {
+                CacheManager mgr = new CacheManager(uri, this, clsLdr, props);
 
-            if (mgr == null || mgr.isClosed()) {
-                mgr = new CacheManager(uri, this, clsLdr, props);
+                fut.onDone(mgr);
 
-                uriMap.put(uri, mgr);
+                return mgr;
             }
+            catch (Throwable e) {
+                synchronized (cacheManagers) {
+                    uriMap.remove(uri);
+                }
+
+                fut.onDone(e);
 
-            return mgr;
+                throw CU.convertToCacheException(U.cast(e));
+            }
+        }
+        else {
+            try {
+                return fut.get();
+            }
+            catch (IgniteCheckedException e) {
+                throw CU.convertToCacheException(e);
+            }
         }
     }
 
@@ -116,16 +152,25 @@ public class CachingProvider implements javax.cache.spi.CachingProvider
{
     }
 
     /**
-     * @param cache Cache.
+     * @param ignite Ignite.
      */
-    public javax.cache.CacheManager findManager(IgniteCache<?,?> cache) {
-        Ignite ignite = cache.unwrap(Ignite.class);
-
+    public javax.cache.CacheManager findManager(Ignite ignite) {
         synchronized (cacheManagers) {
-            for (Map<URI, CacheManager> map : cacheManagers.values()) {
-                for (CacheManager manager : map.values()) {
-                    if (manager.isManagedIgnite(ignite))
-                        return manager;
+            for (Map<URI, GridFutureAdapter<CacheManager>> map : cacheManagers.values())
{
+                for (GridFutureAdapter<CacheManager> fut : map.values()) {
+                    if (fut.isDone()) {
+                        assert !fut.isFailed();
+
+                        try {
+                            CacheManager mgr = fut.get();
+
+                            if (mgr.unwrap(Ignite.class) == ignite)
+                                return mgr;
+                        }
+                        catch (IgniteCheckedException e) {
+                            throw CU.convertToCacheException(e);
+                        }
+                    }
                 }
             }
         }
@@ -135,51 +180,97 @@ public class CachingProvider implements javax.cache.spi.CachingProvider
{
 
     /** {@inheritDoc} */
     @Override public void close() {
-        Collection<CacheManager> mgrs = new ArrayList<>();
+        Collection<GridFutureAdapter<CacheManager>> futs = new ArrayList<>();
 
         synchronized (cacheManagers) {
-            for (Map<URI, CacheManager> uriMap : cacheManagers.values())
-                mgrs.addAll(uriMap.values());
+            for (Map<URI, GridFutureAdapter<CacheManager>> uriMap : cacheManagers.values())
+                futs.addAll(uriMap.values());
 
             cacheManagers.clear();
         }
 
-        for (CacheManager mgr : mgrs)
-            mgr.close();
+        closeManagers(futs);
     }
 
     /** {@inheritDoc} */
     @Override public void close(ClassLoader clsLdr) {
-        Collection<CacheManager> mgrs;
+        Map<URI, GridFutureAdapter<CacheManager>> uriMap;
 
         synchronized (cacheManagers) {
-            Map<URI, CacheManager> uriMap = cacheManagers.remove(clsLdr);
+            uriMap = cacheManagers.remove(clsLdr);
+        }
 
-            if (uriMap == null)
-                return;
+        if (uriMap == null)
+            return;
+
+        closeManagers(uriMap.values());
+    }
+
+    /**
+     * @param futs Futs.
+     */
+    private void closeManagers(Collection<GridFutureAdapter<CacheManager>> futs)
{
+        for (GridFutureAdapter<CacheManager> fut : futs) {
+            try {
+                CacheManager mgr = fut.get();
 
-            mgrs = uriMap.values();
+                mgr.close();
+            }
+            catch (Exception ignored) {
+                // No-op.
+            }
         }
+    }
 
-        for (CacheManager mgr : mgrs)
-            mgr.close();
+    /**
+     * @param mgr Manager.
+     */
+    protected void removeClosedManager(CacheManager mgr) {
+        synchronized (cacheManagers) {
+            Map<URI, GridFutureAdapter<CacheManager>> uriMap = cacheManagers.get(mgr.getClassLoader());
+
+            GridFutureAdapter<CacheManager> fut = uriMap.get(mgr.getURI());
+
+            if (fut != null && fut.isDone() && !fut.isFailed()) {
+                try {
+                    CacheManager cachedManager = fut.get();
+
+                    if (cachedManager == mgr)
+                        uriMap.remove(mgr.getURI());
+                }
+                catch (IgniteCheckedException e) {
+                    CU.convertToCacheException(e);
+                }
+            }
+        }
     }
 
     /** {@inheritDoc} */
     @Override public void close(URI uri, ClassLoader clsLdr) {
-        CacheManager mgr;
+        GridFutureAdapter<CacheManager> fut;
 
         synchronized (cacheManagers) {
-            Map<URI, CacheManager> uriMap = cacheManagers.get(clsLdr);
+            Map<URI, GridFutureAdapter<CacheManager>> uriMap = cacheManagers.get(clsLdr);
 
             if (uriMap == null)
                 return;
 
-            mgr = uriMap.remove(uri);
+            fut = uriMap.remove(uri);
         }
 
-        if (mgr != null)
+        if (fut != null) {
+            CacheManager mgr;
+
+            try {
+                mgr = fut.get();
+            }
+            catch (Exception ignored) {
+                return;
+            }
+
             mgr.close();
+        }
+
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/210d5ca1/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 cddae65..9d27f4a 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
@@ -64,6 +64,9 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K,
V
     /** Projection. */
     private GridCacheProjectionImpl<K, V> prj;
 
+    /** */
+    private CacheManager cacheMgr;
+
     /**
      * Empty constructor required for {@link Externalizable}.
      */
@@ -1224,31 +1227,27 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K,
V
     }
 
     /** {@inheritDoc} */
-    @Override public javax.cache.CacheManager getCacheManager() {
-        // TODO IGNITE-45 (Support start/close/destroy cache correctly)
-        CachingProvider provider = (CachingProvider)Caching.getCachingProvider(
-            CachingProvider.class.getName(),
-            CachingProvider.class.getClassLoader());
-
-        if (provider == null)
-            return null;
+    @Override public CacheManager getCacheManager() {
+        return cacheMgr;
+    }
 
-        return provider.findManager(this);
+    /**
+     * @param cacheMgr Cache manager.
+     */
+    public void setCacheManager(CacheManager cacheMgr) {
+        this.cacheMgr = cacheMgr;
     }
 
     /** {@inheritDoc} */
     @Override public void close() {
         // TODO IGNITE-45 (Support start/close/destroy cache correctly)
-        CacheManager cacheMgr = getCacheManager();
-
-        if (cacheMgr != null) // cacheMgr == null means cache is closed.
-            cacheMgr.destroyCache(getName());
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
     @Override public boolean isClosed() {
         // TODO IGNITE-45 (Support start/close/destroy cache correctly)
-        return getCacheManager() == null;
+        return cacheMgr != null && cacheMgr.isClosed();
     }
 
     /** {@inheritDoc} */


Mime
View raw message