Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1AC27200CC1 for ; Thu, 1 Jun 2017 15:23:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 19AD4160BDF; Thu, 1 Jun 2017 13:23:25 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3F5D3160BB5 for ; Thu, 1 Jun 2017 15:23:21 +0200 (CEST) Received: (qmail 15358 invoked by uid 500); 1 Jun 2017 13:23:20 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 14603 invoked by uid 99); 1 Jun 2017 13:23:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jun 2017 13:23:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 31DA6E9113; Thu, 1 Jun 2017 13:23:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Thu, 01 Jun 2017 13:23:29 -0000 Message-Id: <838a192fc361443399f1e6d350aa5161@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [14/50] [abbrv] ignite git commit: IGNITE-3355: Implemented Compute::Call() for C++ archived-at: Thu, 01 Jun 2017 13:23:25 -0000 IGNITE-3355: Implemented Compute::Call() for C++ Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f9c96de5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f9c96de5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f9c96de5 Branch: refs/heads/ignite-5267 Commit: f9c96de578c8a87e8f2f7fee01d3719d0bb21359 Parents: 0f8af13 Author: Igor Sapego Authored: Mon May 29 17:29:10 2017 +0300 Committer: Igor Sapego Committed: Mon May 29 17:29:10 2017 +0300 ---------------------------------------------------------------------- modules/platforms/cpp/binary/Makefile.am | 67 ++-- .../platforms/cpp/binary/include/Makefile.am | 55 +-- .../binary/include/ignite/binary/binary_type.h | 2 +- .../ignite/impl/binary/binary_type_impl.h | 61 ++++ .../ignite/impl/binary/binary_writer_impl.h | 4 +- .../cpp/binary/project/vs/binary.vcxproj | 2 + .../binary/project/vs/binary.vcxproj.filters | 6 + .../binary/src/impl/binary/binary_type_impl.cpp | 61 ++++ modules/platforms/cpp/common/Makefile.am | 54 +-- .../platforms/cpp/common/include/Makefile.am | 1 + .../common/include/ignite/common/cancelable.h | 65 ++++ .../cpp/common/include/ignite/common/promise.h | 18 + .../common/include/ignite/common/shared_state.h | 51 +++ .../cpp/common/include/ignite/future.h | 60 +++- .../cpp/common/include/ignite/ignite_error.h | 3 + .../cpp/common/project/vs/common.vcxproj | 1 + .../common/project/vs/common.vcxproj.filters | 3 + modules/platforms/cpp/core-test/Makefile.am | 101 +++--- .../cpp/core-test/include/ignite/test_utils.h | 24 +- .../cpp/core-test/project/vs/core-test.vcxproj | 1 + .../project/vs/core-test.vcxproj.filters | 10 +- .../cpp/core-test/src/cache_invoke_test.cpp | 2 +- .../cpp/core-test/src/cluster_test.cpp | 2 +- .../cpp/core-test/src/compute_test.cpp | 337 +++++++++++++++++++ .../cpp/core-test/src/continuous_query_test.cpp | 2 +- .../platforms/cpp/core-test/src/test_utils.cpp | 9 + modules/platforms/cpp/core/Makefile.am | 82 ++--- modules/platforms/cpp/core/include/Makefile.am | 107 +++--- .../cpp/core/include/ignite/cache/cache.h | 4 +- .../cpp/core/include/ignite/cache/query/query.h | 1 - .../cpp/core/include/ignite/compute/compute.h | 136 ++++++++ .../core/include/ignite/compute/compute_func.h | 65 ++++ .../platforms/cpp/core/include/ignite/ignite.h | 19 +- .../cpp/core/include/ignite/ignite_binding.h | 25 ++ .../include/ignite/ignite_binding_context.h | 2 +- .../cpp/core/include/ignite/impl/bindings.h | 24 ++ .../ignite/impl/cluster/cluster_group_impl.h | 31 +- .../ignite/impl/compute/cancelable_impl.h | 70 ++++ .../include/ignite/impl/compute/compute_impl.h | 118 +++++++ .../ignite/impl/compute/compute_job_holder.h | 139 ++++++++ .../ignite/impl/compute/compute_job_result.h | 161 +++++++++ .../ignite/impl/compute/compute_task_holder.h | 213 ++++++++++++ .../include/ignite/impl/ignite_binding_impl.h | 2 + .../include/ignite/impl/ignite_environment.h | 69 ++++ .../cpp/core/include/ignite/impl/ignite_impl.h | 23 +- .../ignite/impl/interop/interop_target.h | 11 +- .../platforms/cpp/core/project/vs/core.vcxproj | 9 + .../cpp/core/project/vs/core.vcxproj.filters | 33 ++ modules/platforms/cpp/core/src/ignite.cpp | 5 + .../src/impl/cluster/cluster_group_impl.cpp | 23 +- .../core/src/impl/compute/cancelable_impl.cpp | 59 ++++ .../cpp/core/src/impl/compute/compute_impl.cpp | 35 ++ .../cpp/core/src/impl/ignite_environment.cpp | 260 +++++++++++++- .../platforms/cpp/core/src/impl/ignite_impl.cpp | 15 +- .../core/src/impl/interop/interop_target.cpp | 20 ++ .../src/impl/transactions/transactions_impl.cpp | 10 - .../platforms/cpp/jni/include/ignite/jni/java.h | 1 + modules/platforms/cpp/jni/src/java.cpp | 10 + 58 files changed, 2493 insertions(+), 291 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/Makefile.am b/modules/platforms/cpp/binary/Makefile.am index d3c2072..499c8a9 100644 --- a/modules/platforms/cpp/binary/Makefile.am +++ b/modules/platforms/cpp/binary/Makefile.am @@ -20,51 +20,52 @@ ACLOCAL_AMFLAGS =-I m4 lib_LTLIBRARIES = libignite-binary.la SUBDIRS = \ - include + include AM_CPPFLAGS = \ - -I$(srcdir)/include \ - -I@top_srcdir@/common/include \ - -I@top_srcdir@/common/os/linux/include \ - -DIGNITE_IMPL \ - -D__STDC_LIMIT_MACROS \ - -D__STDC_CONSTANT_MACROS + -I$(srcdir)/include \ + -I@top_srcdir@/common/include \ + -I@top_srcdir@/common/os/linux/include \ + -DIGNITE_IMPL \ + -D__STDC_LIMIT_MACROS \ + -D__STDC_CONSTANT_MACROS AM_CXXFLAGS = \ - -Wall \ - -std=c++03 + -Wall \ + -std=c++03 libignite_binary_la_LIBADD = \ - @top_srcdir@/common/libignite-common.la + @top_srcdir@/common/libignite-common.la libignite_binary_la_LDFLAGS = \ - -no-undefined \ - -version-info 0:0:0 \ - -release $(PACKAGE_VERSION) + -no-undefined \ + -version-info 0:0:0 \ + -release $(PACKAGE_VERSION) libignite_binary_la_DEPENDENCIES = \ - @top_srcdir@/common/libignite-common.la + @top_srcdir@/common/libignite-common.la libignite_binary_la_SOURCES = \ - src/binary/binary_containers.cpp \ - src/binary/binary_raw_writer.cpp \ - src/binary/binary_writer.cpp \ - src/binary/binary_reader.cpp \ - src/binary/binary_type.cpp \ - src/binary/binary_raw_reader.cpp \ - src/impl/binary/binary_type_manager.cpp \ - src/impl/binary/binary_utils.cpp \ - src/impl/binary/binary_reader_impl.cpp \ - src/impl/binary/binary_type_handler.cpp \ - src/impl/binary/binary_writer_impl.cpp \ - src/impl/binary/binary_schema.cpp \ - src/impl/binary/binary_type_snapshot.cpp \ - src/impl/binary/binary_object_header.cpp \ - src/impl/binary/binary_object_impl.cpp \ - src/impl/binary/binary_field_meta.cpp \ - src/impl/interop/interop_memory.cpp \ - src/impl/interop/interop_output_stream.cpp \ - src/impl/interop/interop_input_stream.cpp + src/binary/binary_containers.cpp \ + src/binary/binary_raw_writer.cpp \ + src/binary/binary_writer.cpp \ + src/binary/binary_reader.cpp \ + src/binary/binary_type.cpp \ + src/binary/binary_raw_reader.cpp \ + src/impl/binary/binary_type_manager.cpp \ + src/impl/binary/binary_type_impl.cpp \ + src/impl/binary/binary_utils.cpp \ + src/impl/binary/binary_reader_impl.cpp \ + src/impl/binary/binary_type_handler.cpp \ + src/impl/binary/binary_writer_impl.cpp \ + src/impl/binary/binary_schema.cpp \ + src/impl/binary/binary_type_snapshot.cpp \ + src/impl/binary/binary_object_header.cpp \ + src/impl/binary/binary_object_impl.cpp \ + src/impl/binary/binary_field_meta.cpp \ + src/impl/interop/interop_memory.cpp \ + src/impl/interop/interop_output_stream.cpp \ + src/impl/interop/interop_input_stream.cpp clean-local: $(RM) *.gcno *.gcda http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/include/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/Makefile.am b/modules/platforms/cpp/binary/include/Makefile.am index a73d5de..85a5516 100644 --- a/modules/platforms/cpp/binary/include/Makefile.am +++ b/modules/platforms/cpp/binary/include/Makefile.am @@ -18,33 +18,34 @@ ACLOCAL_AMFLAGS =-I m4 nobase_include_HEADERS = \ - ignite/binary/binary_raw_reader.h \ - ignite/binary/binary_reader.h \ - ignite/binary/binary_writer.h \ - ignite/binary/binary_raw_writer.h \ - ignite/binary/binary_containers.h \ - ignite/binary/binary.h \ - ignite/binary/binary_consts.h \ - ignite/binary/binary_type.h \ - ignite/binary/binary_object.h \ - ignite/impl/binary/binary_type_handler.h \ - ignite/impl/binary/binary_id_resolver.h \ - ignite/impl/binary/binary_type_manager.h \ - ignite/impl/binary/binary_type_updater.h \ - ignite/impl/binary/binary_common.h \ - ignite/impl/binary/binary_writer_impl.h \ - ignite/impl/binary/binary_field_meta.h \ - ignite/impl/binary/binary_type_snapshot.h \ - ignite/impl/binary/binary_reader_impl.h \ - ignite/impl/binary/binary_schema.h \ - ignite/impl/binary/binary_utils.h \ - ignite/impl/binary/binary_object_header.h \ - ignite/impl/binary/binary_object_impl.h \ - ignite/impl/interop/interop_memory.h \ - ignite/impl/interop/interop.h \ - ignite/impl/interop/interop_stream_position_guard.h \ - ignite/impl/interop/interop_output_stream.h \ - ignite/impl/interop/interop_input_stream.h + ignite/binary/binary_raw_reader.h \ + ignite/binary/binary_reader.h \ + ignite/binary/binary_writer.h \ + ignite/binary/binary_raw_writer.h \ + ignite/binary/binary_containers.h \ + ignite/binary/binary.h \ + ignite/binary/binary_consts.h \ + ignite/binary/binary_type.h \ + ignite/binary/binary_object.h \ + ignite/impl/binary/binary_type_handler.h \ + ignite/impl/binary/binary_id_resolver.h \ + ignite/impl/binary/binary_type_impl.h \ + ignite/impl/binary/binary_type_manager.h \ + ignite/impl/binary/binary_type_updater.h \ + ignite/impl/binary/binary_common.h \ + ignite/impl/binary/binary_writer_impl.h \ + ignite/impl/binary/binary_field_meta.h \ + ignite/impl/binary/binary_type_snapshot.h \ + ignite/impl/binary/binary_reader_impl.h \ + ignite/impl/binary/binary_schema.h \ + ignite/impl/binary/binary_utils.h \ + ignite/impl/binary/binary_object_header.h \ + ignite/impl/binary/binary_object_impl.h \ + ignite/impl/interop/interop_memory.h \ + ignite/impl/interop/interop.h \ + ignite/impl/interop/interop_stream_position_guard.h \ + ignite/impl/interop/interop_output_stream.h \ + ignite/impl/interop/interop_input_stream.h uninstall-hook: if [ -d ${includedir}/ignite ]; then find ${includedir}/ignite -type d -empty -delete; fi http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h index 8fb9dc2..749404a 100644 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h +++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h @@ -28,7 +28,7 @@ #include -#include +#include /** * @def IGNITE_BINARY_TYPE_START(T) http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h new file mode 100644 index 0000000..2548a83 --- /dev/null +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_IMPL_BINARY_BINARY_TYPE_IMPL +#define _IGNITE_IMPL_BINARY_BINARY_TYPE_IMPL + +#include + +#include + +namespace ignite +{ + namespace binary + { + class BinaryReader; + class BinaryWriter; + + template + struct BinaryType; + + template<> + struct BinaryType + { + static int32_t GetTypeId(); + + static void GetTypeName(std::string& dst) + { + dst = "IgniteError"; + } + + static int32_t GetFieldId(const char* name); + + static bool IsNull(const IgniteError& obj) + { + return false; + } + + static void GetNull(IgniteError& dst); + + static void Write(BinaryWriter& writer, const IgniteError& obj); + + static void Read(BinaryReader& reader, IgniteError& dst); + }; + } +} + +#endif //_IGNITE_IMPL_BINARY_BINARY_TYPE_IMPL http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h index d91e2f7..32801ec 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h @@ -59,7 +59,7 @@ namespace ignite * @param metaMgr Type manager. * @param metaHnd Type handler. */ - BinaryWriterImpl(ignite::impl::interop::InteropOutputStream* stream, BinaryIdResolver* idRslvr, + BinaryWriterImpl(interop::InteropOutputStream* stream, BinaryIdResolver* idRslvr, BinaryTypeManager* metaMgr, BinaryTypeHandler* metaHnd, int32_t start); /** @@ -69,7 +69,7 @@ namespace ignite * @param stream Interop stream. * @param metaMgr Type manager. */ - BinaryWriterImpl(ignite::impl::interop::InteropOutputStream* stream, BinaryTypeManager* metaMgr); + BinaryWriterImpl(interop::InteropOutputStream* stream, BinaryTypeManager* metaMgr); /** * Write 8-byte signed integer. Maps to "byte" type in Java. http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/project/vs/binary.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/project/vs/binary.vcxproj b/modules/platforms/cpp/binary/project/vs/binary.vcxproj index 21f1248..5b76f06 100644 --- a/modules/platforms/cpp/binary/project/vs/binary.vcxproj +++ b/modules/platforms/cpp/binary/project/vs/binary.vcxproj @@ -194,6 +194,7 @@ + @@ -218,6 +219,7 @@ + http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters b/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters index 27e4ad8..573b5fa 100644 --- a/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters +++ b/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters @@ -100,6 +100,9 @@ Code\impl\binary + + Code\impl\binary + @@ -159,5 +162,8 @@ Code\impl\binary + + Code\impl\binary + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/binary/src/impl/binary/binary_type_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/src/impl/binary/binary_type_impl.cpp b/modules/platforms/cpp/binary/src/impl/binary/binary_type_impl.cpp new file mode 100644 index 0000000..59a4dda --- /dev/null +++ b/modules/platforms/cpp/binary/src/impl/binary/binary_type_impl.cpp @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +namespace ignite +{ + namespace binary + { + int32_t BinaryType::GetTypeId() + { + return GetBinaryStringHashCode("IgniteError"); + } + + int32_t BinaryType::GetFieldId(const char* name) + { + return GetBinaryStringHashCode(name); + } + + void BinaryType::GetNull(IgniteError& dst) + { + dst = IgniteError(0, 0); + } + + void BinaryType::Write(BinaryWriter& writer, const IgniteError& obj) + { + BinaryRawWriter raw = writer.RawWriter(); + + raw.WriteInt32(obj.GetCode()); + raw.WriteString(obj.GetText(), static_cast(strlen(obj.GetText()))); + } + + void BinaryType::Read(BinaryReader& reader, IgniteError& dst) + { + BinaryRawReader raw = reader.RawReader(); + + int32_t code = raw.ReadInt32(); + std::string msg = raw.ReadObject(); + + dst = IgniteError(code, msg.c_str()); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/Makefile.am b/modules/platforms/cpp/common/Makefile.am index 8515d5b..374f417 100644 --- a/modules/platforms/cpp/common/Makefile.am +++ b/modules/platforms/cpp/common/Makefile.am @@ -20,41 +20,41 @@ ACLOCAL_AMFLAGS =-I m4 lib_LTLIBRARIES = libignite-common.la SUBDIRS = \ - include \ - os/linux/include + include \ + os/linux/include AM_CPPFLAGS = \ - -I$(srcdir)/include \ - -I$(srcdir)/os/linux/include \ - -DIGNITE_IMPL \ - -D__STDC_LIMIT_MACROS \ - -D__STDC_CONSTANT_MACROS + -I$(srcdir)/include \ + -I$(srcdir)/os/linux/include \ + -DIGNITE_IMPL \ + -D__STDC_LIMIT_MACROS \ + -D__STDC_CONSTANT_MACROS AM_CXXFLAGS = \ - -Wall \ - -std=c++03 + -Wall \ + -std=c++03 libignite_common_la_LDFLAGS = \ - -no-undefined \ - -L/usr/local/lib \ - -ldl \ - -version-info 0:0:0 \ - -release $(PACKAGE_VERSION) + -no-undefined \ + -L/usr/local/lib \ + -ldl \ + -version-info 0:0:0 \ + -release $(PACKAGE_VERSION) libignite_common_la_SOURCES = \ - os/linux/src/common/concurrent_os.cpp \ - os/linux/src/common/platform_utils.cpp \ - os/linux/src/common/dynamic_load_os.cpp \ - src/common/big_integer.cpp \ - src/common/concurrent.cpp \ - src/common/decimal.cpp \ - src/common/bits.cpp \ - src/common/utils.cpp \ - src/date.cpp \ - src/ignite_error.cpp \ - src/guid.cpp \ - src/timestamp.cpp \ - src/time.cpp + os/linux/src/common/concurrent_os.cpp \ + os/linux/src/common/platform_utils.cpp \ + os/linux/src/common/dynamic_load_os.cpp \ + src/common/big_integer.cpp \ + src/common/concurrent.cpp \ + src/common/decimal.cpp \ + src/common/bits.cpp \ + src/common/utils.cpp \ + src/date.cpp \ + src/ignite_error.cpp \ + src/guid.cpp \ + src/timestamp.cpp \ + src/time.cpp clean-local: $(RM) *.gcno *.gcda http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/include/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/Makefile.am b/modules/platforms/cpp/common/include/Makefile.am index 64f0c46..f115c94 100644 --- a/modules/platforms/cpp/common/include/Makefile.am +++ b/modules/platforms/cpp/common/include/Makefile.am @@ -20,6 +20,7 @@ ACLOCAL_AMFLAGS =-I m4 nobase_include_HEADERS = \ ignite/common/big_integer.h \ ignite/common/bits.h \ + ignite/common/cancelable.h \ ignite/common/concurrent.h \ ignite/common/decimal.h \ ignite/common/default_allocator.h \ http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/include/ignite/common/cancelable.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/cancelable.h b/modules/platforms/cpp/common/include/ignite/common/cancelable.h new file mode 100644 index 0000000..ab0c126 --- /dev/null +++ b/modules/platforms/cpp/common/include/ignite/common/cancelable.h @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Declares ignite::common::Cancelable class. + */ + +#ifndef _IGNITE_COMMON_CANCELABLE +#define _IGNITE_COMMON_CANCELABLE + +#include + +namespace ignite +{ + namespace common + { + /** + * Cancelable. + */ + class IGNITE_IMPORT_EXPORT Cancelable + { + public: + /** + * Default constructor. + */ + Cancelable() + { + // No-op. + } + + /** + * Destructor. + */ + virtual ~Cancelable() + { + // No-op. + } + + /** + * Cancels the operation. + */ + virtual void Cancel() = 0; + + private: + IGNITE_NO_COPY_ASSIGNMENT(Cancelable); + }; + } +} + +#endif //_IGNITE_COMMON_CANCELABLE http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/include/ignite/common/promise.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/promise.h b/modules/platforms/cpp/common/include/ignite/common/promise.h index 548b76b..2e6152f 100644 --- a/modules/platforms/cpp/common/include/ignite/common/promise.h +++ b/modules/platforms/cpp/common/include/ignite/common/promise.h @@ -111,9 +111,18 @@ namespace ignite state.Get()->SetError(err); } + /** + * Set cancel target. + */ + void SetCancelTarget(std::auto_ptr& target) + { + state.Get()->SetCancelTarget(target); + } + private: IGNITE_NO_COPY_ASSIGNMENT(Promise); + /** Shared state. */ concurrent::SharedPointer< SharedState > state; }; @@ -190,9 +199,18 @@ namespace ignite state.Get()->SetError(err); } + /** + * Set cancel target. + */ + void SetCancelTarget(std::auto_ptr& target) + { + state.Get()->SetCancelTarget(target); + } + private: IGNITE_NO_COPY_ASSIGNMENT(Promise); + /** Shared state. */ concurrent::SharedPointer< SharedState > state; }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/include/ignite/common/shared_state.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/shared_state.h b/modules/platforms/cpp/common/include/ignite/common/shared_state.h index 8886532..d223753 100644 --- a/modules/platforms/cpp/common/include/ignite/common/shared_state.h +++ b/modules/platforms/cpp/common/include/ignite/common/shared_state.h @@ -23,8 +23,11 @@ #ifndef _IGNITE_SHARED_STATE #define _IGNITE_SHARED_STATE +#include + #include #include +#include #include namespace ignite @@ -162,9 +165,33 @@ namespace ignite throw error; } + /** + * Set cancel target. + */ + void SetCancelTarget(std::auto_ptr& target) + { + concurrent::CsLockGuard guard(mutex); + + cancelTarget = target; + } + + /** + * Cancel related operation. + */ + void Cancel() + { + concurrent::CsLockGuard guard(mutex); + + if (cancelTarget.get()) + cancelTarget->Cancel(); + } + private: IGNITE_NO_COPY_ASSIGNMENT(SharedState); + /** Cancel target. */ + std::auto_ptr cancelTarget; + /** Value. */ std::auto_ptr value; @@ -310,9 +337,33 @@ namespace ignite throw error; } + /** + * Set cancel target. + */ + void SetCancelTarget(std::auto_ptr& target) + { + concurrent::CsLockGuard guard(mutex); + + cancelTarget = target; + } + + /** + * Cancel related operation. + */ + void Cancel() + { + concurrent::CsLockGuard guard(mutex); + + if (cancelTarget.get()) + cancelTarget->Cancel(); + } + private: IGNITE_NO_COPY_ASSIGNMENT(SharedState); + /** Cancel target. */ + std::auto_ptr cancelTarget; + /** Marker. */ bool done; http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/include/ignite/future.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/future.h b/modules/platforms/cpp/common/include/ignite/future.h index 5c42e55..f709797 100644 --- a/modules/platforms/cpp/common/include/ignite/future.h +++ b/modules/platforms/cpp/common/include/ignite/future.h @@ -85,7 +85,7 @@ namespace ignite assert(state0 != 0); - state.Get()->Wait(); + state0->Wait(); } /** @@ -101,7 +101,7 @@ namespace ignite assert(state0 != 0); - return state.Get()->WaitFor(msTimeout); + return state0->WaitFor(msTimeout); } /** @@ -117,7 +117,31 @@ namespace ignite assert(state0 != 0); - return state.Get()->GetValue(); + return state0->GetValue(); + } + + /** + * Cancel related operation. + */ + void Cancel() + { + common::SharedState* state0 = state.Get(); + + assert(state0 != 0); + + state0->Cancel(); + } + + /** + * Check if the future ready. + */ + bool IsReady() + { + common::SharedState* state0 = state.Get(); + + assert(state0 != 0); + + return state0->IsSet(); } private: @@ -182,7 +206,7 @@ namespace ignite assert(state0 != 0); - state.Get()->Wait(); + state0->Wait(); } /** @@ -198,7 +222,7 @@ namespace ignite assert(state0 != 0); - return state.Get()->WaitFor(msTimeout); + return state0->WaitFor(msTimeout); } /** @@ -213,7 +237,31 @@ namespace ignite assert(state0 != 0); - state.Get()->GetValue(); + state0->GetValue(); + } + + /** + * Cancel related operation. + */ + void Cancel() + { + common::SharedState* state0 = state.Get(); + + assert(state0 != 0); + + state0->Cancel(); + } + + /** + * Check if the future ready. + */ + bool IsReady() + { + common::SharedState* state0 = state.Get(); + + assert(state0 != 0); + + return state0->IsSet(); } private: http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/include/ignite/ignite_error.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/ignite_error.h b/modules/platforms/cpp/common/include/ignite/ignite_error.h index 7818dd2..59bb0c4 100644 --- a/modules/platforms/cpp/common/include/ignite/ignite_error.h +++ b/modules/platforms/cpp/common/include/ignite/ignite_error.h @@ -124,6 +124,9 @@ namespace ignite /** Binary error. */ static const int IGNITE_ERR_BINARY = 1002; + /** Standard library exception. */ + static const int IGNITE_ERR_STD = 1003; + /** Generic %Ignite error. */ static const int IGNITE_ERR_GENERIC = 2000; http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/project/vs/common.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/common.vcxproj b/modules/platforms/cpp/common/project/vs/common.vcxproj index 9f32461..07c3f50 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj @@ -166,6 +166,7 @@ + http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/common/project/vs/common.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/common.vcxproj.filters b/modules/platforms/cpp/common/project/vs/common.vcxproj.filters index 4daf3aa..020d32b 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj.filters +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj.filters @@ -76,6 +76,9 @@ Code\common + + Code\common + http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/Makefile.am b/modules/platforms/cpp/core-test/Makefile.am index 11f4d1a..f87effd 100644 --- a/modules/platforms/cpp/core-test/Makefile.am +++ b/modules/platforms/cpp/core-test/Makefile.am @@ -20,67 +20,68 @@ ACLOCAL_AMFLAGS =-I m4 noinst_PROGRAMS = ignite-tests SUBDIRS = \ - include + include AM_CPPFLAGS = \ - -I$(srcdir)/include \ - -I@top_srcdir@/core/include \ - -I@top_srcdir@/core/os/linux/include \ - -I@top_srcdir@/common/include \ - -I@top_srcdir@/common/os/linux/include \ - -I@top_srcdir@/binary/include \ - -I@top_srcdir@/jni/include \ - -I@top_srcdir@/jni/os/linux/include \ - -I$(JAVA_HOME)/include \ - -I$(JAVA_HOME)/include/linux \ - -DIGNITE_IMPL \ - -D__STDC_LIMIT_MACROS \ - -D__STDC_CONSTANT_MACROS + -I$(srcdir)/include \ + -I@top_srcdir@/core/include \ + -I@top_srcdir@/core/os/linux/include \ + -I@top_srcdir@/common/include \ + -I@top_srcdir@/common/os/linux/include \ + -I@top_srcdir@/binary/include \ + -I@top_srcdir@/jni/include \ + -I@top_srcdir@/jni/os/linux/include \ + -I$(JAVA_HOME)/include \ + -I$(JAVA_HOME)/include/linux \ + -DIGNITE_IMPL \ + -D__STDC_LIMIT_MACROS \ + -D__STDC_CONSTANT_MACROS AM_CXXFLAGS = \ - -Wall \ - -std=c++03 + -Wall \ + -std=c++03 ignite_tests_LDADD = \ - @top_srcdir@/core/libignite.la \ - -lpthread \ - -lboost_thread \ - -lboost_system \ - -lboost_chrono + @top_srcdir@/core/libignite.la \ + -lpthread \ + -lboost_thread \ + -lboost_system \ + -lboost_chrono ignite_tests_LDFLAGS = \ - -static-libtool-libs \ - -rdynamic + -static-libtool-libs \ + -rdynamic ignite_tests_SOURCES = \ - src/reference_test.cpp \ - src/bits_test.cpp \ + src/reference_test.cpp \ + src/bits_test.cpp \ src/binary_identity_resolver_test.cpp \ - src/cache_test.cpp \ - src/cache_query_test.cpp \ - src/cache_store_test.cpp \ - src/continuous_query_test.cpp \ - src/concurrent_test.cpp \ - src/ignition_test.cpp \ - src/interop_memory_test.cpp \ - src/interop_test.cpp \ - src/cluster_test.cpp \ - src/cache_invoke_test.cpp \ - src/handle_registry_test.cpp \ - src/ignite_error_test.cpp \ - src/binary_test_defs.cpp \ - src/binary_object_test.cpp \ - src/binary_reader_writer_raw_test.cpp \ - src/binary_reader_writer_test.cpp \ - src/binary_session_test.cpp \ - src/date_time_test.cpp \ - src/decimal_test.cpp \ - src/dynamic_size_array_test.cpp \ - src/fixed_size_array_test.cpp \ - src/future_test.cpp \ - src/transactions_test.cpp \ - src/teamcity_messages.cpp \ - src/teamcity_boost.cpp \ + src/cache_test.cpp \ + src/cache_query_test.cpp \ + src/cache_store_test.cpp \ + src/continuous_query_test.cpp \ + src/concurrent_test.cpp \ + src/compute_test.cpp \ + src/ignition_test.cpp \ + src/interop_memory_test.cpp \ + src/interop_test.cpp \ + src/cluster_test.cpp \ + src/cache_invoke_test.cpp \ + src/handle_registry_test.cpp \ + src/ignite_error_test.cpp \ + src/binary_test_defs.cpp \ + src/binary_object_test.cpp \ + src/binary_reader_writer_raw_test.cpp \ + src/binary_reader_writer_test.cpp \ + src/binary_session_test.cpp \ + src/date_time_test.cpp \ + src/decimal_test.cpp \ + src/dynamic_size_array_test.cpp \ + src/fixed_size_array_test.cpp \ + src/future_test.cpp \ + src/transactions_test.cpp \ + src/teamcity_messages.cpp \ + src/teamcity_boost.cpp \ src/test_utils.cpp run-check: check http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/include/ignite/test_utils.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/include/ignite/test_utils.h b/modules/platforms/cpp/core-test/include/ignite/test_utils.h index 67fda95..aa91458 100644 --- a/modules/platforms/cpp/core-test/include/ignite/test_utils.h +++ b/modules/platforms/cpp/core-test/include/ignite/test_utils.h @@ -22,6 +22,11 @@ namespace ignite_test { + enum + { + TEST_ERROR = 424242 + }; + /** * Initialize configuration for a node. * @@ -65,9 +70,24 @@ namespace ignite_test * @param err Error. * @return True if the error is generic. */ - inline bool IsGenericError(const ignite::IgniteError& err) + bool IsGenericError(const ignite::IgniteError& err); + + /** + * Check if the error is generic. + * + * @param err Error. + * @return True if the error is generic. + */ + bool IsTestError(const ignite::IgniteError& err); + + /** + * Make test error. + * + * @return Test error. + */ + inline ignite::IgniteError MakeTestError() { - return err.GetCode() == ignite::IgniteError::IGNITE_ERR_GENERIC; + return ignite::IgniteError(TEST_ERROR, "Test error"); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj index 51ae5d41..f2f6a1b 100644 --- a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj +++ b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj @@ -64,6 +64,7 @@ + http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters index ebccc7f..d58ef97 100644 --- a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters +++ b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters @@ -88,6 +88,9 @@ Code + + Code + @@ -166,9 +169,6 @@ Configs - - Configs - Configs @@ -178,9 +178,5 @@ Configs - - Configs - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp b/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp index 0c30af8..55fca85 100644 --- a/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp +++ b/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp @@ -379,7 +379,7 @@ namespace ignite IGNITE_EXPORTED_CALL void IgniteModuleInit(ignite::IgniteBindingContext& context) { - IgniteBinding binding = context.GetBingding(); + IgniteBinding binding = context.GetBinding(); binding.RegisterCacheEntryProcessor(); binding.RegisterCacheEntryProcessor(); http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/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 754fe7e..e9d6728 100644 --- a/modules/platforms/cpp/core-test/src/cluster_test.cpp +++ b/modules/platforms/cpp/core-test/src/cluster_test.cpp @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(IgniteImplForServers) IgniteError err; - BOOST_REQUIRE(clusterGroup.Get()->ForServers(err).IsValid()); + BOOST_REQUIRE(clusterGroup.Get()->ForServers().IsValid()); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/src/compute_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/compute_test.cpp b/modules/platforms/cpp/core-test/src/compute_test.cpp new file mode 100644 index 0000000..d3b1183 --- /dev/null +++ b/modules/platforms/cpp/core-test/src/compute_test.cpp @@ -0,0 +1,337 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _MSC_VER + #define BOOST_TEST_DYN_LINK +#endif + +#include +#include +#include + +#include +#include + +#include + +using namespace ignite; +using namespace ignite::compute; +using namespace ignite::common::concurrent; +using namespace ignite_test; + +using namespace boost::unit_test; + +/* + * Test setup fixture. + */ +struct ComputeTestSuiteFixture +{ + Ignite node; + + Ignite MakeNode(const char* name) + { +#ifdef IGNITE_TESTS_32 + const char* config = "cache-test-32.xml"; +#else + const char* config = "cache-test.xml"; +#endif + return StartNode(config, name); + } + + /* + * Constructor. + */ + ComputeTestSuiteFixture() : + node(MakeNode("ComputeNode1")) + { + // No-op. + } + + /* + * Destructor. + */ + ~ComputeTestSuiteFixture() + { + Ignition::StopAll(true); + } +}; + +struct Func1 : ComputeFunc +{ + Func1() : + a(), b(), err() + { + // No-op. + } + + Func1(int32_t a, int32_t b) : + a(a), b(b), err() + { + // No-op. + } + + Func1(IgniteError err) : + a(), b(), err(err) + { + // No-op. + } + + virtual std::string Call() + { + if (err.GetCode() != IgniteError::IGNITE_SUCCESS) + throw err; + + std::stringstream tmp; + + tmp << a << '.' << b; + + return tmp.str(); + } + + int32_t a; + int32_t b; + IgniteError err; +}; + +struct Func2 : ComputeFunc +{ + Func2() : + a(), b(), err() + { + // No-op. + } + + Func2(int32_t a, int32_t b) : + a(a), b(b), err() + { + // No-op. + } + + Func2(IgniteError err) : + a(), b(), err(err) + { + // No-op. + } + + virtual std::string Call() + { + boost::this_thread::sleep_for(boost::chrono::milliseconds(200)); + + if (err.GetCode() != IgniteError::IGNITE_SUCCESS) + throw err; + + std::stringstream tmp; + + tmp << a << '.' << b; + + return tmp.str(); + } + + int32_t a; + int32_t b; + IgniteError err; +}; + +namespace ignite +{ + namespace binary + { + template<> + struct BinaryType + { + static int32_t GetTypeId() + { + return GetBinaryStringHashCode("Func1"); + } + + static void GetTypeName(std::string& dst) + { + dst = "Func1"; + } + + static int32_t GetFieldId(const char* name) + { + return GetBinaryStringHashCode(name); + } + + static bool IsNull(const Func1& obj) + { + return false; + } + + static void GetNull(Func1& dst) + { + dst = Func1(0, 0); + } + + static void Write(BinaryWriter& writer, const Func1& obj) + { + writer.WriteInt32("a", obj.a); + writer.WriteInt32("b", obj.b); + writer.WriteObject("err", obj.err); + } + + static void Read(BinaryReader& reader, Func1& dst) + { + dst.a = reader.ReadInt32("a"); + dst.b = reader.ReadInt32("b"); + dst.err = reader.ReadObject("err"); + } + }; + + template<> + struct BinaryType + { + static int32_t GetTypeId() + { + return GetBinaryStringHashCode("Func2"); + } + + static void GetTypeName(std::string& dst) + { + dst = "Func2"; + } + + static int32_t GetFieldId(const char* name) + { + return GetBinaryStringHashCode(name); + } + + static bool IsNull(const Func2& obj) + { + return false; + } + + static void GetNull(Func2& dst) + { + dst = Func2(0, 0); + } + + static void Write(BinaryWriter& writer, const Func2& obj) + { + writer.WriteInt32("a", obj.a); + writer.WriteInt32("b", obj.b); + writer.WriteObject("err", obj.err); + } + + static void Read(BinaryReader& reader, Func2& dst) + { + dst.a = reader.ReadInt32("a"); + dst.b = reader.ReadInt32("b"); + dst.err = reader.ReadObject("err"); + } + }; + } +} + +IGNITE_EXPORTED_CALL void IgniteModuleInit1(IgniteBindingContext& context) +{ + IgniteBinding binding = context.GetBinding(); + + binding.RegisterComputeFunc(); + binding.RegisterComputeFunc(); +} + +BOOST_FIXTURE_TEST_SUITE(ComputeTestSuite, ComputeTestSuiteFixture) + +BOOST_AUTO_TEST_CASE(IgniteCallSyncLocal) +{ + Compute compute = node.GetCompute(); + + BOOST_CHECKPOINT("Making Call"); + std::string res = compute.Call(Func1(8, 5)); + + BOOST_CHECK_EQUAL(res, "8.5"); +} + +BOOST_AUTO_TEST_CASE(IgniteCallAsyncLocal) +{ + Compute compute = node.GetCompute(); + + BOOST_CHECKPOINT("Making Call"); + Future res = compute.CallAsync(Func2(312, 245)); + + BOOST_CHECK(!res.IsReady()); + + BOOST_CHECKPOINT("Waiting with timeout"); + res.WaitFor(100); + + BOOST_CHECK(!res.IsReady()); + + BOOST_CHECK_EQUAL(res.GetValue(), "312.245"); +} + +BOOST_AUTO_TEST_CASE(IgniteCallSyncLocalError) +{ + Compute compute = node.GetCompute(); + + BOOST_CHECKPOINT("Making Call"); + + BOOST_CHECK_EXCEPTION(compute.Call(Func1(MakeTestError())), IgniteError, IsTestError); +} + +BOOST_AUTO_TEST_CASE(IgniteCallAsyncLocalError) +{ + Compute compute = node.GetCompute(); + + BOOST_CHECKPOINT("Making Call"); + Future res = compute.CallAsync(Func2(MakeTestError())); + + BOOST_CHECK(!res.IsReady()); + + BOOST_CHECKPOINT("Waiting with timeout"); + res.WaitFor(100); + + BOOST_CHECK(!res.IsReady()); + + BOOST_CHECK_EXCEPTION(res.GetValue(), IgniteError, IsTestError); +} + +BOOST_AUTO_TEST_CASE(IgniteCallTestRemote) +{ + Ignite node2 = MakeNode("ComputeNode2"); + Compute compute = node.GetCompute(); + + BOOST_CHECKPOINT("Making Call"); + compute.CallAsync(Func2(8, 5)); + + std::string res = compute.Call(Func1(42, 24)); + + BOOST_CHECK_EQUAL(res, "42.24"); +} + +BOOST_AUTO_TEST_CASE(IgniteCallTestRemoteError) +{ + Ignite node2 = MakeNode("ComputeNode2"); + Compute compute = node.GetCompute(); + + BOOST_CHECKPOINT("Making Call"); + compute.CallAsync(Func2(8, 5)); + + Future res = compute.CallAsync(Func2(MakeTestError())); + + BOOST_CHECK(!res.IsReady()); + + BOOST_CHECKPOINT("Waiting with timeout"); + res.WaitFor(100); + + BOOST_CHECK(!res.IsReady()); + + BOOST_CHECK_EXCEPTION(res.GetValue(), IgniteError, IsTestError); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/src/continuous_query_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp b/modules/platforms/cpp/core-test/src/continuous_query_test.cpp index e092728..b869eb6 100644 --- a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp +++ b/modules/platforms/cpp/core-test/src/continuous_query_test.cpp @@ -371,7 +371,7 @@ void CheckEvents(Cache& cache, Listener& lsnr) IGNITE_EXPORTED_CALL void IgniteModuleInit0(ignite::IgniteBindingContext& context) { - IgniteBinding binding = context.GetBingding(); + IgniteBinding binding = context.GetBinding(); binding.RegisterCacheEntryEventFilter< RangeFilter >(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core-test/src/test_utils.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/test_utils.cpp b/modules/platforms/cpp/core-test/src/test_utils.cpp index 7323028..c6e4454 100644 --- a/modules/platforms/cpp/core-test/src/test_utils.cpp +++ b/modules/platforms/cpp/core-test/src/test_utils.cpp @@ -83,4 +83,13 @@ namespace ignite_test return Ignition::Start(cfg, name); } + bool IsGenericError(const ignite::IgniteError& err) + { + return err.GetCode() == ignite::IgniteError::IGNITE_ERR_GENERIC; + } + + bool IsTestError(const ignite::IgniteError& err) + { + return err.GetCode() == TEST_ERROR; + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/Makefile.am b/modules/platforms/cpp/core/Makefile.am index 4de45d3..1c970e8 100644 --- a/modules/platforms/cpp/core/Makefile.am +++ b/modules/platforms/cpp/core/Makefile.am @@ -20,58 +20,60 @@ ACLOCAL_AMFLAGS =-I m4 lib_LTLIBRARIES = libignite.la SUBDIRS = \ - include + include AM_CPPFLAGS = \ - -I$(srcdir)/include \ - -I@top_srcdir@/common/include \ - -I@top_srcdir@/common/os/linux/include \ - -I@top_srcdir@/binary/include \ - -I@top_srcdir@/jni/include \ - -I@top_srcdir@/jni/os/linux/include \ - -I$(JAVA_HOME)/include \ - -I$(JAVA_HOME)/include/linux \ - -DIGNITE_IMPL \ - -D__STDC_LIMIT_MACROS \ - -D__STDC_CONSTANT_MACROS + -I$(srcdir)/include \ + -I@top_srcdir@/common/include \ + -I@top_srcdir@/common/os/linux/include \ + -I@top_srcdir@/binary/include \ + -I@top_srcdir@/jni/include \ + -I@top_srcdir@/jni/os/linux/include \ + -I$(JAVA_HOME)/include \ + -I$(JAVA_HOME)/include/linux \ + -DIGNITE_IMPL \ + -D__STDC_LIMIT_MACROS \ + -D__STDC_CONSTANT_MACROS AM_CXXFLAGS = \ - -Wall \ - -std=c++03 + -Wall \ + -std=c++03 libignite_la_LIBADD = \ - @top_srcdir@/jni/libignite-jni.la \ - @top_srcdir@/binary/libignite-binary.la + @top_srcdir@/jni/libignite-jni.la \ + @top_srcdir@/binary/libignite-binary.la libignite_la_LDFLAGS = \ - -no-undefined \ - -ldl \ - -version-info 0:0:0 \ - -release $(PACKAGE_VERSION) + -no-undefined \ + -ldl \ + -version-info 0:0:0 \ + -release $(PACKAGE_VERSION) libignite_la_DEPENDENCIES = \ - @top_srcdir@/jni/libignite-jni.la \ - @top_srcdir@/binary/libignite-binary.la + @top_srcdir@/jni/libignite-jni.la \ + @top_srcdir@/binary/libignite-binary.la libignite_la_SOURCES = \ - src/ignite.cpp \ - src/ignition.cpp \ - src/impl/ignite_environment.cpp \ - src/impl/binary/binary_type_updater_impl.cpp \ - src/impl/handle_registry.cpp \ - src/impl/cache/query/continuous/continuous_query_handle_impl.cpp \ - src/impl/cache/query/query_impl.cpp \ - src/impl/cache/cache_impl.cpp \ - src/impl/cache/query/query_batch.cpp \ - src/impl/interop/interop_external_memory.cpp \ - src/impl/interop/interop_target.cpp \ - src/impl/transactions/transaction_impl.cpp \ - src/impl/transactions/transactions_impl.cpp \ - src/impl/cluster/cluster_group_impl.cpp \ - src/impl/ignite_impl.cpp \ - src/impl/ignite_binding_impl.cpp \ - src/transactions/transaction.cpp \ - src/transactions/transactions.cpp + src/ignite.cpp \ + src/ignition.cpp \ + src/impl/ignite_environment.cpp \ + src/impl/binary/binary_type_updater_impl.cpp \ + src/impl/handle_registry.cpp \ + src/impl/cache/query/continuous/continuous_query_handle_impl.cpp \ + src/impl/cache/query/query_impl.cpp \ + src/impl/cache/cache_impl.cpp \ + src/impl/cache/query/query_batch.cpp \ + src/impl/interop/interop_external_memory.cpp \ + src/impl/interop/interop_target.cpp \ + src/impl/transactions/transaction_impl.cpp \ + src/impl/transactions/transactions_impl.cpp \ + src/impl/cluster/cluster_group_impl.cpp \ + src/impl/compute/cancelable_impl.cpp \ + src/impl/compute/compute_impl.cpp \ + src/impl/ignite_impl.cpp \ + src/impl/ignite_binding_impl.cpp \ + src/transactions/transaction.cpp \ + src/transactions/transactions.cpp pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = $(srcdir)/ignite.pc http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/Makefile.am b/modules/platforms/cpp/core/include/Makefile.am index 0e9a7ec..50772cb 100644 --- a/modules/platforms/cpp/core/include/Makefile.am +++ b/modules/platforms/cpp/core/include/Makefile.am @@ -18,56 +18,63 @@ ACLOCAL_AMFLAGS =-I m4 nobase_include_HEADERS = \ - ignite/cache/cache.h \ - ignite/cache/cache_entry.h \ - ignite/cache/cache_entry_processor.h \ - ignite/cache/cache_peek_mode.h \ - ignite/cache/event/cache_entry_event.h \ - ignite/cache/event/cache_entry_event_filter.h \ - ignite/cache/event/cache_entry_event_listener.h \ - ignite/cache/mutable_cache_entry.h \ - ignite/cache/query/continuous/continuous_query.h \ - ignite/cache/query/continuous/continuous_query_handle.h \ - ignite/cache/query/query.h \ - ignite/cache/query/query_cursor.h \ - ignite/cache/query/query_fields_cursor.h \ - ignite/cache/query/query_fields_row.h \ - ignite/cache/query/query_scan.h \ - ignite/cache/query/query_sql.h \ - ignite/cache/query/query_sql_fields.h \ - ignite/cache/query/query_text.h \ - ignite/ignite.h \ - ignite/ignite_binding.h \ - ignite/ignite_binding_context.h \ - ignite/ignite_configuration.h \ - ignite/ignition.h \ - ignite/impl/binary/binary_type_updater_impl.h \ - ignite/impl/bindings.h \ - ignite/impl/cache/cache_entry_processor_holder.h \ - ignite/impl/cache/cache_impl.h \ - ignite/impl/cache/event/cache_entry_event_filter_base.h \ - ignite/impl/cache/event/cache_entry_event_filter_holder.h \ - ignite/impl/cache/query/continuous/continuous_query_handle_impl.h \ - ignite/impl/cache/query/continuous/continuous_query_impl.h \ - ignite/impl/cache/query/query_argument.h \ - ignite/impl/cache/query/query_batch.h \ - ignite/impl/cache/query/query_fields_row_impl.h \ - ignite/impl/cache/query/query_impl.h \ - ignite/impl/cluster/cluster_group_impl.h \ - ignite/impl/handle_registry.h \ - ignite/impl/ignite_binding_impl.h \ - ignite/impl/ignite_environment.h \ - ignite/impl/ignite_impl.h \ - ignite/impl/interop/interop_external_memory.h \ - ignite/impl/interop/interop_target.h \ - ignite/impl/module_manager.h \ - ignite/impl/operations.h \ - ignite/impl/transactions/transactions_impl.h \ - ignite/impl/transactions/transaction_impl.h \ - ignite/transactions/transaction.h \ - ignite/transactions/transactions.h \ - ignite/transactions/transaction_consts.h \ - ignite/transactions/transaction_metrics.h + ignite/cache/cache.h \ + ignite/cache/cache_entry.h \ + ignite/cache/cache_entry_processor.h \ + ignite/cache/cache_peek_mode.h \ + ignite/cache/event/cache_entry_event.h \ + ignite/cache/event/cache_entry_event_filter.h \ + ignite/cache/event/cache_entry_event_listener.h \ + ignite/cache/mutable_cache_entry.h \ + ignite/cache/query/continuous/continuous_query.h \ + ignite/cache/query/continuous/continuous_query_handle.h \ + ignite/cache/query/query.h \ + ignite/cache/query/query_cursor.h \ + ignite/cache/query/query_fields_cursor.h \ + ignite/cache/query/query_fields_row.h \ + ignite/cache/query/query_scan.h \ + ignite/cache/query/query_sql.h \ + ignite/cache/query/query_sql_fields.h \ + ignite/cache/query/query_text.h \ + ignite/compute/compute.h \ + ignite/compute/compute_func.h \ + ignite/ignite.h \ + ignite/ignite_binding.h \ + ignite/ignite_binding_context.h \ + ignite/ignite_configuration.h \ + ignite/ignition.h \ + ignite/impl/binary/binary_type_updater_impl.h \ + ignite/impl/bindings.h \ + ignite/impl/cache/cache_entry_processor_holder.h \ + ignite/impl/cache/cache_impl.h \ + ignite/impl/cache/event/cache_entry_event_filter_base.h \ + ignite/impl/cache/event/cache_entry_event_filter_holder.h \ + ignite/impl/cache/query/continuous/continuous_query_handle_impl.h \ + ignite/impl/cache/query/continuous/continuous_query_impl.h \ + ignite/impl/cache/query/query_argument.h \ + ignite/impl/cache/query/query_batch.h \ + ignite/impl/cache/query/query_fields_row_impl.h \ + ignite/impl/cache/query/query_impl.h \ + ignite/impl/cluster/cluster_group_impl.h \ + ignite/impl/compute/cancelable_impl.h \ + ignite/impl/compute/compute_impl.h \ + ignite/impl/compute/compute_job_holder.h \ + ignite/impl/compute/compute_job_result.h \ + ignite/impl/compute/compute_task_holder.h \ + ignite/impl/handle_registry.h \ + ignite/impl/ignite_binding_impl.h \ + ignite/impl/ignite_environment.h \ + ignite/impl/ignite_impl.h \ + ignite/impl/interop/interop_external_memory.h \ + ignite/impl/interop/interop_target.h \ + ignite/impl/module_manager.h \ + ignite/impl/operations.h \ + ignite/impl/transactions/transactions_impl.h \ + ignite/impl/transactions/transaction_impl.h \ + ignite/transactions/transaction.h \ + ignite/transactions/transactions.h \ + ignite/transactions/transaction_consts.h \ + ignite/transactions/transaction_metrics.h uninstall-hook: if [ -d ${includedir}/ignite ]; then find ${includedir}/ignite -type d -empty -delete; fi http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/cache/cache.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/cache/cache.h b/modules/platforms/cpp/core/include/ignite/cache/cache.h index e37e806..b16d7f5 100644 --- a/modules/platforms/cpp/core/include/ignite/cache/cache.h +++ b/modules/platforms/cpp/core/include/ignite/cache/cache.h @@ -1529,7 +1529,7 @@ namespace ignite * @code{.cpp} * IGNITE_EXPORTED_CALL void IgniteModuleInit(ignite::IgniteBindingContext& context) * { - * IgniteBinding binding = context.GetBingding(); + * IgniteBinding binding = context.GetBinding(); * * binding.RegisterCacheEntryProcessor(); * binding.RegisterCacheEntryProcessor(); @@ -1582,7 +1582,7 @@ namespace ignite * @code{.cpp} * IGNITE_EXPORTED_CALL void IgniteModuleInit(ignite::IgniteBindingContext& context) * { - * IgniteBinding binding = context.GetBingding(); + * IgniteBinding binding = context.GetBinding(); * * binding.RegisterCacheEntryProcessor(); * binding.RegisterCacheEntryProcessor(); http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/cache/query/query.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/cache/query/query.h b/modules/platforms/cpp/core/include/ignite/cache/query/query.h index b2991e4..a5a5c1f 100644 --- a/modules/platforms/cpp/core/include/ignite/cache/query/query.h +++ b/modules/platforms/cpp/core/include/ignite/cache/query/query.h @@ -23,7 +23,6 @@ #ifndef _IGNITE_CACHE_QUERY_QUERY #define _IGNITE_CACHE_QUERY_QUERY -#include "ignite/cache/query/query_argument.h" #include "ignite/cache/query/query_cursor.h" #include "ignite/cache/query/query_scan.h" #include "ignite/cache/query/query_sql.h" http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/compute/compute.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/compute/compute.h b/modules/platforms/cpp/core/include/ignite/compute/compute.h new file mode 100644 index 0000000..b079569 --- /dev/null +++ b/modules/platforms/cpp/core/include/ignite/compute/compute.h @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Declares ignite::compute::Compute class. + */ + +#ifndef _IGNITE_COMPUTE_COMPUTE +#define _IGNITE_COMPUTE_COMPUTE + +#include + +#include +#include +#include + +#include + +namespace ignite +{ + namespace compute + { + /** + * Defines compute grid functionality for executing tasks and closures + * over nodes in the ClusterGroup. Instance of Compute is obtained from + * Ignite as follows: + * @code{.cpp} + * Ignite node = Ignition::Get(); + * + * // Compute over all nodes in the cluster. + * Compute c = node.GetCompute(); + * @endcode + * + * @par Load Balancing + * In all cases other than Broadcast(...), Ignite must select + * a node for a computation to be executed. The node will be selected + * based on the underlying \c LoadBalancingSpi, which by default + * sequentially picks next available node from the underlying cluster + * group. Other load balancing policies, such as \c random or + * \c adaptive, can be configured as well by selecting a different + * load balancing SPI in Ignite configuration. + * + * @par Fault Tolerance + * Ignite guarantees that as long as there is at least one grid node + * standing, every job will be executed. Jobs will automatically + * failover to another node if a remote node crashed or has rejected + * execution due to lack of resources. By default, in case of failover, + * next load balanced node will be picked for job execution. Also jobs + * will never be re-routed to the nodes they have failed on. This + * behavior can be changed by configuring any of the existing or a + * custom FailoverSpi in grid configuration. + * + * @par Computation SPIs + * Note that regardless of which method is used for executing + * computations, all relevant SPI implementations configured for this + * compute instance will be used (i.e. failover, load balancing, + * collision resolution, checkpoints, etc.). + */ + class IGNITE_IMPORT_EXPORT Compute + { + public: + /** + * Constructor. + * + * Internal method. Should not be used by user. + * + * @param impl Implementation. + */ + Compute(common::concurrent::SharedPointer impl) : + impl(impl) + { + // No-op. + } + + /** + * Calls provided ComputeFunc on a node within the underlying + * cluster group. + * + * @tparam R Call return type. BinaryType should be specialized for + * the type if it is not primitive. Should not be void. For + * non-returning methods see Compute::Run(). + * @tparam F Compute function type. Should implement ComputeFunc + * class. + * @param func Compute function to call. + * @return Computation result. + * @throw IgniteError in case of error. + */ + template + R Call(const F& func) + { + return impl.Get()->CallAsync(func).GetValue(); + } + + /** + * Asyncronuously calls provided ComputeFunc on a node within + * the underlying cluster group. + * + * @tparam R Call return type. BinaryType should be specialized for + * the type if it is not primitive. Should not be void. For + * non-returning methods see Compute::Run(). + * @tparam F Compute function type. Should implement ComputeFunc + * class. + * @param func Compute function to call. + * @return Future that can be used to access computation result once + * it's ready. + * @throw IgniteError in case of error. + */ + template + Future CallAsync(const F& func) + { + return impl.Get()->CallAsync(func); + } + + private: + /** Implementation. */ + common::concurrent::SharedPointer impl; + }; + } +} + +#endif //_IGNITE_COMPUTE_COMPUTE http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/compute/compute_func.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/compute/compute_func.h b/modules/platforms/cpp/core/include/ignite/compute/compute_func.h new file mode 100644 index 0000000..93a7b4f --- /dev/null +++ b/modules/platforms/cpp/core/include/ignite/compute/compute_func.h @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Declares ignite::compute::ComputeFunc class template. + */ + +#ifndef _IGNITE_COMPUTE_COMPUTE_FUNC +#define _IGNITE_COMPUTE_COMPUTE_FUNC + +namespace ignite +{ + class IgniteBinding; + + namespace compute + { + /** + * Interface for a simple compute function that can be serialized and + * called on the remote nodes. ignite::binary::BinaryType class template + * should be specialized for any class, inheriting from this class. + * + * @tparam R Call return type. BinaryType should be specialized for the + * type if it is not primitive. + */ + template + class ComputeFunc + { + friend class ignite::IgniteBinding; + + typedef R ReturnType; + public: + /** + * Destructor. + */ + virtual ~ComputeFunc() + { + // No-op. + } + + /** + * Called upon execution by compute. + * + * @return Computation result. + */ + virtual R Call() = 0; + }; + } +} + +#endif //_IGNITE_COMPUTE_COMPUTE_FUNC http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/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 d96f81f..b3b06f0 100644 --- a/modules/platforms/cpp/core/include/ignite/ignite.h +++ b/modules/platforms/cpp/core/include/ignite/ignite.h @@ -23,10 +23,12 @@ #ifndef _IGNITE_IGNITE #define _IGNITE_IGNITE -#include "ignite/cache/cache.h" -#include "ignite/transactions/transactions.h" -#include "ignite/impl/ignite_impl.h" -#include "ignite/ignite_configuration.h" +#include + +#include +#include +#include +#include namespace ignite { @@ -189,6 +191,15 @@ namespace ignite transactions::Transactions GetTransactions(); /** + * Get compute. + * + * This method should only be called on the valid instance. + * + * @return Compute class instance. + */ + compute::Compute GetCompute(); + + /** * Get ignite binding. * * This method should only be used on the valid instance. http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/ignite_binding.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/ignite_binding.h b/modules/platforms/cpp/core/include/ignite/ignite_binding.h index 344bdf6..fe060c1 100644 --- a/modules/platforms/cpp/core/include/ignite/ignite_binding.h +++ b/modules/platforms/cpp/core/include/ignite/ignite_binding.h @@ -121,6 +121,31 @@ namespace ignite } /** + * Register type as Compute function. + * + * Registred type should be a child of ignite::compute::ComputeFunc + * class. + */ + template + void RegisterComputeFunc() + { + impl::IgniteBindingImpl *im = impl.Get(); + + int32_t typeId = binary::BinaryType::GetTypeId(); + + if (im) + { + im->RegisterCallback(impl::IgniteBindingImpl::CallbackType::COMPUTE_JOB_CREATE, + typeId, impl::binding::ComputeJobCreate); + } + else + { + throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, + "Instance is not usable (did you check for error?)."); + } + } + + /** * Check if the instance is valid. * * Invalid instance can be returned if some of the previous operations http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/ignite_binding_context.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/ignite_binding_context.h b/modules/platforms/cpp/core/include/ignite/ignite_binding_context.h index 4d8a7a7..244b255 100644 --- a/modules/platforms/cpp/core/include/ignite/ignite_binding_context.h +++ b/modules/platforms/cpp/core/include/ignite/ignite_binding_context.h @@ -48,7 +48,7 @@ namespace ignite * * @return IgniteBinding instance. */ - IgniteBinding GetBingding() const + IgniteBinding GetBinding() const { return binding; } http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/impl/bindings.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/bindings.h b/modules/platforms/cpp/core/include/ignite/impl/bindings.h index c1ada12..357b0f0 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/bindings.h +++ b/modules/platforms/cpp/core/include/ignite/impl/bindings.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace ignite { @@ -88,6 +89,29 @@ namespace ignite return 0; } + + /** + * Binding for compute job creation. + * + * @tparam F The job type. + * @tparam R The job return type. + * + * @param reader Reader. + * @param env Environment. + * @return Handle for the job. + */ + template + int64_t ComputeJobCreate(binary::BinaryReaderImpl& reader, binary::BinaryWriterImpl&, IgniteEnvironment& env) + { + using namespace common::concurrent; + using namespace compute; + + F job = reader.ReadObject(); + + SharedPointer jobPtr(new ComputeJobHolderImpl(job)); + + return env.GetHandleRegistry().Allocate(jobPtr); + } } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/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 2bff0d8..3cfd700 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 @@ -22,6 +22,7 @@ #include #include +#include namespace ignite { @@ -29,13 +30,19 @@ namespace ignite { namespace cluster { + /* Forward declaration. */ + class ClusterGroupImpl; + + /* Shared pointer. */ + typedef common::concurrent::SharedPointer SP_ClusterGroupImpl; + /** * Cluster group implementation. */ class IGNITE_FRIEND_EXPORT ClusterGroupImpl : private interop::InteropTarget { typedef common::concurrent::SharedPointer SP_IgniteEnvironment; - typedef common::concurrent::SharedPointer SP_ClusterGroupImpl; + typedef common::concurrent::SharedPointer SP_ComputeImpl; public: /** * Constructor used to create new instance. @@ -53,12 +60,20 @@ namespace ignite /** * Get server nodes cluster group implementation. * - * @param err Error. * @return Server nodes cluster group implementation. */ - SP_ClusterGroupImpl ForServers(IgniteError& err); + SP_ClusterGroupImpl ForServers(); + + /** + * Get compute instance over this cluster group. + * + * @return Compute instance. + */ + SP_ComputeImpl GetCompute(); private: + IGNITE_NO_COPY_ASSIGNMENT(ClusterGroupImpl); + /** * Make cluster group implementation using java reference and * internal state of this cluster group. @@ -68,7 +83,15 @@ namespace ignite */ SP_ClusterGroupImpl FromTarget(jobject javaRef); - IGNITE_NO_COPY_ASSIGNMENT(ClusterGroupImpl) + /** + * Gets instance of compute internally. + * + * @return Instance of compute. + */ + SP_ComputeImpl InternalGetCompute(); + + /** Compute for the cluster group. */ + SP_ComputeImpl computeImpl; }; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/impl/compute/cancelable_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/compute/cancelable_impl.h b/modules/platforms/cpp/core/include/ignite/impl/compute/cancelable_impl.h new file mode 100644 index 0000000..828ecba --- /dev/null +++ b/modules/platforms/cpp/core/include/ignite/impl/compute/cancelable_impl.h @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Declares ignite::impl::compute::CancelableImpl class. + */ + +#ifndef _IGNITE_IMPL_COMPUTE_CANCELABLE_IMPL +#define _IGNITE_IMPL_COMPUTE_CANCELABLE_IMPL + +#include +#include +#include + +namespace ignite +{ + namespace impl + { + namespace compute + { + /** + * Compute implementation. + */ + class IGNITE_IMPORT_EXPORT CancelableImpl : public interop::InteropTarget, public common::Cancelable + { + public: + /** + * Constructor. + * + * @param env Environment. + * @param javaRef Java object reference. + */ + CancelableImpl(common::concurrent::SharedPointer env, jobject javaRef); + + /** + * Destructor. + */ + virtual ~CancelableImpl() + { + // No-op. + } + + /** + * Cancels the operation. + */ + virtual void Cancel(); + + private: + IGNITE_NO_COPY_ASSIGNMENT(CancelableImpl); + }; + } + } +} + +#endif //_IGNITE_IMPL_COMPUTE_CANCELABLE_IMPL http://git-wip-us.apache.org/repos/asf/ignite/blob/f9c96de5/modules/platforms/cpp/core/include/ignite/impl/compute/compute_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/compute/compute_impl.h b/modules/platforms/cpp/core/include/ignite/impl/compute/compute_impl.h new file mode 100644 index 0000000..389c571 --- /dev/null +++ b/modules/platforms/cpp/core/include/ignite/impl/compute/compute_impl.h @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Declares ignite::impl::compute::ComputeImpl class. + */ + +#ifndef _IGNITE_IMPL_COMPUTE_COMPUTE_IMPL +#define _IGNITE_IMPL_COMPUTE_COMPUTE_IMPL + +#include +#include +#include +#include +#include + +#include + +namespace ignite +{ + namespace impl + { + namespace compute + { + /** + * Compute implementation. + */ + class IGNITE_IMPORT_EXPORT ComputeImpl : public interop::InteropTarget + { + public: + /** + * Operation type. + */ + struct Operation + { + enum Type + { + Unicast = 5 + }; + }; + + /** + * Constructor. + * + * @param env Environment. + * @param javaRef Java object reference. + */ + ComputeImpl(common::concurrent::SharedPointer env, jobject javaRef); + + /** + * Asyncronuously calls provided ComputeFunc on a node within + * the underlying cluster group. + * + * @tparam F Compute function type. Should implement ComputeFunc + * class. + * @tparam R Call return type. BinaryType should be specialized for + * the type if it is not primitive. Should not be void. For + * non-returning methods see Compute::Run(). + * @param func Compute function to call. + * @return Future that can be used to acess computation result once + * it's ready. + * @throw IgniteError in case of error. + */ + template + Future CallAsync(const F& func) + { + common::concurrent::SharedPointer mem = GetEnvironment().AllocateMemory(); + interop::InteropOutputStream out(mem.Get()); + binary::BinaryWriterImpl writer(&out, GetEnvironment().GetTypeManager()); + + common::concurrent::SharedPointer job(new ComputeJobHolderImpl(func)); + + int64_t jobHandle = GetEnvironment().GetHandleRegistry().Allocate(job); + + ComputeTaskHolderImpl* taskPtr = new ComputeTaskHolderImpl(jobHandle); + common::concurrent::SharedPointer task(taskPtr); + + int64_t taskHandle = GetEnvironment().GetHandleRegistry().Allocate(task); + + writer.WriteInt64(taskHandle); + writer.WriteInt32(1); + writer.WriteInt64(jobHandle); + writer.WriteObject(func); + + out.Synchronize(); + + jobject target = InStreamOutObject(Operation::Unicast, *mem.Get()); + std::auto_ptr cancelable(new CancelableImpl(GetEnvironmentPointer(), target)); + + common::Promise& promise = taskPtr->GetPromise(); + promise.SetCancelTarget(cancelable); + + return promise.GetFuture(); + } + + private: + IGNITE_NO_COPY_ASSIGNMENT(ComputeImpl); + }; + } + } +} + +#endif //_IGNITE_IMPL_COMPUTE_COMPUTE_IMPL