From 8ffbf028b5997c066e20ad532fc970ec945163e1 Mon Sep 17 00:00:00 2001 From: ihsan demir Date: Tue, 12 Jan 2016 11:13:42 +0200 Subject: [PATCH] Code samples are completed to reflect all possible samples that exists in https://github.com/hazelcast/hazelcast-code-samples and can be applied to C++ client. --- examples/CMakeLists.txt | 2 + .../distributed-collections/CMakeLists.txt | 19 +++++ .../blockingqueue/CMakeLists.txt | 18 +++++ .../blockingqueue/Consumer.cpp | 46 +++++++++++ .../blockingqueue/Producer.cpp | 38 +++++++++ .../itemlisteners/CMakeLists.txt | 18 +++++ .../itemlisteners/CollectionChanger.cpp | 37 +++++++++ .../itemlisteners/ItemListener.cpp | 78 ++++++++++++++++++ .../list/CMakeLists.txt | 18 +++++ .../distributed-collections/list/Reader.cpp | 38 +++++++++ .../distributed-collections/list/Writer.cpp | 37 +++++++++ .../set/CMakeLists.txt | 18 +++++ .../distributed-collections/set/Reader.cpp | 38 +++++++++ .../distributed-collections/set/Writer.cpp | 37 +++++++++ examples/distributed-map/basic/FillMap.cpp | 28 ++++--- examples/distributed-map/basic/PrintAll.cpp | 19 ++--- .../criteria-api/Predicate.cpp | 38 ++++----- .../custom-attributes/CarAttributeDemo.cpp | 39 ++++----- .../entry-listener/ModifyMap.cpp | 21 ++--- .../distributed-map/entry-listener/main.cpp | 21 ++--- .../entry-processor/Employee.cpp | 6 +- .../entry-processor/Employee.h | 2 +- .../ModifyWithNoEntryProcessor.cpp | 41 +++++----- .../distributed-map/entry-processor/main.cpp | 27 +++---- .../distributed-map/eviction/EvictAll.cpp | 39 ++++----- examples/distributed-map/index/main.cpp | 57 ++++++------- .../locking/AbaProtectedOptimisticUpdate.cpp | 41 +++++----- .../locking/OptimisticUpdate.cpp | 45 +++++------ .../locking/PessimisticUpdate.cpp | 45 +++++------ .../distributed-map/locking/RacyUpdate.cpp | 37 ++++----- .../distributed-map/map-interceptor/main.cpp | 21 ++--- .../distributed-map/multimap/MultimapPut.cpp | 19 ++--- .../distributed-map/multimap/PrintValues.cpp | 37 ++++----- .../query-collections/main.cpp | 81 +++++++++---------- examples/distributed-map/sqlquery/main.cpp | 37 ++++----- .../atomiclong/main.cpp | 23 +++--- .../countdownlatch/Follower.cpp | 17 ++-- .../countdownlatch/Leader.cpp | 31 +++---- .../idgenerator/IdGenerator.cpp | 19 ++--- .../distributed-primitives/lock/RaceFree.cpp | 65 +++++++-------- examples/distributed-primitives/lock/Racy.cpp | 43 +++++----- .../semaphore/Semaphore.cpp | 33 ++++---- .../basic-pub-sub/Publisher.cpp | 15 ++-- .../basic-pub-sub/Subscriber.cpp | 21 ++--- .../configure-logging/main.cpp | 11 +-- .../destroying-instances/main.cpp | 21 ++--- .../learning-basics/unique-names/main.cpp | 17 ++-- examples/monitoring/cluster/main.cpp | 34 +++++--- .../socket-interceptor/main.cpp | 15 ++-- examples/network-configuration/tcpip/main.cpp | 21 ++--- .../identified-data-serializable/main.cpp | 37 ++++----- examples/serialization/portable/main.cpp | 37 ++++----- examples/spi/proxy/main.cpp | 14 ++-- .../transaction-basic/TransactionBasic.cpp | 7 +- .../include/hazelcast/client/ItemEvent.h | 2 +- 55 files changed, 955 insertions(+), 671 deletions(-) create mode 100644 examples/distributed-collections/CMakeLists.txt create mode 100644 examples/distributed-collections/blockingqueue/CMakeLists.txt create mode 100644 examples/distributed-collections/blockingqueue/Consumer.cpp create mode 100644 examples/distributed-collections/blockingqueue/Producer.cpp create mode 100644 examples/distributed-collections/itemlisteners/CMakeLists.txt create mode 100644 examples/distributed-collections/itemlisteners/CollectionChanger.cpp create mode 100644 examples/distributed-collections/itemlisteners/ItemListener.cpp create mode 100644 examples/distributed-collections/list/CMakeLists.txt create mode 100644 examples/distributed-collections/list/Reader.cpp create mode 100644 examples/distributed-collections/list/Writer.cpp create mode 100644 examples/distributed-collections/set/CMakeLists.txt create mode 100644 examples/distributed-collections/set/Reader.cpp create mode 100644 examples/distributed-collections/set/Writer.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 088d1a6ec9..ed5171482f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,6 +23,8 @@ add_subdirectory(learning-basics) add_subdirectory(distributed-topic) add_subdirectory(distributed-primitives) add_subdirectory(distributed-map) +add_subdirectory(distributed-collections) + diff --git a/examples/distributed-collections/CMakeLists.txt b/examples/distributed-collections/CMakeLists.txt new file mode 100644 index 0000000000..d3b3fe1c4b --- /dev/null +++ b/examples/distributed-collections/CMakeLists.txt @@ -0,0 +1,19 @@ +# +# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. +# +# 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. +# +add_subdirectory(blockingqueue) +add_subdirectory(itemlisteners) +add_subdirectory(list) +add_subdirectory(set) diff --git a/examples/distributed-collections/blockingqueue/CMakeLists.txt b/examples/distributed-collections/blockingqueue/CMakeLists.txt new file mode 100644 index 0000000000..b408b500dd --- /dev/null +++ b/examples/distributed-collections/blockingqueue/CMakeLists.txt @@ -0,0 +1,18 @@ +# +# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. +# +# 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. +# +add_executable(blockingqueueconsumer ./Consumer.cpp) +add_executable(blockingqueueproducer ./Producer.cpp) + diff --git a/examples/distributed-collections/blockingqueue/Consumer.cpp b/examples/distributed-collections/blockingqueue/Consumer.cpp new file mode 100644 index 0000000000..49d1f47fac --- /dev/null +++ b/examples/distributed-collections/blockingqueue/Consumer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IQueue queue = hz.getQueue("queue"); + + while (true) { + boost::shared_ptr item = queue.take(); + if (item.get()) { + std::cout << "Consumed: " << *item << std::endl; + + if (*item == -1) { + queue.put(-1); + break; + } + } else { + std::cout << "Retrieved item is null." << std::endl; + } + hazelcast::util::sleep(5); + } + std::cout << "Consumer Finished!" << std::endl; + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-collections/blockingqueue/Producer.cpp b/examples/distributed-collections/blockingqueue/Producer.cpp new file mode 100644 index 0000000000..152a62e42c --- /dev/null +++ b/examples/distributed-collections/blockingqueue/Producer.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IQueue queue = hz.getQueue("queue"); + + for (int k = 1; k < 100; k++) { + queue.put(k); + std::cout << "Producing: " << k << std::endl; + hazelcast::util::sleep(1); + } + queue.put(-1); + std::cout << "Producer Finished!" << std::endl; + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-collections/itemlisteners/CMakeLists.txt b/examples/distributed-collections/itemlisteners/CMakeLists.txt new file mode 100644 index 0000000000..b1b27c7329 --- /dev/null +++ b/examples/distributed-collections/itemlisteners/CMakeLists.txt @@ -0,0 +1,18 @@ +# +# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. +# +# 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. +# +add_executable(itemlistener ./ItemListener.cpp) +add_executable(collectionchanger ./CollectionChanger.cpp) + diff --git a/examples/distributed-collections/itemlisteners/CollectionChanger.cpp b/examples/distributed-collections/itemlisteners/CollectionChanger.cpp new file mode 100644 index 0000000000..3c8c44009f --- /dev/null +++ b/examples/distributed-collections/itemlisteners/CollectionChanger.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IQueue queue = hz.getQueue("queue"); + + queue.put("foo"); + queue.put("bar"); + queue.take(); + queue.take(); + + std::cout << "Changer Finished!" << std::endl; + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-collections/itemlisteners/ItemListener.cpp b/examples/distributed-collections/itemlisteners/ItemListener.cpp new file mode 100644 index 0000000000..d44fc1b0b5 --- /dev/null +++ b/examples/distributed-collections/itemlisteners/ItemListener.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +class ItemListenerImpl : public hazelcast::client::ItemListener { +public: + + ItemListenerImpl() : numAdded(0), numRemoved(0) { + } + + void itemAdded(const hazelcast::client::ItemEvent &item) { + std::cout << "Item added:" << item.getItem() << std::endl; + ++numAdded; + } + + void itemRemoved(const hazelcast::client::ItemEvent &item) { + std::cout << "Item removed:" << item.getItem() << std::endl; + ++numRemoved; + } + + + int getNumAdded() const { + return numAdded; + } + + int getNumRemoved() const { + return numRemoved; + } + +private: + int numAdded; + int numRemoved; +}; + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IQueue queue = hz.getQueue("queue"); + + ItemListenerImpl listener; + std::string registrationId = queue.addItemListener(listener, true); + + std::cout << "Registered the listener with registration id:" << registrationId << + "Waiting for the listener events!" << std::endl; + + hazelcast::util::sleep(5); + + std::cout << "Received " << listener.getNumAdded() << " items addition and " << listener.getNumRemoved() << + " items removal events." << std::endl; + + // unregister the listener + if (queue.removeItemListener(registrationId)) { + std::cout << "Removed the item listener with registration id " << registrationId << std::endl; + } else { + std::cout << "Failed to remove the item listener with registration id " << registrationId << std::endl; + } + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-collections/list/CMakeLists.txt b/examples/distributed-collections/list/CMakeLists.txt new file mode 100644 index 0000000000..199258fecf --- /dev/null +++ b/examples/distributed-collections/list/CMakeLists.txt @@ -0,0 +1,18 @@ +# +# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. +# +# 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. +# +add_executable(listreader ./Reader.cpp) +add_executable(listwriter ./Writer.cpp) + diff --git a/examples/distributed-collections/list/Reader.cpp b/examples/distributed-collections/list/Reader.cpp new file mode 100644 index 0000000000..6673a32634 --- /dev/null +++ b/examples/distributed-collections/list/Reader.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IList list = hz.getList("list"); + + std::vector listValues = list.toArray(); + + for (std::vector::const_iterator it = listValues.begin(); it != listValues.end(); ++it) { + std::cout << *it << std::endl; + } + + std::cout << "Reading finished!" << std::endl; + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-collections/list/Writer.cpp b/examples/distributed-collections/list/Writer.cpp new file mode 100644 index 0000000000..975587e656 --- /dev/null +++ b/examples/distributed-collections/list/Writer.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IList list = hz.getList("list"); + + list.add("Tokyo"); + list.add("Paris"); + list.add("London"); + list.add("New York"); + + std::cout << "Putting finished!" << std::endl; + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-collections/set/CMakeLists.txt b/examples/distributed-collections/set/CMakeLists.txt new file mode 100644 index 0000000000..7db847978c --- /dev/null +++ b/examples/distributed-collections/set/CMakeLists.txt @@ -0,0 +1,18 @@ +# +# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. +# +# 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. +# +add_executable(setreader ./Reader.cpp) +add_executable(setwriter ./Writer.cpp) + diff --git a/examples/distributed-collections/set/Reader.cpp b/examples/distributed-collections/set/Reader.cpp new file mode 100644 index 0000000000..66b80a2ae4 --- /dev/null +++ b/examples/distributed-collections/set/Reader.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::ISet set = hz.getSet("set"); + + std::vector listValues = set.toArray(); + + for (std::vector::const_iterator it = listValues.begin(); it != listValues.end(); ++it) { + std::cout << *it << std::endl; + } + + std::cout << "Reading finished!" << std::endl; + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-collections/set/Writer.cpp b/examples/distributed-collections/set/Writer.cpp new file mode 100644 index 0000000000..410a727a0d --- /dev/null +++ b/examples/distributed-collections/set/Writer.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * 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. + */ +// +// Created by İhsan Demir on 21/12/15. +// +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::ISet set = hz.getSet("set"); + + set.add("Tokyo"); + set.add("Paris"); + set.add("London"); + set.add("New York"); + + std::cout << "Putting finished!" << std::endl; + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/distributed-map/basic/FillMap.cpp b/examples/distributed-map/basic/FillMap.cpp index 884bed9a3e..46d1d8f7e0 100644 --- a/examples/distributed-map/basic/FillMap.cpp +++ b/examples/distributed-map/basic/FillMap.cpp @@ -19,18 +19,24 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("map"); - map.put("1", "Tokyo"); - map.put("2", "Paris"); - map.put("3", "New York"); - std::cout << "Finished loading map" << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + hazelcast::client::IMap map = hz.getMap("map"); + map.put("1", "Tokyo"); + map.put("2", "Paris"); + map.put("3", "New York"); + std::cout << "Finished loading map" << std::endl; + + hazelcast::client::IMap > binaryMap = hz.getMap >("MyBinaryMap"); + std::vector value(100); + int key = 3; + binaryMap.put(key, value); + std::cout << "Inserted an entry with key 3 and a binary value to the binary map." << std::endl; + + boost::shared_ptr > valueFromMap = binaryMap.get(key); + if (NULL != valueFromMap.get()) { + std::cout << "The binary map returned a binary array of size " << valueFromMap->size() << std::endl; } std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/basic/PrintAll.cpp b/examples/distributed-map/basic/PrintAll.cpp index 1925c0b03e..0d18df33ce 100644 --- a/examples/distributed-map/basic/PrintAll.cpp +++ b/examples/distributed-map/basic/PrintAll.cpp @@ -19,19 +19,14 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("map"); - std::vector > entries = map.entrySet(); - for (std::vector >::const_iterator it = entries.begin(); - it != entries.end(); ++it) { - std::cout << it->first << " " << it->second << std::endl; - } - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + hazelcast::client::IMap map = hz.getMap("map"); + std::vector > entries = map.entrySet(); + for (std::vector >::const_iterator it = entries.begin(); + it != entries.end(); ++it) { + std::cout << it->first << " " << it->second << std::endl; } std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/criteria-api/Predicate.cpp b/examples/distributed-map/criteria-api/Predicate.cpp index fbbdcc91d5..e6f36b1300 100644 --- a/examples/distributed-map/criteria-api/Predicate.cpp +++ b/examples/distributed-map/criteria-api/Predicate.cpp @@ -83,13 +83,13 @@ class Person : public hazelcast::client::serialization::IdentifiedDataSerializab int age; }; -std::ostream &operator << (std::ostream &out, const Person &p) { +std::ostream &operator<<(std::ostream &out, const Person &p) { const std::string *n = p.getName(); out << "Person{" - << "male=" << p.isMale() - << ", name='" << (NULL == n ? "No name" : n->c_str()) << "\'" - << ", age=" << p.getAge() - << '}'; + << "male=" << p.isMale() + << ", name='" << (NULL == n ? "No name" : n->c_str()) << "\'" + << ", age=" << p.getAge() + << '}'; return out; } @@ -111,7 +111,8 @@ class PredicateMember { return personMap.values(predicate); } - std::vector getWithNameAndAge(const char *name, int age, hazelcast::client::IMap &personMap) { + std::vector getWithNameAndAge(const char *name, int age, + hazelcast::client::IMap &personMap) { char buf[300]; hazelcast::util::snprintf(buf, 300, "name == %s AND age == %d", name, age); hazelcast::client::query::SqlPredicate predicate(buf); @@ -145,38 +146,33 @@ class PredicateMember { std::cout << "Get with name Peter" << std::endl; std::vector values = getWithName("Peter", personMap); - for (std::vector::iterator it = values.begin();it != values.end(); ++it) { - std::cout << *it << std::endl; + for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + std::cout << *it << std::endl; } std::cout << "Get not with name Peter" << std::endl; values = getNotWithName("Peter", personMap); - for (std::vector::const_iterator it = values.begin();it != values.end(); ++it) { - std::cout << *it << std::endl; + for (std::vector::const_iterator it = values.begin(); it != values.end(); ++it) { + std::cout << *it << std::endl; } std::cout << "Find name Peter and age 36" << std::endl; values = getWithNameAndAge("Peter", 36, personMap); - for (std::vector::const_iterator it = values.begin();it != values.end(); ++it) { - std::cout << *it << std::endl; + for (std::vector::const_iterator it = values.begin(); it != values.end(); ++it) { + std::cout << *it << std::endl; } std::cout << "Find name Peter and age 37" << std::endl; values = getWithNameAndAge("Peter", 37, personMap); - for (std::vector::const_iterator it = values.begin();it != values.end(); ++it) { - std::cout << *it << std::endl; + for (std::vector::const_iterator it = values.begin(); it != values.end(); ++it) { + std::cout << *it << std::endl; } } }; int main() { - try { - PredicateMember m; - m.run(); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + PredicateMember m; + m.run(); std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/custom-attributes/CarAttributeDemo.cpp b/examples/distributed-map/custom-attributes/CarAttributeDemo.cpp index e089e38f16..63ab20eaad 100644 --- a/examples/distributed-map/custom-attributes/CarAttributeDemo.cpp +++ b/examples/distributed-map/custom-attributes/CarAttributeDemo.cpp @@ -26,7 +26,7 @@ class Car : public hazelcast::client::serialization::IdentifiedDataSerializable public: Car() { } - Car(const char *name){ + Car(const char *name) { attributes["name"] = name; attributes["tripStart"] = "0"; attributes["tripStop"] = "0"; @@ -56,7 +56,7 @@ class Car : public hazelcast::client::serialization::IdentifiedDataSerializable } void writeData(hazelcast::client::serialization::ObjectDataOutput &out) const { - out.writeInt((int)attributes.size()); + out.writeInt((int) attributes.size()); for (std::map::const_iterator it = attributes.begin(); it != attributes.end(); ++it) { out.writeUTF(&it->first); @@ -85,14 +85,14 @@ class Car : public hazelcast::client::serialization::IdentifiedDataSerializable std::map attributes; }; -std::ostream &operator << (std::ostream &out, const Car &c) { +std::ostream &operator<<(std::ostream &out, const Car &c) { out << "Car{" - << "attributes={"; + << "attributes={"; const std::map &attrs = c.getAttributes(); for (std::map::const_iterator it = attrs.begin(); it != attrs.end();) { - out << "(" << it->first << ", " << it->second << ")"; + out << "(" << it->first << ", " << it->second << ")"; ++it; if (it != attrs.end()) { out << ", "; @@ -105,27 +105,22 @@ std::ostream &operator << (std::ostream &out, const Car &c) { } int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("cars"); + hazelcast::client::IMap map = hz.getMap("cars"); - map.put(1, Car("Audi Q7", 250, 22000)); - map.put(2, Car("BMW X5", 312, 34000)); - map.put(3, Car("Porsche Cayenne", 408, 57000)); + map.put(1, Car("Audi Q7", 250, 22000)); + map.put(2, Car("BMW X5", 312, 34000)); + map.put(3, Car("Porsche Cayenne", 408, 57000)); - // we're using a custom attribute called 'attribute' which is provided by the 'CarAttributeExtractor' - // we are also passing an argument 'mileage' to the extractor - hazelcast::client::query::SqlPredicate criteria("attribute[mileage] < 30000"); - std::vector cars = map.values(criteria); + // we're using a custom attribute called 'attribute' which is provided by the 'CarAttributeExtractor' + // we are also passing an argument 'mileage' to the extractor + hazelcast::client::query::SqlPredicate criteria("attribute[mileage] < 30000"); + std::vector cars = map.values(criteria); - for (std::vector::const_iterator it = cars.begin(); it != cars.end(); ++it) { - std::cout << (*it) << std::endl; - } - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + for (std::vector::const_iterator it = cars.begin(); it != cars.end(); ++it) { + std::cout << (*it) << std::endl; } std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/entry-listener/ModifyMap.cpp b/examples/distributed-map/entry-listener/ModifyMap.cpp index 79817542c7..e613b413f9 100644 --- a/examples/distributed-map/entry-listener/ModifyMap.cpp +++ b/examples/distributed-map/entry-listener/ModifyMap.cpp @@ -19,22 +19,17 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("somemap"); + hazelcast::client::IMap map = hz.getMap("somemap"); - std::ostringstream out; - out << time(NULL); + std::ostringstream out; + out << time(NULL); - map.put(out.str(), "1"); - map.put(out.str(), "2"); - map.deleteEntry(out.str()); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + map.put(out.str(), "1"); + map.put(out.str(), "2"); + map.deleteEntry(out.str()); std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/entry-listener/main.cpp b/examples/distributed-map/entry-listener/main.cpp index cdb4fcccfc..04df524f4e 100644 --- a/examples/distributed-map/entry-listener/main.cpp +++ b/examples/distributed-map/entry-listener/main.cpp @@ -55,24 +55,19 @@ class MyEntryListener : public hazelcast::client::EntryListener map = hz.getMap("somemap"); + hazelcast::client::IMap map = hz.getMap("somemap"); - MyEntryListener listener; + MyEntryListener listener; - map.addEntryListener(listener, true); + map.addEntryListener(listener, true); - std::cout << "EntryListener registered" << std::endl; + std::cout << "EntryListener registered" << std::endl; - // wait for modify map executable to run - hazelcast::util::sleep(10); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + // wait for modify map executable to run + hazelcast::util::sleep(10); std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/entry-processor/Employee.cpp b/examples/distributed-map/entry-processor/Employee.cpp index ff412a1d0c..98de2513e0 100644 --- a/examples/distributed-map/entry-processor/Employee.cpp +++ b/examples/distributed-map/entry-processor/Employee.cpp @@ -29,11 +29,11 @@ Employee::Employee() { Employee::Employee(int s) : salary(s) { } -int Employee::getFactoryId() const{ +int Employee::getFactoryId() const { return 1; } -int Employee::getClassId() const{ +int Employee::getClassId() const { return 5; } @@ -41,7 +41,7 @@ void Employee::writeData(hazelcast::client::serialization::ObjectDataOutput &out out.writeInt(salary); } -void Employee::readData(hazelcast::client::serialization::ObjectDataInput &in){ +void Employee::readData(hazelcast::client::serialization::ObjectDataInput &in) { salary = in.readInt(); } diff --git a/examples/distributed-map/entry-processor/Employee.h b/examples/distributed-map/entry-processor/Employee.h index ba924ac23c..e8a903a836 100644 --- a/examples/distributed-map/entry-processor/Employee.h +++ b/examples/distributed-map/entry-processor/Employee.h @@ -39,10 +39,10 @@ class Employee : public hazelcast::client::serialization::IdentifiedDataSerializ void incSalary(int amount); int getSalary() const; + private: int salary; }; - #endif //HAZELCAST_EXAMPLES_DISTRIBUTED_MAP_ENTRYPROCESSOR_EMPLOYEE_H diff --git a/examples/distributed-map/entry-processor/ModifyWithNoEntryProcessor.cpp b/examples/distributed-map/entry-processor/ModifyWithNoEntryProcessor.cpp index 83a7322526..1d41a411d2 100644 --- a/examples/distributed-map/entry-processor/ModifyWithNoEntryProcessor.cpp +++ b/examples/distributed-map/entry-processor/ModifyWithNoEntryProcessor.cpp @@ -20,37 +20,32 @@ #include "Employee.h" int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap employees = hz.getMap("employees"); + hazelcast::client::IMap employees = hz.getMap("employees"); - employees.put("John", Employee(1000)); - employees.put("Mark", Employee(1000)); - employees.put("Spencer", Employee(1000)); + employees.put("John", Employee(1000)); + employees.put("Mark", Employee(1000)); + employees.put("Spencer", Employee(1000)); - std::vector > entries = employees.entrySet(); + std::vector > entries = employees.entrySet(); - for (std::vector >::const_iterator it = entries.begin(); - it != entries.end(); ++it) { - boost::shared_ptr employee = employees.get(it->first); - employee->incSalary(10); - employees.put(it->first, *employee); - } - - entries = employees.entrySet(); + for (std::vector >::const_iterator it = entries.begin(); + it != entries.end(); ++it) { + boost::shared_ptr employee = employees.get(it->first); + employee->incSalary(10); + employees.put(it->first, *employee); + } - for (std::vector >::const_iterator it = entries.begin(); - it != entries.end(); ++it) { - std::cout << it->first << " salary: " << it->second.getSalary() << std::endl; - } + entries = employees.entrySet(); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + for (std::vector >::const_iterator it = entries.begin(); + it != entries.end(); ++it) { + std::cout << it->first << " salary: " << it->second.getSalary() << std::endl; } + std::cout << "Finished" << std::endl; return 0; diff --git a/examples/distributed-map/entry-processor/main.cpp b/examples/distributed-map/entry-processor/main.cpp index 02aa32bfb6..3e0ac9d910 100644 --- a/examples/distributed-map/entry-processor/main.cpp +++ b/examples/distributed-map/entry-processor/main.cpp @@ -39,26 +39,21 @@ class EmployeeRaiseEntryProcessor : public hazelcast::client::serialization::Ide int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap employees = hz.getMap("employees"); + hazelcast::client::IMap employees = hz.getMap("employees"); - employees.put("John", Employee(1000)); - employees.put("Mark", Employee(1000)); - employees.put("Spencer", Employee(1000)); + employees.put("John", Employee(1000)); + employees.put("Mark", Employee(1000)); + employees.put("Spencer", Employee(1000)); - EmployeeRaiseEntryProcessor processor; - std::map > result = - employees.executeOnEntries(processor); + EmployeeRaiseEntryProcessor processor; + std::map > result = + employees.executeOnEntries(processor); - for (std::map >::const_iterator it = result.begin();it != result.end(); ++it) { - std::cout << it->first << " salary: " << *it->second << std::endl; - } - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + for (std::map >::const_iterator it = result.begin(); it != result.end(); ++it) { + std::cout << it->first << " salary: " << *it->second << std::endl; } std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/eviction/EvictAll.cpp b/examples/distributed-map/eviction/EvictAll.cpp index 75d655e062..e0cfa94caa 100644 --- a/examples/distributed-map/eviction/EvictAll.cpp +++ b/examples/distributed-map/eviction/EvictAll.cpp @@ -19,35 +19,30 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("evictiontestmap"); + hazelcast::client::IMap map = hz.getMap("evictiontestmap"); - int numberOfKeysToLock = 4; - int numberOfEntriesToAdd = 1000; + int numberOfKeysToLock = 4; + int numberOfEntriesToAdd = 1000; - for (int i = 0; i < numberOfEntriesToAdd; i++) { - map.put(i, i); - } + for (int i = 0; i < numberOfEntriesToAdd; i++) { + map.put(i, i); + } - for (int i = 0; i < numberOfKeysToLock; i++) { - map.lock(i); - } + for (int i = 0; i < numberOfKeysToLock; i++) { + map.lock(i); + } - std::cout << "# Map size before evictAll\t:" << map.size() << std::endl; + std::cout << "# Map size before evictAll\t:" << map.size() << std::endl; - // should keep locked keys and evict all others. - map.evictAll(); + // should keep locked keys and evict all others. + map.evictAll(); - std::cout << "# After calling evictAll..." << std::endl; - std::cout << "# Expected map size\t: " << numberOfKeysToLock << std::endl; - std::cout << "# Actual map size\t: " << map.size() << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + std::cout << "# After calling evictAll..." << std::endl; + std::cout << "# Expected map size\t: " << numberOfKeysToLock << std::endl; + std::cout << "# Actual map size\t: " << map.size() << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/index/main.cpp b/examples/distributed-map/index/main.cpp index a3dd9c4474..e724847ee0 100644 --- a/examples/distributed-map/index/main.cpp +++ b/examples/distributed-map/index/main.cpp @@ -81,38 +81,33 @@ class Person : public hazelcast::client::serialization::IdentifiedDataSerializab }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); - - hazelcast::client::IMap map = - hz.getMap("personsWithIndex"); - - map.addIndex("name", true); - - const int mapSize = 200000; - - char buf[30]; - char name[30]; - time_t start = time(NULL); - for (int i = 0; i < mapSize; ++i) { - hazelcast::util::snprintf(buf, 30, "person-%d", i); - hazelcast::util::snprintf(name, 50, "myname-%d", i % 1000); - Person p(name, (i%2==0), (i % 100)); - map.put(buf, p); - } - time_t end = time(NULL); - std::cout << "Put " << mapSize << " entries into the map in " << end - start << " seconds" << std::endl; - - start = time(NULL); - hazelcast::client::query::SqlPredicate predicate("name == 'myname-30'"); - std::vector > entries = map.entrySet(predicate); - end = time(NULL); - std::cout << "The query resulted in " << entries.size() << " entries in " << end-start << " seconds" << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IMap map = + hz.getMap("personsWithIndex"); + + map.addIndex("name", true); + + const int mapSize = 200000; + + char buf[30]; + char name[30]; + time_t start = time(NULL); + for (int i = 0; i < mapSize; ++i) { + hazelcast::util::snprintf(buf, 30, "person-%d", i); + hazelcast::util::snprintf(name, 50, "myname-%d", i % 1000); + Person p(name, (i % 2 == 0), (i % 100)); + map.put(buf, p); } + time_t end = time(NULL); + std::cout << "Put " << mapSize << " entries into the map in " << end - start << " seconds" << std::endl; + + start = time(NULL); + hazelcast::client::query::SqlPredicate predicate("name == 'myname-30'"); + std::vector > entries = map.entrySet(predicate); + end = time(NULL); + std::cout << "The query resulted in " << entries.size() << " entries in " << end - start << " seconds" << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/locking/AbaProtectedOptimisticUpdate.cpp b/examples/distributed-map/locking/AbaProtectedOptimisticUpdate.cpp index 7c27d79e33..511bc72ff3 100644 --- a/examples/distributed-map/locking/AbaProtectedOptimisticUpdate.cpp +++ b/examples/distributed-map/locking/AbaProtectedOptimisticUpdate.cpp @@ -60,33 +60,28 @@ class Value : public hazelcast::client::serialization::IdentifiedDataSerializabl }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = - hz.getMap("map"); + hazelcast::client::IMap map = + hz.getMap("map"); - std::string key("1"); - Value v; - map.put(key, v); - std::cout << "Starting" << std::endl; - for (int k = 0; k < 1000; k++) { - for (; ; ) { - boost::shared_ptr oldValue = map.get(key); - Value newValue(*oldValue); - hazelcast::util::sleepmillis(10); - newValue.amount++; - newValue.version++; - if (map.replace(key, *oldValue, newValue)) - break; - } + std::string key("1"); + Value v; + map.put(key, v); + std::cout << "Starting" << std::endl; + for (int k = 0; k < 1000; k++) { + for (; ;) { + boost::shared_ptr oldValue = map.get(key); + Value newValue(*oldValue); + hazelcast::util::sleepmillis(10); + newValue.amount++; + newValue.version++; + if (map.replace(key, *oldValue, newValue)) + break; } - std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); } + std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/locking/OptimisticUpdate.cpp b/examples/distributed-map/locking/OptimisticUpdate.cpp index ae8e159bb6..253510abd8 100644 --- a/examples/distributed-map/locking/OptimisticUpdate.cpp +++ b/examples/distributed-map/locking/OptimisticUpdate.cpp @@ -55,35 +55,30 @@ class Value : public hazelcast::client::serialization::IdentifiedDataSerializabl }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = - hz.getMap("map"); + hazelcast::client::IMap map = + hz.getMap("map"); - std::string key("1"); - Value v; - map.put(key, v); - std::cout << "Starting" << std::endl; - for (int k = 0; k < 1000; k++) { - if (k % 10 == 0) { - std::cout << "At: " << k << std::endl; - } - for (; ;) { - boost::shared_ptr oldValue = map.get(key); - Value newValue(*oldValue); - hazelcast::util::sleepmillis(10); - newValue.amount++; - if (map.replace(key, *oldValue, newValue)) - break; - } + std::string key("1"); + Value v; + map.put(key, v); + std::cout << "Starting" << std::endl; + for (int k = 0; k < 1000; k++) { + if (k % 10 == 0) { + std::cout << "At: " << k << std::endl; + } + for (; ;) { + boost::shared_ptr oldValue = map.get(key); + Value newValue(*oldValue); + hazelcast::util::sleepmillis(10); + newValue.amount++; + if (map.replace(key, *oldValue, newValue)) + break; } - std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); } + std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/locking/PessimisticUpdate.cpp b/examples/distributed-map/locking/PessimisticUpdate.cpp index d8e88ce408..13f359266a 100644 --- a/examples/distributed-map/locking/PessimisticUpdate.cpp +++ b/examples/distributed-map/locking/PessimisticUpdate.cpp @@ -55,36 +55,31 @@ class Value : public hazelcast::client::serialization::IdentifiedDataSerializabl }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = - hz.getMap("map"); + hazelcast::client::IMap map = + hz.getMap("map"); - std::string key("1"); - Value v; - map.put(key, v); - std::cout << "Starting" << std::endl; - for (int k = 0; k < 1000; k++) { - map.lock(key); - try { - map.get(key); - hazelcast::util::sleepmillis(10); - v.amount++; - map.put(key, v); + std::string key("1"); + Value v; + map.put(key, v); + std::cout << "Starting" << std::endl; + for (int k = 0; k < 1000; k++) { + map.lock(key); + try { + map.get(key); + hazelcast::util::sleepmillis(10); + v.amount++; + map.put(key, v); - map.unlock(key); - } catch (...) { - map.unlock(key); - throw; - } + map.unlock(key); + } catch (hazelcast::client::exception::IException &e) { + map.unlock(key); + throw; } - std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); } + std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/locking/RacyUpdate.cpp b/examples/distributed-map/locking/RacyUpdate.cpp index bd495811e7..98eda01485 100644 --- a/examples/distributed-map/locking/RacyUpdate.cpp +++ b/examples/distributed-map/locking/RacyUpdate.cpp @@ -55,31 +55,26 @@ class Value : public hazelcast::client::serialization::IdentifiedDataSerializabl }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = - hz.getMap("map"); + hazelcast::client::IMap map = + hz.getMap("map"); - std::string key("1"); - Value v; - map.put(key, v); - std::cout << "Starting" << std::endl; - for (int k = 0; k < 1000; k++) { - if (k % 100 == 0) { - std::cout << "At: " << k << std::endl; - } - - boost::shared_ptr oldValue = map.get(key); - hazelcast::util::sleepmillis(10); - map.put(key, *oldValue); + std::string key("1"); + Value v; + map.put(key, v); + std::cout << "Starting" << std::endl; + for (int k = 0; k < 1000; k++) { + if (k % 100 == 0) { + std::cout << "At: " << k << std::endl; } - std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + + boost::shared_ptr oldValue = map.get(key); + hazelcast::util::sleepmillis(10); + map.put(key, *oldValue); } + std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/map-interceptor/main.cpp b/examples/distributed-map/map-interceptor/main.cpp index f194aac935..4a5f6a3cb8 100644 --- a/examples/distributed-map/map-interceptor/main.cpp +++ b/examples/distributed-map/map-interceptor/main.cpp @@ -38,23 +38,18 @@ class MapInterceptor : public hazelcast::client::serialization::IdentifiedDataSe }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = - hz.getMap("themap"); + hazelcast::client::IMap map = + hz.getMap("themap"); - MapInterceptor interceptor; - map.addInterceptor(interceptor); + MapInterceptor interceptor; + map.addInterceptor(interceptor); - map.put("1", "1"); + map.put("1", "1"); - std::cout << "The modified value (modified by the interceptor) at the server:" << map.get("1") << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + std::cout << "The modified value (modified by the interceptor) at the server:" << map.get("1") << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/multimap/MultimapPut.cpp b/examples/distributed-map/multimap/MultimapPut.cpp index b92f1478cb..fb799e79f0 100644 --- a/examples/distributed-map/multimap/MultimapPut.cpp +++ b/examples/distributed-map/multimap/MultimapPut.cpp @@ -19,20 +19,15 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::MultiMap map = - hz.getMultiMap("map"); + hazelcast::client::MultiMap map = + hz.getMultiMap("map"); - map.put("a", "1"); - map.put("a", "2"); - map.put("b", "3"); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + map.put("a", "1"); + map.put("a", "2"); + map.put("b", "3"); std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/multimap/PrintValues.cpp b/examples/distributed-map/multimap/PrintValues.cpp index fcef8cb18d..5ab982a78d 100644 --- a/examples/distributed-map/multimap/PrintValues.cpp +++ b/examples/distributed-map/multimap/PrintValues.cpp @@ -19,30 +19,25 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::MultiMap map = - hz.getMultiMap("map"); + hazelcast::client::MultiMap map = + hz.getMultiMap("map"); - std::vector keys = map.keySet(); - - for (std::vector::const_iterator it = keys.begin(); it != keys.end(); ++it) { - std::vector values = map.get(*it); - std::cout << *it << " -> (" ; - for (std::vector::const_iterator valIt = values.begin();valIt != values.end();) { - std::cout << *valIt << std::endl; - ++valIt; - if (valIt != values.end()) { - std::cout << ", "; - } - } - std::cout << ")" << std::endl; + std::vector keys = map.keySet(); + + for (std::vector::const_iterator it = keys.begin(); it != keys.end(); ++it) { + std::vector values = map.get(*it); + std::cout << *it << " -> ("; + for (std::vector::const_iterator valIt = values.begin(); valIt != values.end();) { + std::cout << *valIt << std::endl; + ++valIt; + if (valIt != values.end()) { + std::cout << ", "; + } } - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + std::cout << ")" << std::endl; } std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/query-collections/main.cpp b/examples/distributed-map/query-collections/main.cpp index 4c7130c7f3..d67e27b715 100644 --- a/examples/distributed-map/query-collections/main.cpp +++ b/examples/distributed-map/query-collections/main.cpp @@ -67,7 +67,7 @@ class Person : public hazelcast::client::serialization::IdentifiedDataSerializab void writeData(hazelcast::client::serialization::ObjectDataOutput &out) const { out.writeUTF(&name); - int size = (int)limbs.size(); + int size = (int) limbs.size(); out.writeInt(size); for (int i = 0; i < size; ++i) { out.writeObject(&limbs[i]); @@ -98,51 +98,46 @@ class Person : public hazelcast::client::serialization::IdentifiedDataSerializab }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); - - hazelcast::client::IMap map = - hz.getMap("map"); - - std::vector legs; - legs.push_back(Limb("left-leg")); - legs.push_back(Limb("right-leg")); - - std::vector hands; - hands.push_back(Limb("left-hand")); - hands.push_back(Limb("right-hand")); - - std::vector arms; - hands.push_back(Limb("left-arm")); - hands.push_back(Limb("right-arm")); - - map.put(1, Person("Georg", legs)); - map.put(2, Person("Peter", hands)); - map.put(3, Person("Hans", legs)); - map.put(4, Person("Stefanie", arms)); - - hazelcast::client::query::SqlPredicate predicate("limbs[any].name == right-leg"); - std::vector employees = map.values(predicate); - - std::cout << "People:" << std::endl; - for (std::vector::const_iterator it = employees.begin(); it != employees.end(); ++it) { - std::cout << (*it).getName() << ", Limbs are:{"; - const std::vector &values = it->getLimbs(); - for (std::vector::const_iterator valIt = values.begin(); valIt != values.end();) { - std::cout << valIt->getName(); - ++valIt; - if (valIt != values.end()) { - std::cout << ", "; - } + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IMap map = + hz.getMap("map"); + + std::vector legs; + legs.push_back(Limb("left-leg")); + legs.push_back(Limb("right-leg")); + + std::vector hands; + hands.push_back(Limb("left-hand")); + hands.push_back(Limb("right-hand")); + + std::vector arms; + hands.push_back(Limb("left-arm")); + hands.push_back(Limb("right-arm")); + + map.put(1, Person("Georg", legs)); + map.put(2, Person("Peter", hands)); + map.put(3, Person("Hans", legs)); + map.put(4, Person("Stefanie", arms)); + + hazelcast::client::query::SqlPredicate predicate("limbs[any].name == right-leg"); + std::vector employees = map.values(predicate); + + std::cout << "People:" << std::endl; + for (std::vector::const_iterator it = employees.begin(); it != employees.end(); ++it) { + std::cout << (*it).getName() << ", Limbs are:{"; + const std::vector &values = it->getLimbs(); + for (std::vector::const_iterator valIt = values.begin(); valIt != values.end();) { + std::cout << valIt->getName(); + ++valIt; + if (valIt != values.end()) { + std::cout << ", "; } - std::cout << "}, "; } - std::cout << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + std::cout << "}, "; } + std::cout << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-map/sqlquery/main.cpp b/examples/distributed-map/sqlquery/main.cpp index ff4dbdd1a5..be0ae00b75 100644 --- a/examples/distributed-map/sqlquery/main.cpp +++ b/examples/distributed-map/sqlquery/main.cpp @@ -86,29 +86,24 @@ std::ostream &operator<<(std::ostream &out, const Person &p) { } int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); - - hazelcast::client::IMap map = - hz.getMap("map"); - - map.put("1", Person("peter", true, 36)); - map.put("2", Person("cathy", false, 40)); - map.put("3", Person("roger", true, 20)); - - hazelcast::client::query::SqlPredicate predicate("active AND age < 30"); - std::vector employees = map.values(predicate); - std::cout << "Employees:" << std::endl; - for (std::vector::const_iterator it = employees.begin(); it != employees.end(); ++it) { - std::cout << (*it) << std::endl; - } - std::cout << std::endl; + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IMap map = + hz.getMap("map"); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + map.put("1", Person("peter", true, 36)); + map.put("2", Person("cathy", false, 40)); + map.put("3", Person("roger", true, 20)); + + hazelcast::client::query::SqlPredicate predicate("active AND age < 30"); + std::vector employees = map.values(predicate); + std::cout << "Employees:" << std::endl; + for (std::vector::const_iterator it = employees.begin(); it != employees.end(); ++it) { + std::cout << (*it) << std::endl; } + std::cout << std::endl; + std::cout << "Finished" << std::endl; diff --git a/examples/distributed-primitives/atomiclong/main.cpp b/examples/distributed-primitives/atomiclong/main.cpp index a0d1921247..89f1e0753c 100644 --- a/examples/distributed-primitives/atomiclong/main.cpp +++ b/examples/distributed-primitives/atomiclong/main.cpp @@ -20,25 +20,20 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IAtomicLong counter = hz.getIAtomicLong("counter"); + hazelcast::client::IAtomicLong counter = hz.getIAtomicLong("counter"); - for (int i = 0; i < 1000 * 1000; ++i) { - if (i % 500000 == 0) { - std::cout << "At:" << i << std::endl; - } - counter.incrementAndGet(); + for (int i = 0; i < 1000 * 1000; ++i) { + if (i % 500000 == 0) { + std::cout << "At:" << i << std::endl; } - - std::cout << "Count is:" << counter.get() << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + counter.incrementAndGet(); } + std::cout << "Count is:" << counter.get() << std::endl; + std::cout << "Finished" << std::endl; return 0; diff --git a/examples/distributed-primitives/countdownlatch/Follower.cpp b/examples/distributed-primitives/countdownlatch/Follower.cpp index 418439ae44..c216f2bbcc 100644 --- a/examples/distributed-primitives/countdownlatch/Follower.cpp +++ b/examples/distributed-primitives/countdownlatch/Follower.cpp @@ -20,21 +20,16 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::ICountDownLatch latch = hz.getICountDownLatch("countDownLatch"); + hazelcast::client::ICountDownLatch latch = hz.getICountDownLatch("countDownLatch"); - std::cout << "Waiting" << std::endl; + std::cout << "Waiting" << std::endl; - bool success = latch.await(30000); + bool success = latch.await(30000); - std::cout << "Complete:" << success << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + std::cout << "Complete:" << success << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-primitives/countdownlatch/Leader.cpp b/examples/distributed-primitives/countdownlatch/Leader.cpp index 0821e65f94..014b466cc8 100644 --- a/examples/distributed-primitives/countdownlatch/Leader.cpp +++ b/examples/distributed-primitives/countdownlatch/Leader.cpp @@ -20,31 +20,26 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::ICountDownLatch latch = hz.getICountDownLatch("countDownLatch"); + hazelcast::client::ICountDownLatch latch = hz.getICountDownLatch("countDownLatch"); - std::cout << "Starting" << std::endl; + std::cout << "Starting" << std::endl; - //we init the latch with 1, since we only need to complete a single step. - latch.trySetCount(1); + //we init the latch with 1, since we only need to complete a single step. + latch.trySetCount(1); - //do some sleeping to simulate doing something - hazelcast::util::sleep(30); + //do some sleeping to simulate doing something + hazelcast::util::sleep(30); - //now we do a countdown which notifies all followers - latch.countDown(); + //now we do a countdown which notifies all followers + latch.countDown(); - std::cout << "Leader finished" << std::endl; + std::cout << "Leader finished" << std::endl; - //we need to clean up the latch - latch.destroy(); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + //we need to clean up the latch + latch.destroy(); std::cout << "Finished" << std::endl; diff --git a/examples/distributed-primitives/idgenerator/IdGenerator.cpp b/examples/distributed-primitives/idgenerator/IdGenerator.cpp index 8ac6c00f17..f86061d955 100644 --- a/examples/distributed-primitives/idgenerator/IdGenerator.cpp +++ b/examples/distributed-primitives/idgenerator/IdGenerator.cpp @@ -20,21 +20,16 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IdGenerator generator = hz.getIdGenerator("idGenerator"); - for (int i = 0; i < 10000; ++i) { - hazelcast::util::sleep(1); - std::cout << "Id : " << generator.newId() << std::endl; - } - - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + hazelcast::client::IdGenerator generator = hz.getIdGenerator("idGenerator"); + for (int i = 0; i < 10000; ++i) { + hazelcast::util::sleep(1); + std::cout << "Id : " << generator.newId() << std::endl; } + std::cout << "Finished" << std::endl; return 0; diff --git a/examples/distributed-primitives/lock/RaceFree.cpp b/examples/distributed-primitives/lock/RaceFree.cpp index 3f565b117d..020bdd2159 100644 --- a/examples/distributed-primitives/lock/RaceFree.cpp +++ b/examples/distributed-primitives/lock/RaceFree.cpp @@ -21,54 +21,51 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IAtomicLong number1 = hz.getIAtomicLong("number1"); - hazelcast::client::IAtomicLong number2 = hz.getIAtomicLong("number2"); - hazelcast::client::ILock lock = hz.getILock("lock"); - std::cout << "Started" << std::endl; - for (int k = 0; k < 1000000; k++) { - if (k % 100 == 0) { - std::cout << "at:" << k << std::endl; - } - - lock.lock(); + hazelcast::client::IAtomicLong number1 = hz.getIAtomicLong("number1"); + hazelcast::client::IAtomicLong number2 = hz.getIAtomicLong("number2"); + hazelcast::client::ILock lock = hz.getILock("lock"); + std::cout << "Started" << std::endl; + for (int k = 0; k < 1000000; k++) { + if (k % 100 == 0) { + std::cout << "at:" << k << std::endl; + } - try { - if (k % 2 == 0) { - long n1 = number1.get(); - hazelcast::util::sleepmillis(10); - long n2 = number2.get(); - if (n1 - n2 != 0) { - std::cout << "Datarace detected at" << k << " !" << std::endl; - } - } else { - number1.incrementAndGet(); - number2.incrementAndGet(); - } - } catch (...) { - lock.unlock(); - throw; - } + lock.lock(); + try { if (k % 2 == 0) { long n1 = number1.get(); - hazelcast::util::sleepmillis(100); + hazelcast::util::sleepmillis(10); long n2 = number2.get(); if (n1 - n2 != 0) { - std::cout << "Difference detected at" << k << " !" << std::endl; + std::cout << "Datarace detected at" << k << " !" << std::endl; } } else { number1.incrementAndGet(); number2.incrementAndGet(); } + } catch (hazelcast::client::exception::IException &e) { + lock.unlock(); + throw; + } + + if (k % 2 == 0) { + long n1 = number1.get(); + hazelcast::util::sleepmillis(100); + long n2 = number2.get(); + if (n1 - n2 != 0) { + std::cout << "Difference detected at" << k << " !" << std::endl; + } + } else { + number1.incrementAndGet(); + number2.incrementAndGet(); } - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); + // release the lock + lock.unlock(); } std::cout << "Finished" << std::endl; diff --git a/examples/distributed-primitives/lock/Racy.cpp b/examples/distributed-primitives/lock/Racy.cpp index e61ba504a6..9665e638ed 100644 --- a/examples/distributed-primitives/lock/Racy.cpp +++ b/examples/distributed-primitives/lock/Racy.cpp @@ -20,35 +20,30 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IAtomicLong number1 = hz.getIAtomicLong("number1"); - hazelcast::client::IAtomicLong number2 = hz.getIAtomicLong("number2"); - std::cout << "Started" << std::endl; - for (int k = 0; k < 1000000; k++) { - if (k % 10000 == 0) { - std::cout << "at:" << k << std::endl; - } - if (k % 2 == 0) { - long n1 = number1.get(); - hazelcast::util::sleepmillis(100); - long n2 = number2.get(); - if (n1 - n2 != 0) { - std::cout << "Difference detected at" << k << " !" << std::endl; - } - } else { - number1.incrementAndGet(); - number2.incrementAndGet(); + hazelcast::client::IAtomicLong number1 = hz.getIAtomicLong("number1"); + hazelcast::client::IAtomicLong number2 = hz.getIAtomicLong("number2"); + std::cout << "Started" << std::endl; + for (int k = 0; k < 1000000; k++) { + if (k % 10000 == 0) { + std::cout << "at:" << k << std::endl; + } + if (k % 2 == 0) { + long n1 = number1.get(); + hazelcast::util::sleepmillis(100); + long n2 = number2.get(); + if (n1 - n2 != 0) { + std::cout << "Difference detected at" << k << " !" << std::endl; } + } else { + number1.incrementAndGet(); + number2.incrementAndGet(); } - - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); } + std::cout << "Finished" << std::endl; return 0; diff --git a/examples/distributed-primitives/semaphore/Semaphore.cpp b/examples/distributed-primitives/semaphore/Semaphore.cpp index 314fbe0162..f289e947d4 100644 --- a/examples/distributed-primitives/semaphore/Semaphore.cpp +++ b/examples/distributed-primitives/semaphore/Semaphore.cpp @@ -21,27 +21,22 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::ISemaphore semaphore = hz.getISemaphore("semaphore"); - hazelcast::client::IAtomicLong resource = hz.getIAtomicLong("resource"); - for (int k = 0; k < 1000; k++) { - std::cout << "At iteration: " << k << ", Active Threads: " << resource.get() << std::endl; - semaphore.acquire(); - try { - resource.incrementAndGet(); - hazelcast::util::sleep(1); - resource.decrementAndGet(); - } catch (...) { - semaphore.release(); - throw; - } + hazelcast::client::ISemaphore semaphore = hz.getISemaphore("semaphore"); + hazelcast::client::IAtomicLong resource = hz.getIAtomicLong("resource"); + for (int k = 0; k < 1000; k++) { + std::cout << "At iteration: " << k << ", Active Threads: " << resource.get() << std::endl; + semaphore.acquire(); + try { + resource.incrementAndGet(); + hazelcast::util::sleep(1); + resource.decrementAndGet(); + } catch (hazelcast::client::exception::IException &e) { + semaphore.release(); + throw; } - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); } std::cout << "Finished" << std::endl; diff --git a/examples/distributed-topic/basic-pub-sub/Publisher.cpp b/examples/distributed-topic/basic-pub-sub/Publisher.cpp index 04da14f701..9bf75f837c 100644 --- a/examples/distributed-topic/basic-pub-sub/Publisher.cpp +++ b/examples/distributed-topic/basic-pub-sub/Publisher.cpp @@ -19,17 +19,12 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::ITopic topic = hz.getTopic("testtopic"); - topic.publish("first message"); - std::cout << "Published: Published the message." << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + hazelcast::client::ITopic topic = hz.getTopic("testtopic"); + topic.publish("first message"); + std::cout << "Published: Published the message." << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/distributed-topic/basic-pub-sub/Subscriber.cpp b/examples/distributed-topic/basic-pub-sub/Subscriber.cpp index 20d099c1d4..5eec7693a5 100644 --- a/examples/distributed-topic/basic-pub-sub/Subscriber.cpp +++ b/examples/distributed-topic/basic-pub-sub/Subscriber.cpp @@ -19,26 +19,21 @@ #include class MyTopicListener { - public: +public: void onMessage(hazelcast::client::topic::Message msg) { std::cout << "[MyTopicListener::onMessage] Message received:" << msg.getMessageObject() << std::endl; } }; int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::ITopic topic = hz.getTopic("testtopic"); - MyTopicListener listener; - topic.addMessageListener(listener); - std::cout << "Subscriber: Added topic listener. Waiting 5 seconds for the published topic." << std::endl; - hazelcast::util::sleep(5); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + hazelcast::client::ITopic topic = hz.getTopic("testtopic"); + MyTopicListener listener; + topic.addMessageListener(listener); + std::cout << "Subscriber: Added topic listener. Waiting 5 seconds for the published topic." << std::endl; + hazelcast::util::sleep(5); std::cout << "Finished" << std::endl; diff --git a/examples/learning-basics/configure-logging/main.cpp b/examples/learning-basics/configure-logging/main.cpp index a5d52244f7..26b3dc9445 100644 --- a/examples/learning-basics/configure-logging/main.cpp +++ b/examples/learning-basics/configure-logging/main.cpp @@ -20,14 +20,9 @@ int main() { - try { - hazelcast::client::ClientConfig config; - config.setLogLevel(hazelcast::client::FINEST); - hazelcast::client::HazelcastClient hz(config); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + hazelcast::client::ClientConfig config; + config.setLogLevel(hazelcast::client::FINEST); + hazelcast::client::HazelcastClient hz(config); std::cout << "Finished" << std::endl; diff --git a/examples/learning-basics/destroying-instances/main.cpp b/examples/learning-basics/destroying-instances/main.cpp index b890deb019..c519ab96c2 100644 --- a/examples/learning-basics/destroying-instances/main.cpp +++ b/examples/learning-basics/destroying-instances/main.cpp @@ -19,22 +19,17 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IQueue q1 = hz.getQueue("q"); - hazelcast::client::IQueue q2 = hz.getQueue("q"); + hazelcast::client::IQueue q1 = hz.getQueue("q"); + hazelcast::client::IQueue q2 = hz.getQueue("q"); - q1.put("foo"); - std::cout << "q1.size:" << q1.size() << " q2.size:" << q2.size() << std::endl; + q1.put("foo"); + std::cout << "q1.size:" << q1.size() << " q2.size:" << q2.size() << std::endl; - q1.destroy(); - std::cout << "q1.size:" << q1.size() << " q2.size:" << q2.size() << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + q1.destroy(); + std::cout << "q1.size:" << q1.size() << " q2.size:" << q2.size() << std::endl; std::cout << "Finished" << std::endl; diff --git a/examples/learning-basics/unique-names/main.cpp b/examples/learning-basics/unique-names/main.cpp index b580245724..caf719d4f6 100644 --- a/examples/learning-basics/unique-names/main.cpp +++ b/examples/learning-basics/unique-names/main.cpp @@ -20,19 +20,14 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IdGenerator idGenerator = hz.getIdGenerator("idGenerator"); - std::ostringstream out("somemap"); - out << idGenerator.newId(); - hazelcast::client::IMap map = hz.getMap(out.str()); + hazelcast::client::IdGenerator idGenerator = hz.getIdGenerator("idGenerator"); + std::ostringstream out("somemap"); + out << idGenerator.newId(); + hazelcast::client::IMap map = hz.getMap(out.str()); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } std::cout << "Finished" << std::endl; diff --git a/examples/monitoring/cluster/main.cpp b/examples/monitoring/cluster/main.cpp index d4d5bcf5e5..2c3753d986 100644 --- a/examples/monitoring/cluster/main.cpp +++ b/examples/monitoring/cluster/main.cpp @@ -18,12 +18,8 @@ // #include #include -#include -#include #include #include -#include -#include class MyInitialMemberListener : public hazelcast::client::InitialMembershipListener { @@ -37,7 +33,8 @@ class MyInitialMemberListener : public hazelcast::client::InitialMembershipListe } void memberAdded(const hazelcast::client::MembershipEvent &membershipEvent) { - std::cout << "[MyInitialMemberListener::memberAdded] New member joined:" << membershipEvent.getMember().getAddress() << + std::cout << "[MyInitialMemberListener::memberAdded] New member joined:" << + membershipEvent.getMember().getAddress() << std::endl; } @@ -47,7 +44,8 @@ class MyInitialMemberListener : public hazelcast::client::InitialMembershipListe } void memberAttributeChanged(const hazelcast::client::MemberAttributeEvent &memberAttributeEvent) { - std::cout << "[MyInitialMemberListener::memberAttributeChanged] Member attribute:" << memberAttributeEvent.getKey() + std::cout << "[MyInitialMemberListener::memberAttributeChanged] Member attribute:" << + memberAttributeEvent.getKey() << " changed. Value:" << memberAttributeEvent.getValue() << " for member:" << memberAttributeEvent.getMember().getAddress() << std::endl; } @@ -74,25 +72,37 @@ class MyMemberListener : public hazelcast::client::MembershipListener { }; int main() { + MyMemberListener memberListener; + MyInitialMemberListener initialMemberListener; + + hazelcast::client::Cluster *clusterPtr = NULL; try { hazelcast::client::ClientConfig config; hazelcast::client::HazelcastClient hz(config); - hazelcast::client::Cluster cluster = hz.getCluster(); + hazelcast::client::Cluster &cluster = hz.getCluster(); + clusterPtr = &cluster; std::vector members = cluster.getMembers(); std::cout << "The following are members in the cluster:" << std::endl; for (std::vector::const_iterator it = members.begin(); it != members.end(); ++it) { std::cout << it->getAddress() << std::endl; } - - MyMemberListener memberListener; + cluster.addMembershipListener(&memberListener); - - MyInitialMemberListener initialMemberListener; + cluster.addMembershipListener(&initialMemberListener); - + + // sleep some time for the events to be delivered before exiting + hazelcast::util::sleep(3); + + cluster.removeMembershipListener(&memberListener); + cluster.removeMembershipListener(&initialMemberListener); } catch (hazelcast::client::exception::IException &e) { std::cerr << "Test failed !!! " << e.what() << std::endl; + if (NULL != clusterPtr) { + clusterPtr->removeMembershipListener(&memberListener); + clusterPtr->removeMembershipListener(&initialMemberListener); + } exit(-1); } diff --git a/examples/network-configuration/socket-interceptor/main.cpp b/examples/network-configuration/socket-interceptor/main.cpp index 5c208f6e8c..690aa9fa87 100644 --- a/examples/network-configuration/socket-interceptor/main.cpp +++ b/examples/network-configuration/socket-interceptor/main.cpp @@ -22,20 +22,15 @@ class MyInterceptor : public hazelcast::client::SocketInterceptor { public: void onConnect(const hazelcast::client::Socket &connectedSocket) { std::cout << "[MyInterceptor::onConnect] Connected to remote host " << - connectedSocket.getAddress() << std::endl; + connectedSocket.getAddress() << std::endl; } }; int main() { - try { - hazelcast::client::ClientConfig config; - MyInterceptor interceptor; - config.setSocketInterceptor(&interceptor); - hazelcast::client::HazelcastClient hz(config); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + hazelcast::client::ClientConfig config; + MyInterceptor interceptor; + config.setSocketInterceptor(&interceptor); + hazelcast::client::HazelcastClient hz(config); std::cout << "Finished" << std::endl; diff --git a/examples/network-configuration/tcpip/main.cpp b/examples/network-configuration/tcpip/main.cpp index b47704bd8d..9633430392 100644 --- a/examples/network-configuration/tcpip/main.cpp +++ b/examples/network-configuration/tcpip/main.cpp @@ -19,22 +19,17 @@ #include int main() { - try { - const char *serverIp = "127.0.0.1"; - const int port = 5701; - hazelcast::client::ClientConfig config; - hazelcast::client::Address addr(serverIp, port); - config.addAddress(addr); - hazelcast::client::HazelcastClient hz(config); + const char *serverIp = "127.0.0.1"; + const int port = 5701; + hazelcast::client::ClientConfig config; + hazelcast::client::Address addr(serverIp, port); + config.addAddress(addr); + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("test map"); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + hazelcast::client::IMap map = hz.getMap("test map"); std::cout << "Finished" << std::endl; - + return 0; } diff --git a/examples/serialization/identified-data-serializable/main.cpp b/examples/serialization/identified-data-serializable/main.cpp index d48e5941b5..d89535b5cf 100644 --- a/examples/serialization/identified-data-serializable/main.cpp +++ b/examples/serialization/identified-data-serializable/main.cpp @@ -33,11 +33,11 @@ class Person : public hazelcast::client::serialization::IdentifiedDataSerializab return name.get(); } - int getFactoryId() const{ + int getFactoryId() const { return 1; } - int getClassId() const{ + int getClassId() const { return 1; } @@ -45,7 +45,7 @@ class Person : public hazelcast::client::serialization::IdentifiedDataSerializab out.writeUTF(name.get()); } - void readData(hazelcast::client::serialization::ObjectDataInput &in){ + void readData(hazelcast::client::serialization::ObjectDataInput &in) { name = in.readUTF(); } @@ -53,30 +53,23 @@ class Person : public hazelcast::client::serialization::IdentifiedDataSerializab std::auto_ptr name; }; -namespace std{ - std::ostream &operator<<(std::ostream &out, const Person &p) { - const string *str = p.getName(); - out << ((NULL == str) ? "NULL" : str->c_str()); - return out; - } +std::ostream &operator<<(std::ostream &out, const Person &p) { + const std::string *str = p.getName(); + out << ((NULL == str) ? "NULL" : str->c_str()); + return out; } int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("map"); - Person testPerson("foo"); - map.put("foo", testPerson); - std::cout << "Finished writing" << std::endl; - std::cout << map.get("foo"); - std::cout << "Finished reading" << std::endl; + hazelcast::client::IMap map = hz.getMap("map"); + Person testPerson("foo"); + map.put("foo", testPerson); + std::cout << "Finished writing" << std::endl; + std::cout << map.get("foo"); + std::cout << "Finished reading" << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } std::cout << "Finished" << std::endl; diff --git a/examples/serialization/portable/main.cpp b/examples/serialization/portable/main.cpp index f590878373..77da81533b 100644 --- a/examples/serialization/portable/main.cpp +++ b/examples/serialization/portable/main.cpp @@ -32,15 +32,15 @@ class Person : public hazelcast::client::serialization::Portable { return name.get(); } - int getFactoryId() const{ + int getFactoryId() const { return 1; } - int getClassId() const{ + int getClassId() const { return 1; } - void writePortable(hazelcast::client::serialization::PortableWriter& out) const { + void writePortable(hazelcast::client::serialization::PortableWriter &out) const { std::cout << "Serialize" << std::endl; out.writeUTF("name", name.get()); } @@ -54,30 +54,23 @@ class Person : public hazelcast::client::serialization::Portable { std::auto_ptr name; }; -namespace std{ - std::ostream &operator<<(std::ostream &out, const Person &p) { - const string *str = p.getName(); - out << ((NULL == str) ? "NULL" : str->c_str()); - return out; - } +std::ostream &operator<<(std::ostream &out, const Person &p) { + const std::string *str = p.getName(); + out << ((NULL == str) ? "NULL" : str->c_str()); + return out; } int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getMap("map"); - Person testPerson("foo"); - map.put("foo", testPerson); - std::cout << "Finished writing" << std::endl; - std::cout << map.get("foo"); - std::cout << "Finished reading" << std::endl; + hazelcast::client::IMap map = hz.getMap("map"); + Person testPerson("foo"); + map.put("foo", testPerson); + std::cout << "Finished writing" << std::endl; + std::cout << map.get("foo"); + std::cout << "Finished reading" << std::endl; - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } std::cout << "Finished" << std::endl; diff --git a/examples/spi/proxy/main.cpp b/examples/spi/proxy/main.cpp index b2901b5b13..b873c180ae 100644 --- a/examples/spi/proxy/main.cpp +++ b/examples/spi/proxy/main.cpp @@ -19,18 +19,14 @@ #include int main() { - try { - hazelcast::client::ClientConfig config; - hazelcast::client::HazelcastClient hz(config); + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); - hazelcast::client::IMap map = hz.getDistributedObject >("map distributed object"); - } catch (hazelcast::client::exception::IException &e) { - std::cerr << "Test failed !!! " << e.what() << std::endl; - exit(-1); - } + hazelcast::client::IMap map = hz.getDistributedObject >( + "map distributed object"); std::cout << "Finished" << std::endl; - + return 0; } diff --git a/examples/transactions/transaction-basic/TransactionBasic.cpp b/examples/transactions/transaction-basic/TransactionBasic.cpp index 37dacbcbb6..636cba8ecd 100644 --- a/examples/transactions/transaction-basic/TransactionBasic.cpp +++ b/examples/transactions/transaction-basic/TransactionBasic.cpp @@ -21,7 +21,7 @@ int main() { hazelcast::client::ClientConfig config; hazelcast::client::HazelcastClient hz(config); - + hazelcast::client::TransactionOptions txOptions; txOptions.setTimeout(10); @@ -30,7 +30,8 @@ int main() { try { txCxt.beginTransaction(); - hazelcast::client::TransactionalMap map = txCxt.getMap("transaction map"); + hazelcast::client::TransactionalMap map = txCxt.getMap( + "transaction map"); map.put("1", "1"); hazelcast::util::sleepmillis(20); @@ -43,7 +44,7 @@ int main() { } std::cout << "Finished" << std::endl; - + return 0; } diff --git a/hazelcast/include/hazelcast/client/ItemEvent.h b/hazelcast/include/hazelcast/client/ItemEvent.h index 1b269de083..0ac24b9260 100644 --- a/hazelcast/include/hazelcast/client/ItemEvent.h +++ b/hazelcast/include/hazelcast/client/ItemEvent.h @@ -94,7 +94,7 @@ namespace hazelcast { /** * @returns the item. */ - const E &geItem() const { + const E &getItem() const { return item; };