IGNITE-6282: CPP: Implemented lazy initialization of IgniteImpl members
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/bacff9e1 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/bacff9e1 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/bacff9e1 Branch: refs/heads/ignite-3484 Commit: bacff9e1ae748f016545cdd0fb1d54c1a6384d86 Parents: e881993 Author: Igor Sapego <[email protected]> Authored: Thu Sep 7 19:10:11 2017 +0300 Committer: Igor Sapego <[email protected]> Committed: Thu Sep 7 19:10:11 2017 +0300 ---------------------------------------------------------------------- .../platforms/cpp/common/include/Makefile.am | 1 + .../cpp/common/include/ignite/common/lazy.h | 172 +++++++++++++++++++ .../cpp/common/include/ignite/common/utils.h | 51 ++++++ .../cpp/common/project/vs/common.vcxproj | 1 + .../common/project/vs/common.vcxproj.filters | 3 + .../platforms/cpp/core-test/config/invalid.xml | 39 +++++ .../cpp/core-test/config/isolated-32.xml | 51 ++++++ .../cpp/core-test/config/isolated-default.xml | 59 +++++++ .../platforms/cpp/core-test/config/isolated.xml | 32 ++++ .../core-test/config/persistence-store-32.xml | 51 ++++++ .../config/persistence-store-default.xml | 36 ++++ .../cpp/core-test/config/persistence-store.xml | 32 ++++ .../cpp/core-test/project/vs/core-test.vcxproj | 10 ++ .../project/vs/core-test.vcxproj.filters | 19 ++ .../cpp/core-test/src/cluster_test.cpp | 33 ++++ .../cpp/core-test/src/ignition_test.cpp | 37 +++- .../cpp/core-test/src/interop_test.cpp | 11 -- .../cpp/core/include/ignite/impl/ignite_impl.h | 25 +-- modules/platforms/cpp/core/src/ignition.cpp | 2 +- .../platforms/cpp/core/src/impl/ignite_impl.cpp | 45 +++-- modules/platforms/cpp/ignite/src/ignite.cpp | 23 ++- 21 files changed, 671 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/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 f115c94..a28d04f 100644 --- a/modules/platforms/cpp/common/include/Makefile.am +++ b/modules/platforms/cpp/common/include/Makefile.am @@ -27,6 +27,7 @@ nobase_include_HEADERS = \ ignite/common/reference_impl.h \ ignite/common/dynamic_size_array.h \ ignite/common/fixed_size_array.h \ + ignite/common/lazy.h \ ignite/common/utils.h \ ignite/common/platform_utils.h \ ignite/common/shared_state.h \ http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/common/include/ignite/common/lazy.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/lazy.h b/modules/platforms/cpp/common/include/ignite/common/lazy.h new file mode 100644 index 0000000..f2fc0e4 --- /dev/null +++ b/modules/platforms/cpp/common/include/ignite/common/lazy.h @@ -0,0 +1,172 @@ +/* + * 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_COMMON_LAZY +#define _IGNITE_COMMON_LAZY + +#include <stdint.h> + +#include <ignite/common/concurrent.h> +#include <ignite/common/common.h> + +namespace ignite +{ + namespace common + { + /** + * Lazy initialization template. + */ + template<typename T> + class IGNITE_IMPORT_EXPORT Lazy + { + /** + * Init function type. + */ + struct InitFunctionType + { + /** + * Destructor. + */ + virtual ~InitFunctionType() + { + // No-op. + } + + /** + * Call init function. + * + * @return Init function. + */ + virtual T* Init() = 0; + }; + + /** + * Init function type. + */ + template<typename F> + struct InitFunctionType0 : InitFunctionType + { + /** + * Constructor. + * + * @param func Function. + */ + InitFunctionType0(F func) : + func(func) + { + // No-op. + } + + /** + * Destructor. + */ + virtual ~InitFunctionType0() + { + // No-op. + } + + /** + * Call init function. + * + * @return Init function. + */ + virtual T* Init() + { + return func(); + } + + private: + /** Init function. */ + F func; + }; + + public: + typedef T InstanceType; + + /** + * Constructor. + * + * @param initFunc Initialization function. + */ + template<typename F> + Lazy(F initFunc) : + initFunc(new InitFunctionType0<F>(initFunc)), + instance(), + lock() + { + // No-op. + } + + /** + * Default constructor for late init. + */ + Lazy() : + initFunc(), + instance(), + lock() + { + // No-op. + } + + /** + * Init function. Can be used for late init. + * + * @warning Do not re-init inited instances to avoid undefined behaviour. + * + * @param initFunc Initialization function. + */ + template<typename F> + void Init(F initFunc) + { + this->initFunc = concurrent::SharedPointer<InitFunctionType>(new InitFunctionType0<F>(initFunc)); + } + + /** + * Get instance. + * + * Inits if was not inited prior. + * + * @return Instance. + */ + concurrent::SharedPointer<InstanceType> Get() + { + if (instance.Get()) + return instance; + + concurrent::CsLockGuard guard(lock); + + if (instance.Get()) + return instance; + + instance = concurrent::SharedPointer<InstanceType>(initFunc.Get()->Init()); + + return instance; + } + + private: + /** Init function. */ + concurrent::SharedPointer<InitFunctionType> initFunc; + + /** Instance. */ + concurrent::SharedPointer<InstanceType> instance; + + /** Sync lock. */ + concurrent::CriticalSection lock; + }; + } +} + +#endif // _IGNITE_COMMON_LAZY \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/common/include/ignite/common/utils.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/include/ignite/common/utils.h b/modules/platforms/cpp/common/include/ignite/common/utils.h index 67a4a3f..5022897 100644 --- a/modules/platforms/cpp/common/include/ignite/common/utils.h +++ b/modules/platforms/cpp/common/include/ignite/common/utils.h @@ -425,6 +425,57 @@ namespace ignite { typedef T2 type; }; + + /** + * Utility class to bind class instance with member function. + */ + template<typename R, typename T> + class BoundInstance + { + public: + typedef R FunctionReturnType; + typedef T ClassType; + typedef FunctionReturnType(ClassType::* MemberFunctionType)(); + + /** + * Constructor. + * + * @param instance Class instance. + * @param mfunc Member function. + */ + BoundInstance(ClassType* instance, MemberFunctionType mfunc) : + instance(instance), + mfunc(mfunc) + { + // No-op. + } + + /** + * Invoke operator. + * + * @return Result of the invokation of the member function on the bound instance. + */ + FunctionReturnType operator()() + { + return (instance->*mfunc)(); + } + + private: + /** Instance reference. */ + ClassType* instance; + + /** Member function pointer. */ + MemberFunctionType mfunc; + }; + + /** + * Utility function for binding. + */ + template<typename R, typename T> + BoundInstance<R, T> Bind(T* instance, R(T::* mfunc)()) + { + return BoundInstance<R, T>(instance, mfunc); + } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/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 07c3f50..bce1c2f 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj @@ -173,6 +173,7 @@ <ClInclude Include="..\..\include\ignite\common\dynamic_size_array.h" /> <ClInclude Include="..\..\include\ignite\common\fixed_size_array.h" /> <ClInclude Include="..\..\include\ignite\common\bits.h" /> + <ClInclude Include="..\..\include\ignite\common\lazy.h" /> <ClInclude Include="..\..\include\ignite\common\platform_utils.h" /> <ClInclude Include="..\..\include\ignite\common\promise.h" /> <ClInclude Include="..\..\include\ignite\common\reference_impl.h" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/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 020d32b..2d1a8b8 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj.filters +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj.filters @@ -79,6 +79,9 @@ <ClInclude Include="..\..\include\ignite\common\cancelable.h"> <Filter>Code\common</Filter> </ClInclude> + <ClInclude Include="..\..\include\ignite\common\lazy.h"> + <Filter>Code\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\src\date.cpp"> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/config/invalid.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/config/invalid.xml b/modules/platforms/cpp/core-test/config/invalid.xml index d6481c7..7ef741a 100644 --- a/modules/platforms/cpp/core-test/config/invalid.xml +++ b/modules/platforms/cpp/core-test/config/invalid.xml @@ -29,11 +29,50 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> + <property name="localHost" value="127.0.0.1"/> + + <property name="communicationSpi"> + <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi"> + <property name="localPort" value="52100"/> + </bean> + </property> <property name="discoverySpi"> <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> + <!-- Initial local port to listen to. --> + <property name="localPort" value="52500"/> + + <property name="ipFinder"> + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> + <property name="addresses"> + <list> + <!-- In distributed environment, replace with actual host IP address. --> + <value>127.0.0.1:52500</value> + </list> + </property> + </bean> + </property> <property name="socketTimeout" value="-300" /> </bean> </property> + + <property name="memoryConfiguration"> + <bean class="org.apache.ignite.configuration.MemoryConfiguration"> + <property name="systemCacheInitialSize" value="#{40 * 1024 * 1024}"/> + <property name="systemCacheMaxSize" value="#{40 * 1024 * 1024}"/> + + <property name="defaultMemoryPolicyName" value="dfltPlc"/> + + <property name="memoryPolicies"> + <list> + <bean class="org.apache.ignite.configuration.MemoryPolicyConfiguration"> + <property name="name" value="dfltPlc"/> + <property name="maxSize" value="#{100 * 1024 * 1024}"/> + <property name="initialSize" value="#{100 * 1024 * 1024}"/> + </bean> + </list> + </property> + </bean> + </property> </bean> </beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/config/isolated-32.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/config/isolated-32.xml b/modules/platforms/cpp/core-test/config/isolated-32.xml new file mode 100644 index 0000000..b758e11 --- /dev/null +++ b/modules/platforms/cpp/core-test/config/isolated-32.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<!-- + Ignite Spring configuration file to startup grid cache. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + <import resource="isolated-default.xml"/> + + <bean parent="grid.cfg"> + <property name="memoryConfiguration"> + <bean class="org.apache.ignite.configuration.MemoryConfiguration"> + <property name="systemCacheInitialSize" value="#{40 * 1024 * 1024}"/> + <property name="systemCacheMaxSize" value="#{40 * 1024 * 1024}"/> + + <property name="defaultMemoryPolicyName" value="dfltPlc"/> + + <property name="memoryPolicies"> + <list> + <bean class="org.apache.ignite.configuration.MemoryPolicyConfiguration"> + <property name="name" value="dfltPlc"/> + <property name="maxSize" value="#{100 * 1024 * 1024}"/> + <property name="initialSize" value="#{100 * 1024 * 1024}"/> + </bean> + </list> + </property> + </bean> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/config/isolated-default.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/config/isolated-default.xml b/modules/platforms/cpp/core-test/config/isolated-default.xml new file mode 100644 index 0000000..8dbbba3 --- /dev/null +++ b/modules/platforms/cpp/core-test/config/isolated-default.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<!-- + Ignite Spring configuration file to startup grid cache. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util.xsd"> + <bean abstract="true" id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> + <property name="localHost" value="127.0.0.1"/> + + <property name="communicationSpi"> + <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi"> + <property name="localPort" value="59100"/> + </bean> + </property> + + <property name="discoverySpi"> + <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> + <!-- Initial local port to listen to. --> + <property name="localPort" value="59500"/> + + <property name="ipFinder"> + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> + <property name="addresses"> + <list> + <!-- In distributed environment, replace with actual host IP address. --> + <value>127.0.0.1:59500</value> + </list> + </property> + </bean> + </property> + <property name="socketTimeout" value="300" /> + </bean> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/config/isolated.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/config/isolated.xml b/modules/platforms/cpp/core-test/config/isolated.xml new file mode 100644 index 0000000..8e56f00 --- /dev/null +++ b/modules/platforms/cpp/core-test/config/isolated.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<!-- + Ignite Spring configuration file to startup grid cache. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + <import resource="isolated-default.xml"/> + + <bean parent="grid.cfg"/> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/config/persistence-store-32.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/config/persistence-store-32.xml b/modules/platforms/cpp/core-test/config/persistence-store-32.xml new file mode 100644 index 0000000..3f607bc --- /dev/null +++ b/modules/platforms/cpp/core-test/config/persistence-store-32.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<!-- + Ignite Spring configuration file to startup grid cache. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + <import resource="persistence-store-default.xml"/> + + <bean parent="grid.cfg"> + <property name="memoryConfiguration"> + <bean class="org.apache.ignite.configuration.MemoryConfiguration"> + <property name="systemCacheInitialSize" value="#{40 * 1024 * 1024}"/> + <property name="systemCacheMaxSize" value="#{40 * 1024 * 1024}"/> + + <property name="defaultMemoryPolicyName" value="dfltPlc"/> + + <property name="memoryPolicies"> + <list> + <bean class="org.apache.ignite.configuration.MemoryPolicyConfiguration"> + <property name="name" value="dfltPlc"/> + <property name="maxSize" value="#{100 * 1024 * 1024}"/> + <property name="initialSize" value="#{100 * 1024 * 1024}"/> + </bean> + </list> + </property> + </bean> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/config/persistence-store-default.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/config/persistence-store-default.xml b/modules/platforms/cpp/core-test/config/persistence-store-default.xml new file mode 100644 index 0000000..373ef28 --- /dev/null +++ b/modules/platforms/cpp/core-test/config/persistence-store-default.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<!-- + Ignite Spring configuration file to startup grid cache. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + <bean abstract="true" id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> + <property name="localHost" value="127.0.0.1"/> + + <property name="persistentStoreConfiguration"> + <bean class="org.apache.ignite.configuration.PersistentStoreConfiguration"/> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/config/persistence-store.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/config/persistence-store.xml b/modules/platforms/cpp/core-test/config/persistence-store.xml new file mode 100644 index 0000000..a017d3d --- /dev/null +++ b/modules/platforms/cpp/core-test/config/persistence-store.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<!-- + Ignite Spring configuration file to startup grid cache. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + <import resource="persistence-store-default.xml"/> + + <bean parent="grid.cfg"/> +</beans> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/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 f2f6a1b..b614e59 100644 --- a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj +++ b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj @@ -56,6 +56,16 @@ <None Include="..\..\config\cache-query-continuous.xml" /> <None Include="..\..\config\cache-query-continuous-default.xml" /> <None Include="..\..\config\invalid.xml" /> + <None Include="..\..\config\isolated-32.xml" /> + <None Include="..\..\config\isolated-default.xml" /> + <None Include="..\..\config\isolated.xml" /> + <None Include="..\..\config\persistence-store-32.xml"> + <SubType>Designer</SubType> + </None> + <None Include="..\..\config\persistence-store-default.xml" /> + <None Include="..\..\config\persistence-store.xml"> + <SubType>Designer</SubType> + </None> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\src\binary_object_test.cpp" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/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 d58ef97..a445af8 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 @@ -178,5 +178,24 @@ <None Include="..\..\config\cache-store-32.xml"> <Filter>Configs</Filter> </None> + <None Include="..\..\config\isolated.xml"> + <Filter>Configs</Filter> + </None> + <None Include="..\..\config\isolated-32.xml"> + <Filter>Configs</Filter> + </None> + <None Include="..\..\config\isolated-default.xml"> + <Filter>Configs</Filter> + </None> + <None Include="..\..\config\cache-query-continuous.xml" /> + <None Include="..\..\config\persistence-store.xml"> + <Filter>Configs</Filter> + </None> + <None Include="..\..\config\persistence-store-32.xml"> + <Filter>Configs</Filter> + </None> + <None Include="..\..\config\persistence-store-default.xml"> + <Filter>Configs</Filter> + </None> </ItemGroup> </Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/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 4ee3f39..cb64b6f 100644 --- a/modules/platforms/cpp/core-test/src/cluster_test.cpp +++ b/modules/platforms/cpp/core-test/src/cluster_test.cpp @@ -58,6 +58,35 @@ struct ClusterTestSuiteFixture } }; +/* + * Test setup fixture. + */ +struct ClusterTestSuiteFixtureIsolated +{ + Ignite node; + + /* + * Constructor. + */ + ClusterTestSuiteFixtureIsolated() : +#ifdef IGNITE_TESTS_32 + node(ignite_test::StartNode("isolated-32.xml", "ClusterTestIsolated")) +#else + node(ignite_test::StartNode("isolated.xml", "ClusterTestIsolated")) +#endif + { + // No-op. + } + + /* + * Destructor. + */ + ~ClusterTestSuiteFixtureIsolated() + { + Ignition::StopAll(true); + } +}; + BOOST_FIXTURE_TEST_SUITE(ClusterTestSuite, ClusterTestSuiteFixture) BOOST_AUTO_TEST_CASE(IgniteImplProjection) @@ -83,6 +112,10 @@ BOOST_AUTO_TEST_CASE(IgniteImplForServers) BOOST_REQUIRE(clusterGroup.Get()->ForServers().IsValid()); } +BOOST_AUTO_TEST_SUITE_END() + +BOOST_FIXTURE_TEST_SUITE(ClusterTestSuiteIsolated, ClusterTestSuiteFixtureIsolated) + BOOST_AUTO_TEST_CASE(IgniteSetActive) { BOOST_REQUIRE(node.IsActive()); http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/src/ignition_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/ignition_test.cpp b/modules/platforms/cpp/core-test/src/ignition_test.cpp index c37c2ee..8b99936 100644 --- a/modules/platforms/cpp/core-test/src/ignition_test.cpp +++ b/modules/platforms/cpp/core-test/src/ignition_test.cpp @@ -35,9 +35,9 @@ BOOST_AUTO_TEST_CASE(TestIgnition) IgniteConfiguration cfg; #ifdef IGNITE_TESTS_32 - ignite_test::InitConfig(cfg, "cache-test-32.xml"); + ignite_test::InitConfig(cfg, "persistence-store-32.xml"); #else - ignite_test::InitConfig(cfg, "cache-test.xml"); + ignite_test::InitConfig(cfg, "persistence-store.xml"); #endif IgniteError err; @@ -81,4 +81,37 @@ BOOST_AUTO_TEST_CASE(TestIgnition) BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_GENERIC); } +BOOST_AUTO_TEST_CASE(TestStartWithpersistence) +{ + IgniteConfiguration cfg; + +#ifdef IGNITE_TESTS_32 + ignite_test::InitConfig(cfg, "persistence-store-32.xml"); +#else + ignite_test::InitConfig(cfg, "persistence-store.xml"); +#endif + try + { + Ignite grid = Ignition::Start(cfg, "test"); + } + catch (...) + { + // Stop all + Ignition::StopAll(true); + + throw; + } +} + +BOOST_AUTO_TEST_CASE(GracefulDeathOnInvalidConfig) +{ + IgniteConfiguration cfg; + + ignite_test::InitConfig(cfg, "invalid.xml"); + + BOOST_CHECK_THROW(Ignition::Start(cfg), IgniteError); + + Ignition::StopAll(false); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core-test/src/interop_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/interop_test.cpp b/modules/platforms/cpp/core-test/src/interop_test.cpp index ac1f428..1b07a03 100644 --- a/modules/platforms/cpp/core-test/src/interop_test.cpp +++ b/modules/platforms/cpp/core-test/src/interop_test.cpp @@ -117,15 +117,4 @@ BOOST_AUTO_TEST_CASE(StringUtfValid4ByteCodePoint) Ignition::StopAll(false); } -BOOST_AUTO_TEST_CASE(GracefulDeathOnInvalidConfig) -{ - IgniteConfiguration cfg; - - ignite_test::InitConfig(cfg, "invalid.xml"); - - BOOST_CHECK_THROW(Ignition::Start(cfg), IgniteError); - - Ignition::StopAll(false); -} - BOOST_AUTO_TEST_SUITE_END() http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h b/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h index 34b3749..8a5a0f1 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h +++ b/modules/platforms/cpp/core/include/ignite/impl/ignite_impl.h @@ -18,9 +18,10 @@ #ifndef _IGNITE_IMPL_IGNITE_IMPL #define _IGNITE_IMPL_IGNITE_IMPL -#include <ignite/common/concurrent.h> #include <ignite/jni/java.h> #include <ignite/common/utils.h> +#include <ignite/common/concurrent.h> +#include <ignite/common/lazy.h> #include <ignite/impl/ignite_environment.h> #include <ignite/impl/cache/cache_impl.h> @@ -28,9 +29,9 @@ #include <ignite/impl/cluster/cluster_group_impl.h> #include <ignite/impl/compute/compute_impl.h> -namespace ignite +namespace ignite { - namespace impl + namespace impl { /* * PlatformProcessor op codes. @@ -156,7 +157,7 @@ namespace ignite */ SP_TransactionsImpl GetTransactions() { - return txImpl; + return txImpl.Get(); } /** @@ -166,7 +167,7 @@ namespace ignite */ cluster::SP_ClusterGroupImpl GetProjection() { - return prjImpl; + return prjImpl.Get(); } /** @@ -183,7 +184,7 @@ namespace ignite */ bool IsActive() { - return prjImpl.Get()->IsActive(); + return prjImpl.Get().Get()->IsActive(); } /** @@ -194,7 +195,7 @@ namespace ignite */ void SetActive(bool active) { - prjImpl.Get()->SetActive(active); + prjImpl.Get().Get()->SetActive(active); } private: @@ -203,23 +204,23 @@ namespace ignite * * @return TransactionsImpl instance. */ - SP_TransactionsImpl InternalGetTransactions(IgniteError &err); + transactions::TransactionsImpl* InternalGetTransactions(); /** * Get current projection internal call. * * @return ClusterGroupImpl instance. */ - cluster::SP_ClusterGroupImpl InternalGetProjection(IgniteError &err); + cluster::ClusterGroupImpl* InternalGetProjection(); /** Environment. */ SP_IgniteEnvironment env; /** Transactions implementaion. */ - SP_TransactionsImpl txImpl; + common::Lazy<transactions::TransactionsImpl> txImpl; /** Projection implementation. */ - cluster::SP_ClusterGroupImpl prjImpl; + common::Lazy<cluster::ClusterGroupImpl> prjImpl; IGNITE_NO_COPY_ASSIGNMENT(IgniteImpl) @@ -235,4 +236,4 @@ namespace ignite } } -#endif //_IGNITE_IMPL_IGNITE_IMPL \ No newline at end of file +#endif //_IGNITE_IMPL_IGNITE_IMPL http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core/src/ignition.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/ignition.cpp b/modules/platforms/cpp/core/src/ignition.cpp index bc25b07..78ddc54 100644 --- a/modules/platforms/cpp/core/src/ignition.cpp +++ b/modules/platforms/cpp/core/src/ignition.cpp @@ -307,7 +307,7 @@ namespace ignite // Even if the call has failed environment are going to be released by the Java. envTarget.release(); - if (!env.Get()->GetProcessor()) + if (!env.Get()->GetProcessor() || jniErr.code != java::IGNITE_JNI_ERR_SUCCESS) { IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/core/src/impl/ignite_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/ignite_impl.cpp b/modules/platforms/cpp/core/src/impl/ignite_impl.cpp index e9d79d3..645db53 100644 --- a/modules/platforms/cpp/core/src/impl/ignite_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/ignite_impl.cpp @@ -25,22 +25,17 @@ using namespace ignite::impl::binary; using namespace ignite::binary; namespace ignite -{ +{ namespace impl { IgniteImpl::IgniteImpl(SharedPointer<IgniteEnvironment> env) : InteropTarget(env, static_cast<jobject>(env.Get()->GetProcessor()), true), - env(env) + env(env), + txImpl(), + prjImpl() { - IgniteError err; - - txImpl = InternalGetTransactions(err); - - IgniteError::ThrowIfNeeded(err); - - prjImpl = InternalGetProjection(err); - - IgniteError::ThrowIfNeeded(err); + txImpl.Init(common::Bind(this, &IgniteImpl::InternalGetTransactions)); + prjImpl.Init(common::Bind(this, &IgniteImpl::InternalGetProjection)); } const char* IgniteImpl::GetName() const @@ -65,35 +60,37 @@ namespace ignite IgniteImpl::SP_ComputeImpl IgniteImpl::GetCompute() { - cluster::SP_ClusterGroupImpl serversCluster = prjImpl.Get()->ForServers(); + cluster::SP_ClusterGroupImpl serversCluster = prjImpl.Get().Get()->ForServers(); return serversCluster.Get()->GetCompute(); } - IgniteImpl::SP_TransactionsImpl IgniteImpl::InternalGetTransactions(IgniteError &err) + transactions::TransactionsImpl* IgniteImpl::InternalGetTransactions() { - SP_TransactionsImpl res; + IgniteError err; jobject txJavaRef = InOpObject(ProcessorOp::GET_TRANSACTIONS, err); - if (txJavaRef) - res = SP_TransactionsImpl(new transactions::TransactionsImpl(env, txJavaRef)); + IgniteError::ThrowIfNeeded(err); + + if (!txJavaRef) + throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Can not get Transactions instance."); - return res; + return new transactions::TransactionsImpl(env, txJavaRef); } - cluster::SP_ClusterGroupImpl IgniteImpl::InternalGetProjection(IgniteError& err) + cluster::ClusterGroupImpl* IgniteImpl::InternalGetProjection() { - cluster::SP_ClusterGroupImpl res; - - JniErrorInfo jniErr; + IgniteError err; jobject clusterGroupJavaRef = InOpObject(ProcessorOp::GET_CLUSTER_GROUP, err); - if (clusterGroupJavaRef) - res = cluster::SP_ClusterGroupImpl(new cluster::ClusterGroupImpl(env, clusterGroupJavaRef)); + IgniteError::ThrowIfNeeded(err); + + if (!clusterGroupJavaRef) + throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Can not get ClusterGroup instance."); - return res; + return new cluster::ClusterGroupImpl(env, clusterGroupJavaRef); } cache::CacheImpl* IgniteImpl::GetOrCreateCache(const char* name, IgniteError& err, int32_t op) http://git-wip-us.apache.org/repos/asf/ignite/blob/bacff9e1/modules/platforms/cpp/ignite/src/ignite.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/ignite/src/ignite.cpp b/modules/platforms/cpp/ignite/src/ignite.cpp index 8e20bf4..5823fcd 100644 --- a/modules/platforms/cpp/ignite/src/ignite.cpp +++ b/modules/platforms/cpp/ignite/src/ignite.cpp @@ -89,7 +89,7 @@ namespace config * Convert arguments to configuration. * * @param cfg Output configuration. - * @param args Input arguments. + * @param src Input arguments. */ void Configure(ignite::IgniteConfiguration& cfg, const StringList& src) { @@ -164,13 +164,12 @@ void PrintHelp() int main(int argc, const char* argv[]) { // Help commands. - StringSet Help; - Help.insert("/help"); - Help.insert("-help"); - Help.insert("--help"); + StringSet help; + help.insert("/help"); + help.insert("-help"); + help.insert("--help"); - StringList args; - std::copy(argv + 1, argv + argc, std::back_insert_iterator<StringList>(args)); + StringList args(argv + 1, argv + argc); try { @@ -181,7 +180,7 @@ int main(int argc, const char* argv[]) std::string first = ToLower(args.front()); - if (Help.find(first) != Help.end()) + if (help.find(first) != help.end()) { PrintHelp(); @@ -202,24 +201,24 @@ int main(int argc, const char* argv[]) if (igniteImpl) { ignite::jni::java::JniContext* context = igniteImpl->GetContext(); + if (context) - { context->DestroyJvm(); - } } } - catch (ignite::IgniteError& e) + catch (const ignite::IgniteError& e) { std::cout << "ERROR: " << e.GetText() << std::endl; return -1; } - catch (std::exception& e) + catch (const std::exception& e) { std::cout << "ERROR: " << e.what() << std::endl; return -2; } + return 0; }
