IGNITE-5771: Added Ignite::SetActive() for C++
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/47fea40b Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/47fea40b Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/47fea40b Branch: refs/heads/ignite-5578 Commit: 47fea40b07857a08727ac2e062cb9a3e0f464fdc Parents: 2941392 Author: Igor Sapego <isap...@gridgain.com> Authored: Thu Jul 27 19:39:51 2017 +0300 Committer: Igor Sapego <isap...@gridgain.com> Committed: Thu Jul 27 19:39:51 2017 +0300 ---------------------------------------------------------------------- .../cpp/core-test/src/cluster_test.cpp | 13 ++++++ .../platforms/cpp/core/include/ignite/ignite.h | 15 +++++++ .../ignite/impl/cluster/cluster_group_impl.h | 15 +++++++ .../cpp/core/include/ignite/impl/ignite_impl.h | 46 ++++++++++---------- modules/platforms/cpp/core/src/ignite.cpp | 10 +++++ .../src/impl/cluster/cluster_group_impl.cpp | 26 ++++++++++- .../platforms/cpp/core/src/impl/ignite_impl.cpp | 24 ++++++++++ 7 files changed, 124 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/47fea40b/modules/platforms/cpp/core-test/src/cluster_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cluster_test.cpp b/modules/platforms/cpp/core-test/src/cluster_test.cpp index e9d6728..4ee3f39 100644 --- a/modules/platforms/cpp/core-test/src/cluster_test.cpp +++ b/modules/platforms/cpp/core-test/src/cluster_test.cpp @@ -83,4 +83,17 @@ BOOST_AUTO_TEST_CASE(IgniteImplForServers) BOOST_REQUIRE(clusterGroup.Get()->ForServers().IsValid()); } +BOOST_AUTO_TEST_CASE(IgniteSetActive) +{ + BOOST_REQUIRE(node.IsActive()); + + node.SetActive(false); + + BOOST_REQUIRE(!node.IsActive()); + + node.SetActive(true); + + BOOST_REQUIRE(node.IsActive()); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/47fea40b/modules/platforms/cpp/core/include/ignite/ignite.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/ignite.h b/modules/platforms/cpp/core/include/ignite/ignite.h index 07134a1..e953b8f 100644 --- a/modules/platforms/cpp/core/include/ignite/ignite.h +++ b/modules/platforms/cpp/core/include/ignite/ignite.h @@ -182,6 +182,21 @@ namespace ignite } /** + * Check if the Ignite grid is active. + * + * @return True if grid is active and false otherwise. + */ + bool IsActive(); + + /** + * Change Ignite grid state to active or inactive. + * + * @param active If true start activation process. If false start + * deactivation process. + */ + void SetActive(bool active); + + /** * Get transactions. * * This method should only be used on the valid instance. http://git-wip-us.apache.org/repos/asf/ignite/blob/47fea40b/modules/platforms/cpp/core/include/ignite/impl/cluster/cluster_group_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/cluster/cluster_group_impl.h b/modules/platforms/cpp/core/include/ignite/impl/cluster/cluster_group_impl.h index 3cfd700..d81e899 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/cluster/cluster_group_impl.h +++ b/modules/platforms/cpp/core/include/ignite/impl/cluster/cluster_group_impl.h @@ -71,6 +71,21 @@ namespace ignite */ SP_ComputeImpl GetCompute(); + /** + * Check if the Ignite grid is active. + * + * @return True if grid is active and false otherwise. + */ + bool IsActive(); + + /** + * Change Ignite grid state to active or inactive. + * + * @param active If true start activation process. If false start + * deactivation process. + */ + void SetActive(bool active); + private: IGNITE_NO_COPY_ASSIGNMENT(ClusterGroupImpl); http://git-wip-us.apache.org/repos/asf/ignite/blob/47fea40b/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h b/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h index d1763c4..5461d1c 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h +++ b/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h @@ -182,6 +182,27 @@ namespace ignite */ SP_ComputeImpl GetCompute(); + /** + * Check if the Ignite grid is active. + * + * @return True if grid is active and false otherwise. + */ + bool IsActive() + { + return prjImpl.Get()->IsActive(); + } + + /** + * Change Ignite grid state to active or inactive. + * + * @param active If true start activation process. If false start + * deactivation process. + */ + void SetActive(bool active) + { + prjImpl.Get()->SetActive(active); + } + private: /** * Get transactions internal call. @@ -215,30 +236,7 @@ namespace ignite * @param err Error. * @param op Operation code. */ - cache::CacheImpl* GetOrCreateCache(const char* name, IgniteError& err, int32_t op) - { - SharedPointer<InteropMemory> mem = env.Get()->AllocateMemory(); - InteropMemory* mem0 = mem.Get(); - InteropOutputStream out(mem0); - BinaryWriterImpl writer(&out, env.Get()->GetTypeManager()); - BinaryRawWriter rawWriter(&writer); - - rawWriter.WriteString(name); - - out.Synchronize(); - - jobject cacheJavaRef = InStreamOutObject(op, *mem0, err); - - if (!cacheJavaRef) - { - return NULL; - } - - char* name0 = common::CopyChars(name); - - return new cache::CacheImpl(name0, env, cacheJavaRef); - } - + cache::CacheImpl* GetOrCreateCache(const char* name, IgniteError& err, int32_t op); }; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/47fea40b/modules/platforms/cpp/core/src/ignite.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/ignite.cpp b/modules/platforms/cpp/core/src/ignite.cpp index 9c42f1d..6eaae01 100644 --- a/modules/platforms/cpp/core/src/ignite.cpp +++ b/modules/platforms/cpp/core/src/ignite.cpp @@ -45,6 +45,16 @@ namespace ignite return impl.Get()->GetConfiguration(); } + bool Ignite::IsActive() + { + return impl.Get()->IsActive(); + } + + void Ignite::SetActive(bool active) + { + impl.Get()->SetActive(active); + } + transactions::Transactions Ignite::GetTransactions() { using ignite::common::concurrent::SharedPointer; http://git-wip-us.apache.org/repos/asf/ignite/blob/47fea40b/modules/platforms/cpp/core/src/impl/cluster/cluster_group_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/cluster/cluster_group_impl.cpp b/modules/platforms/cpp/core/src/impl/cluster/cluster_group_impl.cpp index c34e828..91f9d30 100644 --- a/modules/platforms/cpp/core/src/impl/cluster/cluster_group_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/cluster/cluster_group_impl.cpp @@ -30,7 +30,11 @@ namespace ignite { enum Type { - FOR_SERVERS = 23 + FOR_SERVERS = 23, + + SET_ACTIVE = 28, + + IS_ACTIVE = 29 }; }; @@ -61,6 +65,26 @@ namespace ignite return computeImpl; } + bool ClusterGroupImpl::IsActive() + { + IgniteError err; + + int64_t res = OutInOpLong(Command::IS_ACTIVE, 0, err); + + IgniteError::ThrowIfNeeded(err); + + return res == 1; + } + + void ClusterGroupImpl::SetActive(bool active) + { + IgniteError err; + + int64_t res = OutInOpLong(Command::SET_ACTIVE, active ? 1 : 0, err); + + IgniteError::ThrowIfNeeded(err); + } + SP_ClusterGroupImpl ClusterGroupImpl::FromTarget(jobject javaRef) { return SP_ClusterGroupImpl(new ClusterGroupImpl(GetEnvironmentPointer(), javaRef)); http://git-wip-us.apache.org/repos/asf/ignite/blob/47fea40b/modules/platforms/cpp/core/src/impl/ignite_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/ignite_impl.cpp b/modules/platforms/cpp/core/src/impl/ignite_impl.cpp index f7ff185..f2132d4 100644 --- a/modules/platforms/cpp/core/src/impl/ignite_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/ignite_impl.cpp @@ -91,5 +91,29 @@ namespace ignite return res; } + + cache::CacheImpl* IgniteImpl::GetOrCreateCache(const char* name, IgniteError& err, int32_t op) + { + SharedPointer<InteropMemory> mem = env.Get()->AllocateMemory(); + InteropMemory* mem0 = mem.Get(); + InteropOutputStream out(mem0); + BinaryWriterImpl writer(&out, env.Get()->GetTypeManager()); + BinaryRawWriter rawWriter(&writer); + + rawWriter.WriteString(name); + + out.Synchronize(); + + jobject cacheJavaRef = InStreamOutObject(op, *mem0, err); + + if (!cacheJavaRef) + { + return NULL; + } + + char* name0 = common::CopyChars(name); + + return new cache::CacheImpl(name0, env, cacheJavaRef); + } } }