http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp b/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp new file mode 100644 index 0000000..9d84e48 --- /dev/null +++ b/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp @@ -0,0 +1,257 @@ +/* + * 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 <boost/test/unit_test.hpp> + +#include "ignite/impl/interop/interop.h" +#include "ignite/impl/portable/portable_reader_impl.h" +#include "ignite/impl/portable/portable_writer_impl.h" + +#include "ignite/portable_test_defs.h" + +using namespace ignite; +using namespace ignite::impl::interop; +using namespace ignite::impl::portable; +using namespace ignite::portable; +using namespace ignite_test::core::portable; + +/* + * Check primitive value serialization-deserialization. + */ +template<typename T> +void CheckRawPrimitive(T writeVal) +{ + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writeSes(&out, NULL); + writeSes.WriteTopObject<T>(writeVal); + out.Synchronize(); + + InteropInputStream in(&mem); + PortableReaderImpl reader(&in); + T readVal = reader.ReadTopObject<T>(); + + BOOST_REQUIRE(readVal == writeVal); +} + +BOOST_AUTO_TEST_SUITE(PortableSessionTestSuite) + +BOOST_AUTO_TEST_CASE(TestByte) +{ + CheckRawPrimitive<int8_t>(-128); + CheckRawPrimitive<int8_t>(-1); + CheckRawPrimitive<int8_t>(0); + CheckRawPrimitive<int8_t>(1); + CheckRawPrimitive<int8_t>(127); +} + +BOOST_AUTO_TEST_CASE(TestBool) +{ + CheckRawPrimitive<bool>(true); + CheckRawPrimitive<bool>(false); +} + +BOOST_AUTO_TEST_CASE(TestShort) +{ + //CheckRawPrimitive<int16_t>(std::numeric_limits<int16_t>::min()); + CheckRawPrimitive<int16_t>(-1); + CheckRawPrimitive<int16_t>(0); + CheckRawPrimitive<int16_t>(1); + //CheckRawPrimitive<int16_t>(std::numeric_limits<int16_t>::max()); +} + +BOOST_AUTO_TEST_CASE(TestChar) +{ + //CheckRawPrimitive<uint16_t>(std::numeric_limits<uint16_t>::min()); + CheckRawPrimitive<uint16_t>(1); + //CheckRawPrimitive<uint16_t>(std::numeric_limits<uint16_t>::max()); +} + +BOOST_AUTO_TEST_CASE(TestInt) +{ + //CheckRawPrimitive<int32_t>(std::numeric_limits<int32_t>::min()); + CheckRawPrimitive<int32_t>(-1); + CheckRawPrimitive<int32_t>(0); + CheckRawPrimitive<int32_t>(1); + //CheckRawPrimitive<int32_t>(std::numeric_limits<int32_t>::max()); +} + +BOOST_AUTO_TEST_CASE(TestLong) +{ + //CheckRawPrimitive<int64_t>(std::numeric_limits<int64_t>::min()); + CheckRawPrimitive<int64_t>(-1); + CheckRawPrimitive<int64_t>(0); + CheckRawPrimitive<int64_t>(1); + //CheckRawPrimitive<int64_t>(std::numeric_limits<int64_t>::max()); +} + +BOOST_AUTO_TEST_CASE(TestFloat) +{ + CheckRawPrimitive<float>(-1.1f); + CheckRawPrimitive<float>(0); + CheckRawPrimitive<float>(1.1f); +} + +BOOST_AUTO_TEST_CASE(TestDouble) +{ + CheckRawPrimitive<double>(-1.1); + CheckRawPrimitive<double>(0); + CheckRawPrimitive<double>(1.1); +} + +BOOST_AUTO_TEST_CASE(TestGuid) +{ + Guid writeVal = Guid(1, 1); + + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writeSes(&out, NULL); + writeSes.WriteTopObject<Guid>(writeVal); + out.Synchronize(); + + InteropInputStream in(&mem); + PortableReaderImpl reader(&in); + Guid readVal = reader.ReadTopObject<Guid>(); + + BOOST_REQUIRE(readVal.GetMostSignificantBits() == writeVal.GetMostSignificantBits()); + BOOST_REQUIRE(readVal.GetLeastSignificantBits() == writeVal.GetLeastSignificantBits()); +} + +BOOST_AUTO_TEST_CASE(TestString) +{ + std::string writeVal = "MyString"; + + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writeSes(&out, NULL); + writeSes.WriteTopObject<std::string>(writeVal); + out.Synchronize(); + + InteropInputStream in(&mem); + PortableReaderImpl reader(&in); + std::string readVal = reader.ReadTopObject<std::string>(); + + BOOST_REQUIRE(readVal.compare(writeVal) == 0); +} + +BOOST_AUTO_TEST_CASE(TestObject) +{ + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writer(&out, NULL); + + InteropInputStream in(&mem); + PortableReaderImpl reader(&in); + + // 1. Test null object. + PortableInner writeVal(0); + + writer.WriteTopObject<PortableInner>(writeVal); + out.Synchronize(); + + in.Synchronize(); + PortableInner readVal = reader.ReadTopObject<PortableInner>(); + + BOOST_REQUIRE(readVal.GetValue() == 0); + + // 2. Test non-null object. + out.Position(0); + in.Position(0); + + writeVal = PortableInner(1); + + writer.WriteTopObject<PortableInner>(writeVal); + out.Synchronize(); + + in.Synchronize(); + readVal = reader.ReadTopObject<PortableInner>(); + + BOOST_REQUIRE(readVal.GetValue() == 1); +} + +BOOST_AUTO_TEST_CASE(TestObjectWithRawFields) +{ + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writer(&out, NULL); + + InteropInputStream in(&mem); + PortableReaderImpl reader(&in); + + out.Position(0); + in.Position(0); + + PortableFields writeVal = PortableFields(1, 2, 3, 4); + + writer.WriteTopObject<PortableFields>(writeVal); + out.Synchronize(); + + in.Synchronize(); + PortableFields readVal = reader.ReadTopObject<PortableFields>(); + + BOOST_REQUIRE(readVal.val1 == 1); + BOOST_REQUIRE(readVal.val2 == 2); + BOOST_REQUIRE(readVal.rawVal1 == 3); + BOOST_REQUIRE(readVal.rawVal2 == 4); +} + +BOOST_AUTO_TEST_CASE(TestPointer) +{ + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writer(&out, NULL); + + InteropInputStream in(&mem); + PortableReaderImpl reader(&in); + + // 1. Test null object. + writer.WriteTopObject<PortableInner*>(NULL); + out.Synchronize(); + + in.Synchronize(); + PortableInner* readVal = reader.ReadTopObject<PortableInner*>(); + + BOOST_REQUIRE(readVal == NULL); + + // 2. Test non-null object. + out.Position(0); + in.Position(0); + + PortableInner writeVal = PortableInner(1); + + writer.WriteTopObject<PortableInner*>(&writeVal); + out.Synchronize(); + + in.Synchronize(); + readVal = reader.ReadTopObject<PortableInner*>(); + + BOOST_REQUIRE(readVal->GetValue() == 1); + + delete readVal; +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp b/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp new file mode 100644 index 0000000..e818711 --- /dev/null +++ b/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp @@ -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. + */ + +#include "ignite/impl/interop/interop.h" +#include "ignite/portable/portable.h" + +#include "ignite/portable_test_defs.h" + +using namespace ignite; +using namespace ignite::impl::interop; +using namespace ignite::impl::portable; +using namespace ignite::portable; + +namespace ignite_test +{ + namespace core + { + namespace portable + { + PortableInner::PortableInner() : val(0) + { + // No-op. + } + + PortableInner::PortableInner(int32_t val) : val(val) + { + // No-op. + } + + int32_t PortableInner::GetValue() const + { + return val; + } + + PortableOuter::PortableOuter(int32_t valIn, int32_t valOut) : inner(valIn), val(valOut) + { + // No-op. + } + + PortableInner PortableOuter::GetInner() const + { + return inner; + } + + int32_t PortableOuter::GetValue() const + { + return val; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp b/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp new file mode 100644 index 0000000..45c666d --- /dev/null +++ b/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp @@ -0,0 +1,159 @@ +/* Copyright 2011 JetBrains s.r.o. + * + * Licensed 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. + * + * $Revision: 88625 $ +*/ + +#define BOOST_TEST_MODULE IgniteCoreTest + +#include <sstream> + +#include <boost/test/unit_test_suite_impl.hpp> +#include <boost/test/results_collector.hpp> +#include <boost/test/utils/basic_cstring/io.hpp> +#include <boost/test/unit_test_log.hpp> +#include <boost/test/included/unit_test.hpp> + +#include "teamcity_messages.h" + +using namespace boost::unit_test; +using namespace std; + +namespace JetBrains { + +// Custom formatter for TeamCity messages +class TeamcityBoostLogFormatter: public boost::unit_test::unit_test_log_formatter { + TeamcityMessages messages; + std::string currentDetails; + std::string flowId; + +public: + TeamcityBoostLogFormatter(const std::string &_flowId); + TeamcityBoostLogFormatter(); + + void log_start(std::ostream&, boost::unit_test::counter_t test_cases_amount); + void log_finish(std::ostream&); + void log_build_info(std::ostream&); + + void test_unit_start(std::ostream&, boost::unit_test::test_unit const& tu); + void test_unit_finish(std::ostream&, + boost::unit_test::test_unit const& tu, + unsigned long elapsed); + void test_unit_skipped(std::ostream&, boost::unit_test::test_unit const& tu); + + void log_exception(std::ostream&, + boost::unit_test::log_checkpoint_data const&, + boost::unit_test::const_string explanation); + + void log_entry_start(std::ostream&, + boost::unit_test::log_entry_data const&, + log_entry_types let); + void log_entry_value(std::ostream&, boost::unit_test::const_string value); + void log_entry_finish(std::ostream&); +}; + +// Fake fixture to register formatter +struct TeamcityFormatterRegistrar { + TeamcityFormatterRegistrar() { + if (JetBrains::underTeamcity()) { + boost::unit_test::unit_test_log.set_formatter(new JetBrains::TeamcityBoostLogFormatter()); + boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_successful_tests); + } + } +}; +BOOST_GLOBAL_FIXTURE(TeamcityFormatterRegistrar); + +// Formatter implementation +string toString(const_string bstr) { + stringstream ss; + + ss << bstr; + + return ss.str(); +} + +TeamcityBoostLogFormatter::TeamcityBoostLogFormatter(const std::string &_flowId) +: flowId(_flowId) +{} + +TeamcityBoostLogFormatter::TeamcityBoostLogFormatter() +: flowId(getFlowIdFromEnvironment()) +{} + +void TeamcityBoostLogFormatter::log_start(ostream &out, counter_t test_cases_amount) +{} + +void TeamcityBoostLogFormatter::log_finish(ostream &out) +{} + +void TeamcityBoostLogFormatter::log_build_info(ostream &out) +{} + +void TeamcityBoostLogFormatter::test_unit_start(ostream &out, test_unit const& tu) { + messages.setOutput(out); + + if (tu.p_type == tut_case) { + messages.testStarted(tu.p_name, flowId); + } else { + messages.suiteStarted(tu.p_name, flowId); + } + + currentDetails.clear(); +} + +void TeamcityBoostLogFormatter::test_unit_finish(ostream &out, test_unit const& tu, unsigned long elapsed) { + messages.setOutput(out); + + test_results const& tr = results_collector.results(tu.p_id); + if (tu.p_type == tut_case) { + if(!tr.passed()) { + if(tr.p_skipped) { + messages.testIgnored(tu.p_name, "ignored", flowId); + } else if (tr.p_aborted) { + messages.testFailed(tu.p_name, "aborted", currentDetails, flowId); + } else { + messages.testFailed(tu.p_name, "failed", currentDetails, flowId); + } + } + + messages.testFinished(tu.p_name, elapsed / 1000, flowId); + } else { + messages.suiteFinished(tu.p_name, flowId); + } +} + +void TeamcityBoostLogFormatter::test_unit_skipped(ostream &out, test_unit const& tu) +{} + +void TeamcityBoostLogFormatter::log_exception(ostream &out, log_checkpoint_data const&, const_string explanation) { + string what = toString(explanation); + + out << what << endl; + currentDetails += what + "\n"; +} + +void TeamcityBoostLogFormatter::log_entry_start(ostream&, log_entry_data const&, log_entry_types let) +{} + +void TeamcityBoostLogFormatter::log_entry_value(ostream &out, const_string value) { + out << value; + currentDetails += toString(value); +} + +void TeamcityBoostLogFormatter::log_entry_finish(ostream &out) { + out << endl; + currentDetails += "\n"; +} + +} http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp b/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp new file mode 100644 index 0000000..087409e --- /dev/null +++ b/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp @@ -0,0 +1,150 @@ +/* Copyright 2011 JetBrains s.r.o. + * + * Licensed 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. + * + * $Revision: 88625 $ +*/ + +#include <stdlib.h> +#include <sstream> + +#include "teamcity_messages.h" + +using namespace std; + +namespace JetBrains { + +std::string getFlowIdFromEnvironment() { + const char *flowId = getenv("TEAMCITY_PROCESS_FLOW_ID"); + return flowId == NULL ? "" : flowId; +} + +bool underTeamcity() { + return getenv("TEAMCITY_PROJECT_NAME") != NULL; +} + +TeamcityMessages::TeamcityMessages() +: m_out(&cout) +{} + +void TeamcityMessages::setOutput(ostream &out) { + m_out = &out; +} + +string TeamcityMessages::escape(string s) { + string result; + + for (size_t i = 0; i < s.length(); i++) { + char c = s[i]; + + switch (c) { + case '\n': result.append("|n"); break; + case '\r': result.append("|r"); break; + case '\'': result.append("|'"); break; + case '|': result.append("||"); break; + case ']': result.append("|]"); break; + default: result.append(&c, 1); + } + } + + return result; +} + +void TeamcityMessages::openMsg(const string &name) { + // endl for http://jetbrains.net/tracker/issue/TW-4412 + *m_out << endl << "##teamcity[" << name; +} + +void TeamcityMessages::closeMsg() { + *m_out << "]"; + // endl for http://jetbrains.net/tracker/issue/TW-4412 + *m_out << endl; + m_out->flush(); +} + +void TeamcityMessages::writeProperty(string name, string value) { + *m_out << " " << name << "='" << escape(value) << "'"; +} + +void TeamcityMessages::suiteStarted(string name, string flowid) { + openMsg("testSuiteStarted"); + writeProperty("name", name); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::suiteFinished(string name, string flowid) { + openMsg("testSuiteFinished"); + writeProperty("name", name); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::testStarted(string name, string flowid) { + openMsg("testStarted"); + writeProperty("name", name); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::testFinished(string name, int durationMs, string flowid) { + openMsg("testFinished"); + + writeProperty("name", name); + + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + if(durationMs >= 0) { + stringstream out; + out << durationMs; + writeProperty("duration", out.str()); + } + + closeMsg(); +} + +void TeamcityMessages::testFailed(string name, string message, string details, string flowid) { + openMsg("testFailed"); + writeProperty("name", name); + writeProperty("message", message); + writeProperty("details", details); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::testIgnored(std::string name, std::string message, string flowid) { + openMsg("testIgnored"); + writeProperty("name", name); + writeProperty("message", message); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +} http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/Makefile.am b/modules/platform/src/main/cpp/core/Makefile.am new file mode 100644 index 0000000..db50326 --- /dev/null +++ b/modules/platform/src/main/cpp/core/Makefile.am @@ -0,0 +1,66 @@ +## +## 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. +## + +ACLOCAL_AMFLAGS = "-Im4" + +SUBDIRS = . include os/linux/include +DIST_SUBDIRS = . include os/linux/include + +AM_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/os/linux/include -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -DIGNITE_IMPL +AM_CXXFLAGS = -Wall -std=c++0x +LIB_LDFLAGS = -no-undefined -version-info 1 + +COMMON_SRC = os/linux/src/impl/utils.cpp \ + src/ignite_error.cpp \ + src/guid.cpp \ + src/impl/handle_registry.cpp \ + src/impl/interop/interop_memory.cpp \ + src/impl/interop/interop_input_stream.cpp \ + src/impl/interop/interop_output_stream.cpp \ + src/portable/portable_type.cpp \ + src/impl/portable/portable_metadata_snapshot.cpp \ + src/impl/portable/portable_metadata_handler.cpp \ + src/impl/portable/portable_metadata_updater.cpp \ + src/impl/portable/portable_metadata_manager.cpp \ + src/impl/portable/portable_utils.cpp \ + src/impl/portable/portable_reader_impl.cpp \ + src/impl/portable/portable_writer_impl.cpp \ + src/portable/portable_containers.cpp \ + src/portable/portable_raw_reader.cpp \ + src/portable/portable_raw_writer.cpp \ + src/portable/portable_reader.cpp \ + src/portable/portable_writer.cpp \ + src/impl/portable/portable_metadata_updater_impl.cpp \ + src/impl/ignite_environment.cpp \ + src/impl/cache/query/query_impl.cpp \ + src/impl/cache/cache_impl.cpp \ + src/impl/ignite_impl.cpp \ + src/ignite.cpp \ + src/ignition.cpp + +lib_LTLIBRARIES = libignite.la +libignite_la_SOURCES = $(COMMON_SRC) +libignite_la_LDFLAGS = $(LIB_LDFLAGS) -L/usr/local/lib -lignite-common -ldl -version-info 0:0:0 -release $(PACKAGE_VERSION) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = ignite.pc + +clean-local: + $(RM) *.gcno *.gcda + +clean-docs: + $(RM) $(DX_CLEANFILES) http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/configure.ac ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/configure.ac b/modules/platform/src/main/cpp/core/configure.ac new file mode 100644 index 0000000..cdd238f --- /dev/null +++ b/modules/platform/src/main/cpp/core/configure.ac @@ -0,0 +1,62 @@ +# +# 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. +# + +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.69]) +AC_INIT([Apache Ignite C++], [1.4.0], [[email protected]], [ignite], [ignite.apache.org]) +AC_CONFIG_SRCDIR(src) + +AC_CANONICAL_SYSTEM +AC_CONFIG_MACRO_DIR([m4]) +AC_LANG([C++]) + +# Initialize automake +AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) +AC_CONFIG_HEADER(config.h) + +AM_PROG_AR + +# Checks for programs. +GXX="-g -O2" + +AC_PROG_CXX + +# Initialize Libtool +LT_INIT + +# Checks for libraries. +AC_CHECK_LIB([pthread], [pthread_mutex_lock]) + +# Checks for header files. + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_INLINE +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_INT8_T +AC_TYPE_PID_T +AC_TYPE_SIZE_T + +# Checks for library functions. +AC_FUNC_ERROR_AT_LINE + +AC_CONFIG_FILES(Makefile include/Makefile os/linux/include/Makefile ignite.pc) + +AC_OUTPUT http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/ignite.pc.in ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/ignite.pc.in b/modules/platform/src/main/cpp/core/ignite.pc.in new file mode 100644 index 0000000..613fd1a --- /dev/null +++ b/modules/platform/src/main/cpp/core/ignite.pc.in @@ -0,0 +1,9 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: ignite +Description: Apache Ignite C++. +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lignite http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/include/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/Makefile.am b/modules/platform/src/main/cpp/core/include/Makefile.am new file mode 100644 index 0000000..da9d95e --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/Makefile.am @@ -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. +## + +ACLOCAL_AMFLAGS = "-Im4" + +nobase_include_HEADERS = ignite/cache/cache.h \ + ignite/cache/cache_entry.h \ + ignite/cache/cache_peek_mode.h \ + ignite/cache/query/query_argument.h \ + ignite/cache/query/query_cursor.h \ + ignite/cache/query/query_scan.h \ + ignite/cache/query/query_sql.h \ + ignite/cache/query/query_text.h \ + ignite/cache/query/query.h \ + ignite/impl/cache/cache_impl.h \ + ignite/impl/cache/query/query_impl.h \ + ignite/impl/interop/interop.h \ + ignite/impl/interop/interop_input_stream.h \ + ignite/impl/interop/interop_memory.h \ + ignite/impl/interop/interop_output_stream.h \ + ignite/impl/portable/portable_metadata_handler.h \ + ignite/impl/portable/portable_metadata_manager.h \ + ignite/impl/portable/portable_metadata_snapshot.h \ + ignite/impl/portable/portable_metadata_updater.h \ + ignite/impl/portable/portable_metadata_updater_impl.h \ + ignite/impl/portable/portable_common.h \ + ignite/impl/portable/portable_id_resolver.h \ + ignite/impl/portable/portable_reader_impl.h \ + ignite/impl/portable/portable_utils.h \ + ignite/impl/portable/portable_writer_impl.h \ + ignite/impl/ignite_environment.h \ + ignite/impl/ignite_impl.h \ + ignite/impl/handle_registry.h \ + ignite/impl/operations.h \ + ignite/portable/portable.h \ + ignite/portable/portable_consts.h \ + ignite/portable/portable_containers.h \ + ignite/portable/portable_type.h \ + ignite/portable/portable_raw_reader.h \ + ignite/portable/portable_raw_writer.h \ + ignite/portable/portable_reader.h \ + ignite/portable/portable_writer.h \ + ignite/ignite.h \ + ignite/ignite_configuration.h \ + ignite/ignite_error.h \ + ignite/ignition.h \ + ignite/guid.h http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h new file mode 100644 index 0000000..dcc837b --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h @@ -0,0 +1,1153 @@ +/* + * 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_CACHE +#define _IGNITE_CACHE + +#include <map> +#include <set> + +#include <ignite/common/common.h> +#include <ignite/common/concurrent.h> + +#include "ignite/cache/cache_peek_mode.h" +#include "ignite/cache/query/query_cursor.h" +#include "ignite/cache/query/query_scan.h" +#include "ignite/cache/query/query_sql.h" +#include "ignite/cache/query/query_text.h" +#include "ignite/impl/cache/cache_impl.h" +#include "ignite/impl/operations.h" +#include "ignite/ignite_error.h" + +namespace ignite +{ + namespace cache + { + /** + * Main entry point for all Data Grid APIs. + */ + template<typename K, typename V> + class IGNITE_IMPORT_EXPORT Cache + { + public: + /** + * Constructor. + */ + Cache(impl::cache::CacheImpl* impl) : impl(ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl>(impl)) + { + // No-op. + } + + /** + * Name of this cache (null for default cache). + */ + char* GetName() + { + return impl.Get()->GetName(); + } + + /** + * Checks whether this cache contains no key-value mappings. + * Semantically equals to Cache.Size(IGNITE_PEEK_MODE_PRIMARY) == 0. + * + * @return True if cache is empty. + */ + bool IsEmpty() + { + IgniteError err; + + bool res = IsEmpty(err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Checks whether this cache contains no key-value mappings. + * Semantically equals to Cache.Size(IGNITE_PEEK_MODE_PRIMARY) == 0. + * + * @param err Error. + * @return True if cache is empty. + */ + bool IsEmpty(IgniteError& err) + { + return impl.Get()->IsEmpty(&err); + } + + /** + * Check if cache contains mapping for this key. + * + * @param key Key. + * @return True if cache contains mapping for this key. + */ + bool ContainsKey(const K& key) + { + IgniteError err; + + bool res = ContainsKey(key, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Check if cache contains mapping for this key. + * + * @param key Key. + * @param err Error. + * @return True if cache contains mapping for this key. + */ + bool ContainsKey(const K& key, IgniteError& err) + { + impl::In1Operation<K> op(&key); + + return impl.Get()->ContainsKey(op, &err); + } + + /** + * Check if cache contains mapping for these keys. + * + * @param keys Keys. + * @return True if cache contains mapping for all these keys. + */ + bool ContainsKeys(const std::set<K>& keys) + { + IgniteError err; + + bool res = ContainsKeys(keys, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Check if cache contains mapping for these keys. + * + * @param keys Keys. + * @param err Error. + * @return True if cache contains mapping for all these keys. + */ + bool ContainsKeys(const std::set<K>& keys, IgniteError& err) + { + impl::InSetOperation<K> op(&keys); + + return impl.Get()->ContainsKeys(op, &err); + } + + /** + * Peeks at cached value using optional set of peek modes. This method will sequentially + * iterate over given peek modes, and try to peek at value using each peek mode. Once a + * non-null value is found, it will be immediately returned. + * This method does not participate in any transactions, however, it may peek at transactional + * value depending on the peek modes used. + * + * @param key Key. + * @param peekModes Peek modes. + * @return Value. + */ + V LocalPeek(const K& key, int32_t peekModes) + { + IgniteError err; + + V res = LocalPeek(key, peekModes, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Peeks at cached value using optional set of peek modes. This method will sequentially + * iterate over given peek modes, and try to peek at value using each peek mode. Once a + * non-null value is found, it will be immediately returned. + * This method does not participate in any transactions, however, it may peek at transactional + * value depending on the peek modes used. + * + * @param key Key. + * @param peekModes Peek modes. + * @param err Error. + * @return Value. + */ + V LocalPeek(const K& key, int32_t peekModes, IgniteError& err) + { + impl::InCacheLocalPeekOperation<K> inOp(&key, peekModes); + impl::Out1Operation<V> outOp; + + impl.Get()->LocalPeek(inOp, outOp, peekModes, &err); + + return outOp.GetResult(); + } + + /** + * Retrieves value mapped to the specified key from cache. + * If the value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key. + * @return Value. + */ + V Get(const K& key) + { + IgniteError err; + + V res = Get(key, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Retrieves value mapped to the specified key from cache. + * If the value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key. + * @param err Error. + * @return Value. + */ + V Get(const K& key, IgniteError& err) + { + impl::In1Operation<K> inOp(&key); + impl::Out1Operation<V> outOp; + + impl.Get()->Get(inOp, outOp, &err); + + return outOp.GetResult(); + } + + /** + * Retrieves values mapped to the specified keys from cache. + * If some value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param keys Keys. + * @return Map of key-value pairs. + */ + std::map<K, V> GetAll(const std::set<K>& keys) + { + IgniteError err; + + std::map<K, V> res = GetAll(keys, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Retrieves values mapped to the specified keys from cache. + * If some value is not present in cache, then it will be looked up from swap storage. If + * it's not present in swap, or if swap is disabled, and if read-through is allowed, value + * will be loaded from persistent store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param keys Keys. + * @param err Error. + * @return Map of key-value pairs. + */ + std::map<K, V> GetAll(const std::set<K>& keys, IgniteError& err) + { + impl::InSetOperation<K> inOp(&keys); + impl::OutMapOperation<K, V> outOp; + + impl.Get()->GetAll(inOp, outOp, &err); + + return outOp.GetResult(); + } + + /** + * Associates the specified value with the specified key in the cache. + * If the cache previously contained a mapping for the key, + * the old value is replaced by the specified value. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + */ + void Put(const K& key, const V& val) + { + IgniteError err; + + Put(key, val, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Associates the specified value with the specified key in the cache. + * If the cache previously contained a mapping for the key, + * the old value is replaced by the specified value. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + * @param err Error. + */ + void Put(const K& key, const V& val, IgniteError& err) + { + impl::In2Operation<K, V> op(&key, &val); + + impl.Get()->Put(op, &err); + } + + /** + * Stores given key-value pairs in cache. + * If write-through is enabled, the stored values will be persisted to store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param vals Key-value pairs to store in cache. + */ + void PutAll(const std::map<K, V>& vals) + { + IgniteError err; + + PutAll(vals, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Stores given key-value pairs in cache. + * If write-through is enabled, the stored values will be persisted to store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param vals Key-value pairs to store in cache. + * @param err Error. + */ + void PutAll(const std::map<K, V>& vals, IgniteError& err) + { + impl::InMapOperation<K, V> op(&vals); + + impl.Get()->PutAll(op, &err); + } + + /** + * Associates the specified value with the specified key in this cache, + * returning an existing value if one existed. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + * @return The value associated with the key at the start of the + * operation or null if none was associated. + */ + V GetAndPut(const K& key, const V& val) + { + IgniteError err; + + V res = GetAndPut(key, val, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Associates the specified value with the specified key in this cache, + * returning an existing value if one existed. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + * @param err Error. + * @return The value associated with the key at the start of the + * operation or null if none was associated. + */ + V GetAndPut(const K& key, const V& val, IgniteError& err) + { + impl::In2Operation<K, V> inOp(&key, &val); + impl::Out1Operation<V> outOp; + + impl.Get()->GetAndPut(inOp, outOp, &err); + + return outOp.GetResult(); + } + + /** + * Atomically replaces the value for a given key if and only if there is + * a value currently mapped by the key. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + * @return The previous value associated with the specified key, or + * null if there was no mapping for the key. + */ + V GetAndReplace(const K& key, const V& val) + { + IgniteError err; + + V res = GetAndReplace(key, val, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Atomically replaces the value for a given key if and only if there is + * a value currently mapped by the key. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + * @param err Error. + * @return The previous value associated with the specified key, or + * null if there was no mapping for the key. + */ + V GetAndReplace(const K& key, const V& val, IgniteError& err) + { + impl::In2Operation<K, V> inOp(&key, &val); + impl::Out1Operation<V> outOp; + + impl.Get()->GetAndReplace(inOp, outOp, &err); + + return outOp.GetResult(); + } + + /** + * Atomically removes the entry for a key only if currently mapped to some value. + * + * @param key Key with which the specified value is associated. + * @return The value if one existed or null if no mapping existed for this key. + */ + V GetAndRemove(const K& key) + { + IgniteError err; + + V res = GetAndRemove(key, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Atomically removes the entry for a key only if currently mapped to some value. + * + * @param key Key with which the specified value is associated. + * @param err Error. + * @return The value if one existed or null if no mapping existed for this key. + */ + V GetAndRemove(const K& key, IgniteError& err) + { + impl::In1Operation<K> inOp(&key); + impl::Out1Operation<V> outOp; + + impl.Get()->GetAndRemove(inOp, outOp, &err); + + return outOp.GetResult(); + } + + /** + * Atomically associates the specified key with the given value if it is not + * already associated with a value. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + * @return True if a value was set. + */ + bool PutIfAbsent(const K& key, const V& val) + { + IgniteError err; + + bool res = PutIfAbsent(key, val, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Atomically associates the specified key with the given value if it is not + * already associated with a value. + * + * @param key Key with which the specified value is to be associated. + * @param val Value to be associated with the specified key. + * @param err Error. + * @return True if a value was set. + */ + bool PutIfAbsent(const K& key, const V& val, IgniteError& err) + { + impl::In2Operation<K, V> op(&key, &val); + + return impl.Get()->PutIfAbsent(op, &err); + } + + /** + * Stores given key-value pair in cache only if cache had no previous mapping for it. + * If cache previously contained value for the given key, then this value is returned. + * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + * which in its turn may load the value from the swap storage, and consecutively, if it's not + * in swap, from the underlying persistent storage. + * If the returned value is not needed, method putxIfAbsent() should be used instead of this one to + * avoid the overhead associated with returning of the previous value. + * If write-through is enabled, the stored value will be persisted to store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key to store in cache. + * @param val Value to be associated with the given key. + * @return Previously contained value regardless of whether put happened or not + * (null if there was no previous value). + */ + V GetAndPutIfAbsent(const K& key, const V& val) + { + IgniteError err; + + V res = GetAndPutIfAbsent(key, val, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Stores given key-value pair in cache only if cache had no previous mapping for it. + * If cache previously contained value for the given key, then this value is returned. + * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + * which in its turn may load the value from the swap storage, and consecutively, if it's not + * in swap, from the underlying persistent storage. + * If the returned value is not needed, method putxIfAbsent() should be used instead of this one to + * avoid the overhead associated with returning of the previous value. + * If write-through is enabled, the stored value will be persisted to store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key to store in cache. + * @param val Value to be associated with the given key. + * @param err Error. + * @return Previously contained value regardless of whether put happened or not + * (null if there was no previous value). + */ + V GetAndPutIfAbsent(const K& key, const V& val, IgniteError& err) + { + impl::In2Operation<K, V> inOp(&key, &val); + impl::Out1Operation<V> outOp; + + impl.Get()->GetAndPutIfAbsent(inOp, outOp, &err); + + return outOp.GetResult(); + } + + /** + * Stores given key-value pair in cache only if there is a previous mapping for it. + * If cache previously contained value for the given key, then this value is returned. + * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + * which in its turn may load the value from the swap storage, and consecutively, if it's not + * in swap, rom the underlying persistent storage. + * If write-through is enabled, the stored value will be persisted to store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key to store in cache. + * @param val Value to be associated with the given key. + * @return True if the value was replaced. + */ + bool Replace(const K& key, const V& val) + { + IgniteError err; + + bool res = Replace(key, val, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Stores given key-value pair in cache only if there is a previous mapping for it. + * If cache previously contained value for the given key, then this value is returned. + * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + * which in its turn may load the value from the swap storage, and consecutively, if it's not + * in swap, rom the underlying persistent storage. + * If write-through is enabled, the stored value will be persisted to store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key to store in cache. + * @param val Value to be associated with the given key. + * @param err Error. + * @return True if the value was replaced. + */ + bool Replace(const K& key, const V& val, IgniteError& err) + { + impl::In2Operation<K, V> op(&key, &val); + + return impl.Get()->Replace(op, &err); + } + + /** + * Stores given key-value pair in cache only if only if the previous value is equal to the + * old value passed as argument. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key to store in cache. + * @param oldVal Old value to match. + * @param newVal Value to be associated with the given key. + * @return True if replace happened, false otherwise. + */ + bool Replace(const K& key, const V& oldVal, const V& newVal) + { + IgniteError err; + + bool res = Replace(key, oldVal, newVal, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Stores given key-value pair in cache only if only if the previous value is equal to the + * old value passed as argument. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key to store in cache. + * @param oldVal Old value to match. + * @param newVal Value to be associated with the given key. + * @param err Error. + * @return True if replace happened, false otherwise. + */ + bool Replace(const K& key, const V& oldVal, const V& newVal, IgniteError& err) + { + impl::In3Operation<K, V, V> op(&key, &oldVal, &newVal); + + return impl.Get()->ReplaceIfEqual(op, &err); + } + + /** + * Attempts to evict all entries associated with keys. Note, that entry will be evicted only + * if it's not used (not participating in any locks or transactions). + * + * @param keys Keys to evict from cache. + */ + void LocalEvict(const std::set<K>& keys) + { + IgniteError err; + + LocalEvict(keys, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Attempts to evict all entries associated with keys. Note, that entry will be evicted only + * if it's not used (not participating in any locks or transactions). + * + * @param keys Keys to evict from cache. + * @param err Error. + */ + void LocalEvict(const std::set<K>& keys, IgniteError& err) + { + impl::InSetOperation<K> op(&keys); + + impl.Get()->LocalEvict(op, &err); + } + + /** + * Clear cache. + */ + void Clear() + { + IgniteError err; + + Clear(err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Clear cache. + * + * @param err Error. + */ + void Clear(IgniteError& err) + { + impl.Get()->Clear(&err); + } + + /** + * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param key Key to clear. + */ + void Clear(const K& key) + { + IgniteError err; + + Clear(key, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param key Key to clear. + * @param err Error. + */ + void Clear(const K& key, IgniteError& err) + { + impl::In1Operation<K> op(&key); + + impl.Get()->Clear(op, &err); + } + + /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param keys Keys to clear. + */ + void ClearAll(const std::set<K>& keys) + { + IgniteError err; + + ClearAll(keys, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * + * @param keys Keys to clear. + * @param err Error. + */ + void ClearAll(const std::set<K>& keys, IgniteError& err) + { + impl::InSetOperation<K> op(&keys); + + impl.Get()->ClearAll(op, &err); + } + + /** + * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * Note that this operation is local as it merely clears an entry from local cache, it does not + * remove entries from remote caches. + * + * @param key Key to clear. + */ + void LocalClear(const K& key) + { + IgniteError err; + + LocalClear(key, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * Note that this operation is local as it merely clears an entry from local cache, it does not + * remove entries from remote caches. + * + * @param key Key to clear. + * @param err Error. + */ + void LocalClear(const K& key, IgniteError& err) + { + impl::In1Operation<K> op(&key); + + impl.Get()->LocalClear(op, &err); + } + + /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * Note that this operation is local as it merely clears entries from local cache, it does not + * remove entries from remote caches. + * + * @param keys Keys to clear. + */ + void LocalClearAll(const std::set<K>& keys) + { + IgniteError err; + + LocalClearAll(keys, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + * Entry is cleared only if it is not currently locked, and is not participating in a transaction. + * Note that this operation is local as it merely clears entries from local cache, it does not + * remove entries from remote caches. + * + * @param keys Keys to clear. + * @param err Error. + */ + void LocalClearAll(const std::set<K>& keys, IgniteError& err) + { + impl::InSetOperation<K> op(&keys); + + impl.Get()->LocalClearAll(op, &err); + } + + /** + * Removes given key mapping from cache. If cache previously contained value for the given key, + * then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be + * loaded from the primary node, which in its turn may load the value from the disk-based swap + * storage, and consecutively, if it's not in swap, from the underlying persistent storage. + * If the returned value is not needed, method removex() should always be used instead of this + * one to avoid the overhead associated with returning of the previous value. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key whose mapping is to be removed from cache. + * @return False if there was no matching key. + */ + bool Remove(const K& key) + { + IgniteError err; + + bool res = Remove(key, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Removes given key mapping from cache. If cache previously contained value for the given key, + * then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be + * loaded from the primary node, which in its turn may load the value from the disk-based swap + * storage, and consecutively, if it's not in swap, from the underlying persistent storage. + * If the returned value is not needed, method removex() should always be used instead of this + * one to avoid the overhead associated with returning of the previous value. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key whose mapping is to be removed from cache. + * @param err Error. + * @return False if there was no matching key. + */ + bool Remove(const K& key, IgniteError& err) + { + impl::In1Operation<K> op(&key); + + return impl.Get()->Remove(op, &err); + } + + /** + * Removes given key mapping from cache if one exists and value is equal to the passed in value. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key whose mapping is to be removed from cache. + * @param val Value to match against currently cached value. + * @return True if entry was removed, false otherwise. + */ + bool Remove(const K& key, const V& val) + { + IgniteError err; + + bool res = Remove(key, val, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Removes given key mapping from cache if one exists and value is equal to the passed in value. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param key Key whose mapping is to be removed from cache. + * @param val Value to match against currently cached value. + * @param err Error. + * @return True if entry was removed, false otherwise. + */ + bool Remove(const K& key, const V& val, IgniteError& err) + { + impl::In2Operation<K, V> op(&key, &val); + + return impl.Get()->RemoveIfEqual(op, &err); + } + + /** + * Removes given key mappings from cache. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param keys Keys whose mappings are to be removed from cache. + */ + void RemoveAll(const std::set<K>& keys) + { + IgniteError err; + + RemoveAll(keys, err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Removes given key mappings from cache. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param keys Keys whose mappings are to be removed from cache. + * @param err Error. + */ + void RemoveAll(const std::set<K>& keys, IgniteError& err) + { + impl::InSetOperation<K> op(&keys); + + impl.Get()->RemoveAll(op, &err); + } + + /** + * Removes all mappings from cache. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param err Error. + */ + void RemoveAll() + { + IgniteError err; + + RemoveAll(err); + + IgniteError::ThrowIfNeeded(err); + } + + /** + * Removes all mappings from cache. + * If write-through is enabled, the value will be removed from store. + * This method is transactional and will enlist the entry into ongoing transaction if there is one. + * + * @param err Error. + */ + void RemoveAll(IgniteError& err) + { + return impl.Get()->RemoveAll(&err); + } + + /** + * Gets the number of all entries cached on this node. + * + * @return Cache size on this node. + */ + int32_t LocalSize() + { + return LocalSize(IGNITE_PEEK_MODE_ALL); + } + + /** + * Gets the number of all entries cached on this node. + * + * @param err Error. + * @return Cache size on this node. + */ + int32_t LocalSize(IgniteError& err) + { + return LocalSize(IGNITE_PEEK_MODE_ALL, err); + } + + /** + * Gets the number of all entries cached on this node. + * + * @param Peek modes. + * @return Cache size on this node. + */ + int32_t LocalSize(int32_t peekModes) + { + IgniteError err; + + int32_t res = LocalSize(peekModes, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Gets the number of all entries cached on this node. + * + * @param Peek modes. + * @param err Error. + * @return Cache size on this node. + */ + int32_t LocalSize(int32_t peekModes, IgniteError& err) + { + return impl.Get()->LocalSize(peekModes, &err); + } + + /** + * Gets the number of all entries cached across all nodes. + * NOTE: this operation is distributed and will query all participating nodes for their cache sizes. + * + * @return Cache size across all nodes. + */ + int32_t Size() + { + return Size(ignite::cache::IGNITE_PEEK_MODE_ALL); + } + + /** + * Gets the number of all entries cached across all nodes. + * NOTE: this operation is distributed and will query all participating nodes for their cache sizes. + * + * @param err Error. + * @return Cache size across all nodes. + */ + int32_t Size(IgniteError& err) + { + return Size(ignite::cache::IGNITE_PEEK_MODE_ALL, err); + } + + /** + * Gets the number of all entries cached across all nodes. + * NOTE: this operation is distributed and will query all participating nodes for their cache sizes. + * + * @param Peek modes. + * @return Cache size across all nodes. + */ + int32_t Size(int32_t peekModes) + { + IgniteError err; + + int32_t res = Size(peekModes, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Gets the number of all entries cached across all nodes. + * NOTE: this operation is distributed and will query all participating nodes for their cache sizes. + * + * @param Peek modes. + * @param err Error. + * @return Cache size across all nodes. + */ + int32_t Size(int32_t peekModes, IgniteError& err) + { + return impl.Get()->Size(peekModes, &err); + } + + /** + * Perform SQL query. + * + * @param qry Query. + * @return Query cursor. + */ + query::QueryCursor<K, V> Query(const query::SqlQuery& qry) + { + IgniteError err; + + query::QueryCursor<K, V> res = Query(qry, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /** + * Perform SQL query. + * + * @param qry Query. + * @param err Error. + * @return Query cursor. + */ + query::QueryCursor<K, V> Query(const query::SqlQuery& qry, IgniteError& err) + { + impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, &err); + + return query::QueryCursor<K, V>(cursorImpl); + } + + /* + * Perform text query. + * + * @param qry Query. + * @return Query cursor. + */ + query::QueryCursor<K, V> Query(const query::TextQuery& qry) + { + IgniteError err; + + query::QueryCursor<K, V> res = Query(qry, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /* + * Perform text query. + * + * @param qry Query. + * @param err Error. + * @return Query cursor. + */ + query::QueryCursor<K, V> Query(const query::TextQuery& qry, IgniteError& err) + { + impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, &err); + + return query::QueryCursor<K, V>(cursorImpl); + } + + /* + * Perform scan query. + * + * @param qry Query. + * @return Query cursor. + */ + query::QueryCursor<K, V> Query(const query::ScanQuery& qry) + { + IgniteError err; + + query::QueryCursor<K, V> res = Query(qry, err); + + IgniteError::ThrowIfNeeded(err); + + return res; + } + + /* + * Perform scan query. + * + * @param qry Query. + * @param err Error. + * @return Query cursor. + */ + query::QueryCursor<K, V> Query(const query::ScanQuery& qry, IgniteError& err) + { + impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, &err); + + return query::QueryCursor<K, V>(cursorImpl); + } + + private: + /** Implementation delegate. */ + ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl> impl; + }; + } +} + +#endif http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h new file mode 100644 index 0000000..2b6c785 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.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. + */ + +#ifndef _IGNITE_CACHE_ENTRY +#define _IGNITE_CACHE_ENTRY + +#include <ignite/common/common.h> + +namespace ignite +{ + namespace cache + { + /** + * Cache entry. + */ + template<typename K, typename V> + class IGNITE_IMPORT_EXPORT CacheEntry + { + public: + /** + * Default constructor. + */ + CacheEntry() : key(K()), val(V()) + { + // No-op. + } + + /** + * Constructor. + * + * @param key Key. + * @param val Value. + */ + CacheEntry(const K& key, const V& val) : key(key), val(val) + { + // No-op. + } + + /** + * Copy constructor. + * + * @param other Other instance. + */ + CacheEntry(const CacheEntry& other) + { + key = other.key; + val = other.val; + } + + /** + * Assignment operator. + * + * @param other Other instance. + */ + CacheEntry& operator=(const CacheEntry& other) + { + if (this != &other) + { + CacheEntry tmp(other); + + K& key0 = key; + V& val0 = val; + + key = tmp.key; + val = tmp.val; + + tmp.key = key0; + tmp.val = val0; + } + + return *this; + } + + /** + * Get key. + * + * @return Key. + */ + K GetKey() + { + return key; + } + + /** + * Get value. + * + * @return Value. + */ + V GetValue() + { + return val; + } + + private: + /** Key. */ + K key; + + /** Value. */ + V val; + }; + } +} + +#endif http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h new file mode 100644 index 0000000..be61887 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h @@ -0,0 +1,71 @@ +/* + * 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_CACHE_PEEK_MODE +#define _IGNITE_CACHE_PEEK_MODE + +namespace ignite +{ + namespace cache + { + /** + * Enumeration of all supported cache peek modes. + */ + enum CachePeekMode + { + /** + * Peeks into all available cache storages. + */ + IGNITE_PEEK_MODE_ALL = 0x01, + + /** + * Peek into near cache only (don't peek into partitioned cache). + * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode. + */ + IGNITE_PEEK_MODE_NEAR = 0x02, + + /** + * Peek value from primary copy of partitioned cache only (skip near cache). + * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode. + */ + IGNITE_PEEK_MODE_PRIMARY = 0x04, + + /** + * Peek value from backup copies of partitioned cache only (skip near cache). + * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode. + */ + IGNITE_PEEK_MODE_BACKUP = 0x08, + + /** + * Peeks value from the on-heap storage only. + */ + IGNITE_PEEK_MODE_ONHEAP = 0x10, + + /** + * Peeks value from the off-heap storage only, without loading off-heap value into cache. + */ + IGNITE_PEEK_MODE_OFFHEAP = 0x20, + + /** + * Peeks value from the swap storage only, without loading swapped value into cache. + */ + IGNITE_PEEK_MODE_SWAP = 0x40 + }; + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h new file mode 100644 index 0000000..f2d19cd --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h @@ -0,0 +1,27 @@ +/* + * 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_QUERY +#define _IGNITE_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" +#include "ignite/cache/query/query_text.h" + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/58a665aa/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h new file mode 100644 index 0000000..0f41c56 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h @@ -0,0 +1,125 @@ +/* + * 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_CACHE_QUERY_ARGUMENT +#define _IGNITE_CACHE_QUERY_ARGUMENT + +#include "ignite/portable/portable_raw_writer.h" + +namespace ignite +{ + namespace cache + { + namespace query + { + /** + * Base class for all query arguments. + */ + class QueryArgumentBase + { + public: + /** + * Destructor. + */ + virtual ~QueryArgumentBase() + { + // No-op. + } + + /** + * Copy argument. + * + * @return Copy. + */ + virtual QueryArgumentBase* Copy() = 0; + + /** + * Write argument. + */ + virtual void Write(ignite::portable::PortableRawWriter& writer) = 0; + }; + + /** + * Query argument. + */ + template<typename T> + class QueryArgument : public QueryArgumentBase + { + public: + /** + * Constructor. + * + * @param val Value. + */ + QueryArgument(const T& val) : val(val) + { + // No-op. + } + + /** + * Copy constructor. + * + * @param other Other instance. + */ + QueryArgument(const QueryArgument& other) + { + val = other.val; + } + + /** + * Assignment operator. + * + * @param other Other instance. + */ + QueryArgument& operator=(const QueryArgument& other) + { + if (this != &other) + { + QueryArgument tmp(other); + + T val0 = val; + val = tmp.val; + tmp.val = val0; + } + + return *this; + } + + ~QueryArgument() + { + // No-op. + } + + QueryArgumentBase* Copy() + { + return new QueryArgument(val); + } + + void Write(ignite::portable::PortableRawWriter& writer) + { + writer.WriteObject<T>(val); + } + + private: + /** Value. */ + T val; + }; + } + } +} + +#endif \ No newline at end of file
