Repository: ignite Updated Branches: refs/heads/master d7fd58077 -> 9a996332d
IGNITE-1514: .NET: Added "DestroyCache" method. This closes #375. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9a996332 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9a996332 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9a996332 Branch: refs/heads/master Commit: 9a996332df81aee79b629811062d28fe75dead99 Parents: d7fd580 Author: Pavel Tupitsyn <ptupit...@gridgain.com> Authored: Mon Jan 18 18:42:34 2016 +0300 Committer: vozerov-gridgain <voze...@gridgain.com> Committed: Mon Jan 18 18:42:34 2016 +0300 ---------------------------------------------------------------------- .../platform/PlatformNoopProcessor.java | 5 +++++ .../processors/platform/PlatformProcessor.java | 8 ++++++++ .../platform/PlatformProcessorImpl.java | 5 +++++ .../cpp/common/include/ignite/common/exports.h | 1 + .../cpp/common/include/ignite/common/java.h | 3 +++ .../platforms/cpp/common/project/vs/module.def | 3 ++- modules/platforms/cpp/common/src/exports.cpp | 4 ++++ modules/platforms/cpp/common/src/java.cpp | 20 ++++++++++++++++++++ .../Cache/CacheAbstractTest.cs | 19 +++++++++++++++++++ .../dotnet/Apache.Ignite.Core/IIgnite.cs | 7 +++++++ .../dotnet/Apache.Ignite.Core/Impl/Ignite.cs | 6 ++++++ .../Apache.Ignite.Core/Impl/IgniteProxy.cs | 6 ++++++ .../Impl/Unmanaged/IgniteJniNativeMethods.cs | 3 +++ .../Impl/Unmanaged/UnmanagedUtils.cs | 16 ++++++++++++++++ 14 files changed, 105 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java index 9142543..fb28008 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java @@ -74,6 +74,11 @@ public class PlatformNoopProcessor extends GridProcessorAdapter implements Platf } /** {@inheritDoc} */ + @Override public void destroyCache(@Nullable String name) throws IgniteCheckedException { + // No-op. + } + + /** {@inheritDoc} */ @Override public PlatformTarget affinity(@Nullable String name) throws IgniteCheckedException { return null; } http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java index fa22953..8e684e3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java @@ -90,6 +90,14 @@ public interface PlatformProcessor extends GridProcessor { public PlatformTarget getOrCreateCache(@Nullable String name) throws IgniteCheckedException; /** + * Destroy dynamically created cache. + * + * @param name Cache name. + * @throws IgniteCheckedException If failed. + */ + public void destroyCache(@Nullable String name) throws IgniteCheckedException; + + /** * Get affinity. * * @param name Cache name. http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java index b0870bb..dc6e0df 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java @@ -244,6 +244,11 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf } /** {@inheritDoc} */ + @Override public void destroyCache(@Nullable String name) throws IgniteCheckedException { + ctx.grid().destroyCache(name); + } + + /** {@inheritDoc} */ @Override public PlatformTarget affinity(@Nullable String name) throws IgniteCheckedException { return new PlatformAffinity(platformCtx, ctx, name); } http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/cpp/common/include/ignite/common/exports.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/exports.h b/modules/platforms/cpp/common/include/ignite/common/exports.h index 3eb775d..67583ed 100644 --- a/modules/platforms/cpp/common/include/ignite/common/exports.h +++ b/modules/platforms/cpp/common/include/ignite/common/exports.h @@ -36,6 +36,7 @@ extern "C" { void* IGNITE_CALL IgniteProcessorCache(gcj::JniContext* ctx, void* obj, char* name); void* IGNITE_CALL IgniteProcessorCreateCache(gcj::JniContext* ctx, void* obj, char* name); void* IGNITE_CALL IgniteProcessorGetOrCreateCache(gcj::JniContext* ctx, void* obj, char* name); + void IGNITE_CALL IgniteProcessorDestroyCache(gcj::JniContext* ctx, void* obj, char* name); void* IGNITE_CALL IgniteProcessorAffinity(gcj::JniContext* ctx, void* obj, char* name); void* IGNITE_CALL IgniteProcessorDataStreamer(gcj::JniContext* ctx, void* obj, char* name, bool keepPortable); void* IGNITE_CALL IgniteProcessorTransactions(gcj::JniContext* ctx, void* obj); http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/cpp/common/include/ignite/common/java.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/java.h b/modules/platforms/cpp/common/include/ignite/common/java.h index e629c77..572f040 100644 --- a/modules/platforms/cpp/common/include/ignite/common/java.h +++ b/modules/platforms/cpp/common/include/ignite/common/java.h @@ -297,6 +297,7 @@ namespace ignite jmethodID m_PlatformProcessor_cache; jmethodID m_PlatformProcessor_createCache; jmethodID m_PlatformProcessor_getOrCreateCache; + jmethodID m_PlatformProcessor_destroyCache; jmethodID m_PlatformProcessor_affinity; jmethodID m_PlatformProcessor_dataStreamer; jmethodID m_PlatformProcessor_transactions; @@ -488,6 +489,8 @@ namespace ignite jobject ProcessorCreateCache(jobject obj, const char* name, JniErrorInfo* errInfo); jobject ProcessorGetOrCreateCache(jobject obj, const char* name); jobject ProcessorGetOrCreateCache(jobject obj, const char* name, JniErrorInfo* errInfo); + void ProcessorDestroyCache(jobject obj, const char* name); + void ProcessorDestroyCache(jobject obj, const char* name, JniErrorInfo* errInfo); jobject ProcessorAffinity(jobject obj, const char* name); jobject ProcessorDataStreamer(jobject obj, const char* name, bool keepPortable); jobject ProcessorTransactions(jobject obj); http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/cpp/common/project/vs/module.def ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/module.def b/modules/platforms/cpp/common/project/vs/module.def index 3d166bd..c947128 100644 --- a/modules/platforms/cpp/common/project/vs/module.def +++ b/modules/platforms/cpp/common/project/vs/module.def @@ -112,4 +112,5 @@ IgniteAtomicLongClose @109 IgniteListenableCancel @110 IgniteListenableIsCancelled @111 IgniteTargetListenFutureAndGet @112 -IgniteTargetListenFutureForOperationAndGet @113 \ No newline at end of file +IgniteTargetListenFutureForOperationAndGet @113 +IgniteProcessorDestroyCache @114 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/cpp/common/src/exports.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/src/exports.cpp b/modules/platforms/cpp/common/src/exports.cpp index 08425a4..d4ffa7e 100644 --- a/modules/platforms/cpp/common/src/exports.cpp +++ b/modules/platforms/cpp/common/src/exports.cpp @@ -66,6 +66,10 @@ extern "C" { return ctx->ProcessorGetOrCreateCache(static_cast<jobject>(obj), name); } + void IGNITE_CALL IgniteProcessorDestroyCache(gcj::JniContext* ctx, void* obj, char* name) { + ctx->ProcessorDestroyCache(static_cast<jobject>(obj), name); + } + void* IGNITE_CALL IgniteProcessorAffinity(gcj::JniContext* ctx, void* obj, char* name) { return ctx->ProcessorAffinity(static_cast<jobject>(obj), name); } http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/cpp/common/src/java.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/src/java.cpp b/modules/platforms/cpp/common/src/java.cpp index 63deba5..9e55742 100644 --- a/modules/platforms/cpp/common/src/java.cpp +++ b/modules/platforms/cpp/common/src/java.cpp @@ -191,6 +191,7 @@ namespace ignite JniMethod M_PLATFORM_PROCESSOR_CACHE = JniMethod("cache", "(Ljava/lang/String;)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false); JniMethod M_PLATFORM_PROCESSOR_CREATE_CACHE = JniMethod("createCache", "(Ljava/lang/String;)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false); JniMethod M_PLATFORM_PROCESSOR_GET_OR_CREATE_CACHE = JniMethod("getOrCreateCache", "(Ljava/lang/String;)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false); + JniMethod M_PLATFORM_PROCESSOR_DESTROY_CACHE = JniMethod("destroyCache", "(Ljava/lang/String;)V", false); JniMethod M_PLATFORM_PROCESSOR_AFFINITY = JniMethod("affinity", "(Ljava/lang/String;)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false); JniMethod M_PLATFORM_PROCESSOR_DATA_STREAMER = JniMethod("dataStreamer", "(Ljava/lang/String;Z)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false); JniMethod M_PLATFORM_PROCESSOR_TRANSACTIONS = JniMethod("transactions", "()Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false); @@ -635,6 +636,7 @@ namespace ignite m_PlatformProcessor_cache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_CACHE); m_PlatformProcessor_createCache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_CREATE_CACHE); m_PlatformProcessor_getOrCreateCache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_OR_CREATE_CACHE); + m_PlatformProcessor_destroyCache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_DESTROY_CACHE); m_PlatformProcessor_affinity = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_AFFINITY); m_PlatformProcessor_dataStreamer = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_DATA_STREAMER); m_PlatformProcessor_transactions = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_TRANSACTIONS); @@ -1144,6 +1146,24 @@ namespace ignite return ProcessorCache0(obj, name, jvm->GetMembers().m_PlatformProcessor_getOrCreateCache, errInfo); } + void JniContext::ProcessorDestroyCache(jobject obj, const char* name) { + ProcessorDestroyCache(obj, name, NULL); + } + + void JniContext::ProcessorDestroyCache(jobject obj, const char* name, JniErrorInfo* errInfo) + { + JNIEnv* env = Attach(); + + jstring name0 = name != NULL ? env->NewStringUTF(name) : NULL; + + env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformProcessor_destroyCache, name0); + + if (name0) + env->DeleteLocalRef(name0); + + ExceptionCheck(env, errInfo); + } + jobject JniContext::ProcessorAffinity(jobject obj, const char* name) { JNIEnv* env = Attach(); http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs index ce15739..57e4949 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs @@ -3076,6 +3076,25 @@ namespace Apache.Ignite.Core.Tests.Cache } [Test] + public void TestDestroy() + { + var cacheName = "template" + Guid.NewGuid(); + + var ignite = GetIgnite(0); + + var cache = ignite.CreateCache<int, int>(cacheName); + + Assert.IsNotNull(ignite.GetCache<int, int>(cacheName)); + + ignite.DestroyCache(cache.Name); + + var ex = Assert.Throws<ArgumentException>(() => ignite.GetCache<int, int>(cacheName)); + + Assert.IsTrue(ex.Message.StartsWith("Cache doesn't exist")); + } + + + [Test] public void TestIndexer() { var cache = Cache(); http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs index 2f82756..a85e24c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs @@ -102,6 +102,13 @@ namespace Apache.Ignite.Core ICache<TK, TV> CreateCache<TK, TV>(string name); /// <summary> + /// Destroys dynamically created (with <see cref="CreateCache{TK,TV}"/> or + /// <see cref="GetOrCreateCache{TK,TV}"/>) cache. + /// </summary> + /// <param name="name">The name of the cache to stop.</param> + void DestroyCache(string name); + + /// <summary> /// Gets a new instance of data streamer associated with given cache name. Data streamer /// is responsible for loading external data into Ignite. For more information /// refer to <see cref="IDataStreamer{K,V}"/> documentation. http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs index 2fcada3..ffc8be8 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs @@ -344,6 +344,12 @@ namespace Apache.Ignite.Core.Impl return Cache<TK, TV>(UU.ProcessorCreateCache(_proc, name)); } + /** <inheritdoc /> */ + public void DestroyCache(string name) + { + UU.ProcessorDestroyCache(_proc, name); + } + /// <summary> /// Gets cache from specified native cache object. /// </summary> http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs index 36aac1a..16062e2 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs @@ -238,6 +238,12 @@ namespace Apache.Ignite.Core.Impl } /** <inheritdoc /> */ + public void DestroyCache(string name) + { + _ignite.DestroyCache(name); + } + + /** <inheritdoc /> */ public IClusterNode GetLocalNode() { http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs index 5e54a4c..70ad733 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs @@ -55,6 +55,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetOrCreateCache")] public static extern void* ProcessorGetOrCreateCache(void* ctx, void* obj, sbyte* name); + [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorDestroyCache")] + public static extern void* ProcessorDestroyCache(void* ctx, void* obj, sbyte* name); + [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorAffinity")] public static extern void* ProcessorAffinity(void* ctx, void* obj, sbyte* name); http://git-wip-us.apache.org/repos/asf/ignite/blob/9a996332/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs index e9800ee..7b12010 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs @@ -163,6 +163,22 @@ namespace Apache.Ignite.Core.Impl.Unmanaged } } + internal static IUnmanagedTarget ProcessorDestroyCache(IUnmanagedTarget target, string name) + { + sbyte* name0 = IgniteUtils.StringToUtf8Unmanaged(name); + + try + { + void* res = JNI.ProcessorDestroyCache(target.Context, target.Target, name0); + + return target.ChangeTarget(res); + } + finally + { + Marshal.FreeHGlobal(new IntPtr(name0)); + } + } + internal static IUnmanagedTarget ProcessorAffinity(IUnmanagedTarget target, string name) { sbyte* name0 = IgniteUtils.StringToUtf8Unmanaged(name);