You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sh...@apache.org on 2016/11/01 02:37:57 UTC
[38/50] [abbrv] ignite git commit: IGNITE-2957 .NET: Added
IIgnite.CacheNames() method. This closes #675.
IGNITE-2957 .NET: Added IIgnite.CacheNames() method. This closes #675.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1aa9ef7f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1aa9ef7f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1aa9ef7f
Branch: refs/heads/ignite-2788
Commit: 1aa9ef7f57122ab2dcdb7770f9656d8fca15f359
Parents: ffbde05
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Fri Apr 29 10:26:57 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900
----------------------------------------------------------------------
.../platform/PlatformNoopProcessor.java | 5 +++++
.../processors/platform/PlatformProcessor.java | 7 +++++++
.../platform/PlatformProcessorImpl.java | 15 +++++++++++++++
.../cpp/common/include/ignite/common/exports.h | 1 +
.../cpp/common/include/ignite/common/java.h | 2 ++
.../platforms/cpp/common/project/vs/module.def | 1 +
modules/platforms/cpp/common/src/exports.cpp | 4 ++++
modules/platforms/cpp/common/src/java.cpp | 11 +++++++++++
.../Cache/CacheAbstractTest.cs | 18 ++++++++++++++++++
.../dotnet/Apache.Ignite.Core/IIgnite.cs | 8 ++++++++
.../dotnet/Apache.Ignite.Core/Impl/Ignite.cs | 18 ++++++++++++++++++
.../dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs | 7 +++++++
.../Impl/Unmanaged/IgniteJniNativeMethods.cs | 3 +++
.../Impl/Unmanaged/UnmanagedUtils.cs | 5 +++++
14 files changed, 105 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 155981c..cdf418f 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
@@ -152,6 +152,11 @@ public class PlatformNoopProcessor extends GridProcessorAdapter implements Platf
}
/** {@inheritDoc} */
+ @Override public void getCacheNames(long memPtr) {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
@Override public PlatformTarget atomicSequence(String name, long initVal, boolean create) throws IgniteException {
return null;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 cca29d8..fc42b68 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
@@ -235,6 +235,13 @@ public interface PlatformProcessor extends GridProcessor {
public void getIgniteConfiguration(long memPtr);
/**
+ * Gets the cache names.
+ *
+ * @param memPtr Stream to write data to.
+ */
+ public void getCacheNames(long memPtr);
+
+ /**
* Starts a near cache on local node if cache was previously started.
*
* @param cacheName Cache name.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 e294735..5830d37 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
@@ -415,6 +415,21 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
}
/** {@inheritDoc} */
+ @Override public void getCacheNames(long memPtr) {
+ PlatformOutputStream stream = platformCtx.memory().get(memPtr).output();
+ BinaryRawWriterEx writer = platformCtx.writer(stream);
+
+ Collection<String> names = ignite().cacheNames();
+
+ writer.writeInt(names.size());
+
+ for (String name : names)
+ writer.writeString(name);
+
+ stream.synchronize();
+ }
+
+ /** {@inheritDoc} */
@Override public PlatformTarget createNearCache(@Nullable String cacheName, long memPtr) {
NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 c62b365..5798c83 100644
--- a/modules/platforms/cpp/common/include/ignite/common/exports.h
+++ b/modules/platforms/cpp/common/include/ignite/common/exports.h
@@ -53,6 +53,7 @@ extern "C" {
void* IGNITE_CALL IgniteProcessorAtomicSequence(gcj::JniContext* ctx, void* obj, char* name, long long initVal, bool create);
void* IGNITE_CALL IgniteProcessorAtomicReference(gcj::JniContext* ctx, void* obj, char* name, long long memPtr, bool create);
void IGNITE_CALL IgniteProcessorGetIgniteConfiguration(gcj::JniContext* ctx, void* obj, long long memPtr);
+ void IGNITE_CALL IgniteProcessorGetCacheNames(gcj::JniContext* ctx, void* obj, long long memPtr);
long long IGNITE_CALL IgniteTargetInStreamOutLong(gcj::JniContext* ctx, void* obj, int opType, long long memPtr);
void IGNITE_CALL IgniteTargetInStreamOutStream(gcj::JniContext* ctx, void* obj, int opType, long long inMemPtr, long long outMemPtr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 f2007cb..7deb5ef 100644
--- a/modules/platforms/cpp/common/include/ignite/common/java.h
+++ b/modules/platforms/cpp/common/include/ignite/common/java.h
@@ -319,6 +319,7 @@ namespace ignite
jmethodID m_PlatformProcessor_extensions;
jmethodID m_PlatformProcessor_atomicLong;
jmethodID m_PlatformProcessor_getIgniteConfiguration;
+ jmethodID m_PlatformProcessor_getCacheNames;
jmethodID m_PlatformProcessor_atomicSequence;
jmethodID m_PlatformProcessor_atomicReference;
@@ -537,6 +538,7 @@ namespace ignite
jobject ProcessorAtomicSequence(jobject obj, char* name, long long initVal, bool create);
jobject ProcessorAtomicReference(jobject obj, char* name, long long memPtr, bool create);
void ProcessorGetIgniteConfiguration(jobject obj, long long memPtr);
+ void ProcessorGetCacheNames(jobject obj, long long memPtr);
long long TargetInStreamOutLong(jobject obj, int type, long long memPtr, JniErrorInfo* errInfo = NULL);
void TargetInStreamOutStream(jobject obj, int opType, long long inMemPtr, long long outMemPtr, JniErrorInfo* errInfo = NULL);
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 57e58f3..5f2e941 100644
--- a/modules/platforms/cpp/common/project/vs/module.def
+++ b/modules/platforms/cpp/common/project/vs/module.def
@@ -132,3 +132,4 @@ IgniteAtomicReferenceIsClosed @129
IgniteAtomicReferenceClose @130
IgniteProcessorCreateNearCache @131
IgniteProcessorGetOrCreateNearCache @132
+IgniteProcessorGetCacheNames @133
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 0d951b6..43ccb7a 100644
--- a/modules/platforms/cpp/common/src/exports.cpp
+++ b/modules/platforms/cpp/common/src/exports.cpp
@@ -134,6 +134,10 @@ extern "C" {
return ctx->ProcessorGetIgniteConfiguration(static_cast<jobject>(obj), memPtr);
}
+ void IGNITE_CALL IgniteProcessorGetCacheNames(gcj::JniContext* ctx, void* obj, long long memPtr) {
+ return ctx->ProcessorGetCacheNames(static_cast<jobject>(obj), memPtr);
+ }
+
long long IGNITE_CALL IgniteTargetInStreamOutLong(gcj::JniContext* ctx, void* obj, int opType, long long memPtr) {
return ctx->TargetInStreamOutLong(static_cast<jobject>(obj), opType, memPtr);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 081a606..663e2b1 100644
--- a/modules/platforms/cpp/common/src/java.cpp
+++ b/modules/platforms/cpp/common/src/java.cpp
@@ -208,6 +208,7 @@ namespace ignite
JniMethod M_PLATFORM_PROCESSOR_ATOMIC_SEQUENCE = JniMethod("atomicSequence", "(Ljava/lang/String;JZ)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
JniMethod M_PLATFORM_PROCESSOR_ATOMIC_REFERENCE = JniMethod("atomicReference", "(Ljava/lang/String;JZ)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
JniMethod M_PLATFORM_PROCESSOR_GET_IGNITE_CONFIGURATION = JniMethod("getIgniteConfiguration", "(J)V", false);
+ JniMethod M_PLATFORM_PROCESSOR_GET_CACHE_NAMES = JniMethod("getCacheNames", "(J)V", false);
const char* C_PLATFORM_TARGET = "org/apache/ignite/internal/processors/platform/PlatformTarget";
JniMethod M_PLATFORM_TARGET_IN_STREAM_OUT_LONG = JniMethod("inStreamOutLong", "(IJ)J", false);
@@ -679,6 +680,7 @@ namespace ignite
m_PlatformProcessor_atomicSequence = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_ATOMIC_SEQUENCE);
m_PlatformProcessor_atomicReference = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_ATOMIC_REFERENCE);
m_PlatformProcessor_getIgniteConfiguration = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_IGNITE_CONFIGURATION);
+ m_PlatformProcessor_getCacheNames = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_CACHE_NAMES);
c_PlatformTarget = FindClass(env, C_PLATFORM_TARGET);
m_PlatformTarget_inStreamOutLong = FindMethod(env, c_PlatformTarget, M_PLATFORM_TARGET_IN_STREAM_OUT_LONG);
@@ -1462,6 +1464,15 @@ namespace ignite
ExceptionCheck(env);
}
+ void JniContext::ProcessorGetCacheNames(jobject obj, long long memPtr)
+ {
+ JNIEnv* env = Attach();
+
+ env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformProcessor_getCacheNames, memPtr);
+
+ ExceptionCheck(env);
+ }
+
long long JniContext::TargetInStreamOutLong(jobject obj, int opType, long long memPtr, JniErrorInfo* err) {
JNIEnv* env = Attach();
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 9f0528c..62dc2df 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
@@ -3062,8 +3062,10 @@ namespace Apache.Ignite.Core.Tests.Cache
// Can't get non-existent cache with Cache method
Assert.Throws<ArgumentException>(() => GetIgnite(0).GetCache<int, int>(randomName));
+ Assert.IsFalse(GetIgnite(0).GetCacheNames().Contains(randomName));
var cache = GetIgnite(0).CreateCache<int, int>(randomName);
+ Assert.IsTrue(GetIgnite(0).GetCacheNames().Contains(randomName));
cache.Put(1, 10);
@@ -3111,9 +3113,12 @@ namespace Apache.Ignite.Core.Tests.Cache
var cache = ignite.CreateCache<int, int>(cacheName);
Assert.IsNotNull(ignite.GetCache<int, int>(cacheName));
+ Assert.IsTrue(GetIgnite(0).GetCacheNames().Contains(cacheName));
ignite.DestroyCache(cache.Name);
+ Assert.IsFalse(GetIgnite(0).GetCacheNames().Contains(cacheName));
+
var ex = Assert.Throws<ArgumentException>(() => ignite.GetCache<int, int>(cacheName));
Assert.IsTrue(ex.Message.StartsWith("Cache doesn't exist"));
@@ -3121,6 +3126,19 @@ namespace Apache.Ignite.Core.Tests.Cache
Assert.Throws<InvalidOperationException>(() => cache.Get(1));
}
+ [Test]
+ public void TestCacheNames()
+ {
+ var cacheNames = GetIgnite(0).GetCacheNames();
+ var expectedNames = new[]
+ {
+ "local", "local_atomic", "partitioned", "partitioned_atomic",
+ "partitioned_near", "partitioned_atomic_near", "replicated", "replicated_atomic"
+ };
+
+ Assert.AreEqual(0, expectedNames.Except(cacheNames).Count());
+ }
+
[Test]
public void TestIndexer()
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 428c1a8..b45c625 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
@@ -18,6 +18,7 @@
namespace Apache.Ignite.Core
{
using System;
+ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Apache.Ignite.Core.Binary;
using Apache.Ignite.Core.Cache;
@@ -266,5 +267,12 @@ namespace Apache.Ignite.Core
/// <typeparam name="TV">Cache value type.</typeparam>
/// <returns>Near cache instance.</returns>
ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration);
+
+ /// <summary>
+ /// Gets the collection of names of currently available caches, or empty collection if there are no caches.
+ /// Note that null string is a valid cache name.
+ /// </summary>
+ /// <returns>Collection of names of currently available caches.</returns>
+ ICollection<string> GetCacheNames();
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 b84ff29..aee82a7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
@@ -622,6 +622,24 @@ namespace Apache.Ignite.Core.Impl
return GetOrCreateNearCache0<TK, TV>(name, configuration, UU.ProcessorGetOrCreateNearCache);
}
+ /** <inheritdoc /> */
+ public ICollection<string> GetCacheNames()
+ {
+ using (var stream = IgniteManager.Memory.Allocate(1024).GetStream())
+ {
+ UU.ProcessorGetCacheNames(_proc, stream.MemoryPointer);
+ stream.SynchronizeInput();
+
+ var reader = _marsh.StartUnmarshal(stream);
+ var res = new string[stream.ReadInt()];
+
+ for (int i = 0; i < res.Length; i++)
+ res[i] = reader.ReadString();
+
+ return res;
+ }
+ }
+
/// <summary>
/// Gets or creates near cache.
/// </summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 a767077..0ad056a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
@@ -366,12 +366,19 @@ namespace Apache.Ignite.Core.Impl
return _ignite.CreateNearCache<TK, TV>(name, configuration);
}
+ /** <inheritdoc /> */
public ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration)
{
return _ignite.GetOrCreateNearCache<TK, TV>(name, configuration);
}
/** <inheritdoc /> */
+ public ICollection<string> GetCacheNames()
+ {
+ return _ignite.GetCacheNames();
+ }
+
+ /** <inheritdoc /> */
public IAtomicSequence GetAtomicSequence(string name, long initialValue, bool create)
{
return _ignite.GetAtomicSequence(name, initialValue, create);
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 2603841..bb26382 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
@@ -110,6 +110,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
[DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetIgniteConfiguration")]
public static extern void ProcessorGetIgniteConfiguration(void* ctx, void* obj, long memPtr);
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetCacheNames")]
+ public static extern void ProcessorGetCacheNames(void* ctx, void* obj, long memPtr);
+
[DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamOutLong")]
public static extern long TargetInStreamOutLong(void* ctx, void* target, int opType, long memPtr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 f8b5256..a0abfaa 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
@@ -356,6 +356,11 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
JNI.ProcessorGetIgniteConfiguration(target.Context, target.Target, memPtr);
}
+ internal static void ProcessorGetCacheNames(IUnmanagedTarget target, long memPtr)
+ {
+ JNI.ProcessorGetCacheNames(target.Context, target.Target, memPtr);
+ }
+
#endregion
#region NATIVE METHODS: TARGET