diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 91f358dd92..7bc14805bf 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -147,6 +147,8 @@ add_subdirectory(distributed-topic) add_subdirectory(distributed-primitives) add_subdirectory(distributed-map) add_subdirectory(distributed-collections) +add_subdirectory(adaptor) + diff --git a/examples/adaptor/CMakeLists.txt b/examples/adaptor/CMakeLists.txt new file mode 100644 index 0000000000..4286c2f2e6 --- /dev/null +++ b/examples/adaptor/CMakeLists.txt @@ -0,0 +1,24 @@ +# +# 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(rawmap ./RawMap.cpp) +add_executable(rawlist ./RawList.cpp) +add_executable(rawmultimap ./RawMultiMap.cpp) +add_executable(rawqueue ./RawQueue.cpp) +add_executable(rawset ./RawSet.cpp) +add_executable(rawtxmap ./RawTransactionalMap.cpp) +add_executable(rawtxmultimap ./RawTransactionalMultiMap.cpp) +add_executable(rawtxqueue ./RawTransactionalQueue.cpp) + diff --git a/examples/adaptor/RawList.cpp b/examples/adaptor/RawList.cpp new file mode 100644 index 0000000000..5da8d41901 --- /dev/null +++ b/examples/adaptor/RawList.cpp @@ -0,0 +1,74 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IList l = hz.getList("list"); + hazelcast::client::adaptor::RawPointerList list(l); + + std::cout << "There are " << list.size() << " values initally in the list" << std::endl; + + list.clear(); + + std::cout << "After clear operation, there are " << list.size() << " values in the list" << std::endl; + + list.add("Tokyo"); + list.add("Paris"); + list.add("New York"); + std::cout << "Finished loading list" << std::endl; + + std::cout << "There are " << list.size() << " values in the list" << std::endl; + + std::auto_ptr > vals = list.subList(0, 2); + std::cout << "Got sublist between indexes 0 and 2. Size is:" << vals->size() << std::endl; + for (size_t i = 0; i < vals->size(); ++i) { + std::auto_ptr val = vals->get(i); + if (NULL == val.get()) { + std::cout << "Value " << i << " is NULL" << std::endl; + } else { + std::cout << "Value: " << *val << std::endl; + } + } + + std::auto_ptr item = list.get(1); + if (NULL != item.get()) { + std::cout << "Item at index 1 is " << *item << std::endl; + } else { + std::cout << "Item at index 1 is NULL" << std::endl; + } + + vals = list.toArray(); + + for (size_t i = 0; i < vals->size(); ++i) { + std::auto_ptr val = vals->get(i); + if (NULL == val.get()) { + std::cout << "Value " << i << " is NULL" << std::endl; + } else { + std::cout << "Value: " << *val << std::endl; + } + } + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/adaptor/RawMap.cpp b/examples/adaptor/RawMap.cpp new file mode 100644 index 0000000000..f8934e2462 --- /dev/null +++ b/examples/adaptor/RawMap.cpp @@ -0,0 +1,53 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IMap m = hz.getMap("map"); + hazelcast::client::adaptor::RawPointerMap map(m); + map.put("1", "Tokyo"); + map.put("2", "Paris"); + map.put("3", "New York"); + std::cout << "Finished loading map" << std::endl; + + std::auto_ptr > vals = map.values(); + std::auto_ptr > entries = map.entrySet(); + + std::cout << "There are " << vals->size() << " values in the map" << std::endl; + std::cout << "There are " << entries->size() << " entries in the map" << std::endl; + + for (size_t i = 0; i < entries->size(); ++i) { + std::auto_ptr key = entries->getKey(i); + if ((std::string *) NULL == key.get()) { + std::cout << "The key at index " << i << " is NULL" << std::endl; + } else { + std::auto_ptr val = entries->getValue(i); + std::cout << "(Key, Value) for index " << i << " is: (" << *key << ", " << + (val.get() == NULL ? "NULL" : *val) << ")" << std::endl; + } + } + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/adaptor/RawMultiMap.cpp b/examples/adaptor/RawMultiMap.cpp new file mode 100644 index 0000000000..97c66b0ea0 --- /dev/null +++ b/examples/adaptor/RawMultiMap.cpp @@ -0,0 +1,69 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::MultiMap m = hz.getMultiMap("multimap"); + hazelcast::client::adaptor::RawPointerMultiMap multimap(m); + multimap.put("1", "Tokyo"); + multimap.put("2", "Paris"); + multimap.put("3", "New York"); + std::cout << "Finished loading multimap" << std::endl; + + std::auto_ptr > vals = multimap.values(); + std::auto_ptr > entries = multimap.entrySet(); + + std::cout << "There are " << vals->size() << " values in the multimap" << std::endl; + size_t size = entries->size(); + std::cout << "There are " << size << " entries in the multimap" << std::endl; + + for (size_t i = 0; i < size; ++i) { + std::auto_ptr key = entries->getKey(i); + if ((std::string *) NULL == key.get()) { + std::cout << "The key at index " << i << " is NULL" << std::endl; + } else { + std::auto_ptr val = entries->getValue(i); + std::cout << "(Key, Value) for index " << i << " is: (" << *key << ", " << + (val.get() == NULL ? "NULL" : *val) << ")" << std::endl; + } + } + + multimap.put("1", "Istanbul"); + std::cout << "Put the second value for key '1' into the multimap" << std::endl; + + vals = multimap.get("1"); + size = vals->size(); + std::cout << "There are " << vals->size() << " values for key '1' in the multimap. These are:" << std::endl; + for (size_t j = 0; j < size; ++j) { + std::auto_ptr val = vals->get(j); + if (NULL == val.get()) { + std::cout << "NULL" << std::endl; + } else { + std::cout << *val << std::endl; + } + } + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/adaptor/RawQueue.cpp b/examples/adaptor/RawQueue.cpp new file mode 100644 index 0000000000..6db69a1ac5 --- /dev/null +++ b/examples/adaptor/RawQueue.cpp @@ -0,0 +1,63 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::IQueue q = hz.getQueue("queue"); + hazelcast::client::adaptor::RawPointerQueue queue(q); + queue.offer("Tokyo"); + queue.offer("Paris"); + queue.offer("New York"); + std::cout << "Finished loading queue" << std::endl; + + std::auto_ptr > vals = queue.toArray(); + + std::cout << "There are " << queue.size() << " values in the queue" << std::endl; + + for (size_t i = 0; i < vals->size(); ++i) { + std::auto_ptr val = vals->get(i); + if (NULL == val.get()) { + std::cout << "Value " << i << " is NULL" << std::endl; + } else { + std::cout << "Value: " << *val << std::endl; + } + } + + std::auto_ptr item = queue.peek(); + if (NULL == item.get()) { + std::cout << "Head of the queue is NULL" << std::endl; + } else { + std::cout << "Head of the queue is " << *item << std::endl; + } + + item = queue.take(); + if (NULL == item.get()) { + std::cout << "Take operation returned NULL" << std::endl; + } else { + std::cout << "Take operation returned " << *item << std::endl; + } + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/adaptor/RawSet.cpp b/examples/adaptor/RawSet.cpp new file mode 100644 index 0000000000..3b15e64f5e --- /dev/null +++ b/examples/adaptor/RawSet.cpp @@ -0,0 +1,56 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::ISet s = hz.getSet("set"); + hazelcast::client::adaptor::RawPointerSet set(s); + set.add("Tokyo"); + set.add("Paris"); + set.add("New York"); + std::cout << "Finished loading set" << std::endl; + + std::auto_ptr > vals = set.toArray(); + + std::cout << "There are " << set.size() << " values in the set" << std::endl; + + for (size_t i = 0; i < vals->size(); ++i) { + std::auto_ptr val = (*vals)[i]; + if (NULL == val.get()) { + std::cout << "Value " << i << " is NULL" << std::endl; + } else { + std::cout << "Value: " << *val << std::endl; + } + } + + bool exists = set.remove("Tokyo"); + if (exists) { + std::cout << "Removed Tokyo from set" << std::endl; + } else { + std::cout << "Could not remove Tokyo from set. It did not exist." << std::endl; + } + + std::cout << "Finished" << std::endl; + + return 0; +} diff --git a/examples/adaptor/RawTransactionalMap.cpp b/examples/adaptor/RawTransactionalMap.cpp new file mode 100644 index 0000000000..2328d80c94 --- /dev/null +++ b/examples/adaptor/RawTransactionalMap.cpp @@ -0,0 +1,42 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::TransactionContext txCtxt = hz.newTransactionContext(); + + txCtxt.beginTransaction(); + + hazelcast::client::TransactionalMap transactionalMap = txCtxt.getMap("txMap"); + + hazelcast::client::adaptor::RawPointerTransactionalMap map(transactionalMap); + map.put("1", "Tokyo"); + map.put("2", "Paris"); + map.put("3", "New York"); + + txCtxt.commitTransaction(); + + std::cout << "Finished loading transactional map" << std::endl; + + return 0; +} diff --git a/examples/adaptor/RawTransactionalMultiMap.cpp b/examples/adaptor/RawTransactionalMultiMap.cpp new file mode 100644 index 0000000000..2241943a13 --- /dev/null +++ b/examples/adaptor/RawTransactionalMultiMap.cpp @@ -0,0 +1,43 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::TransactionContext txCtxt = hz.newTransactionContext(); + + txCtxt.beginTransaction(); + + hazelcast::client::TransactionalMultiMap transactionalMultiMap = txCtxt.getMultiMap("txMultiMap"); + + hazelcast::client::adaptor::RawPointerTransactionalMultiMap map(transactionalMultiMap); + map.put("1", "Tokyo"); + map.put("1", "Istanbul"); + map.put("2", "Paris"); + map.put("3", "New York"); + + txCtxt.commitTransaction(); + + std::cout << "Finished loading transactional multimap" << std::endl; + + return 0; +} diff --git a/examples/adaptor/RawTransactionalQueue.cpp b/examples/adaptor/RawTransactionalQueue.cpp new file mode 100644 index 0000000000..067ef33481 --- /dev/null +++ b/examples/adaptor/RawTransactionalQueue.cpp @@ -0,0 +1,43 @@ +/* + * 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 +#include + +int main() { + hazelcast::client::ClientConfig config; + hazelcast::client::HazelcastClient hz(config); + + hazelcast::client::TransactionContext txCtxt = hz.newTransactionContext(); + + txCtxt.beginTransaction(); + + hazelcast::client::TransactionalQueue transactionalQueue = txCtxt.getQueue("txQueue"); + + hazelcast::client::adaptor::RawPointerTransactionalQueue map(transactionalQueue); + map.offer("Tokyo"); + map.offer("Istanbul"); + map.offer("Paris"); + map.offer("New York"); + + txCtxt.commitTransaction(); + + std::cout << "Finished loading transactional queue" << std::endl; + + return 0; +} diff --git a/hazelcast/include/hazelcast/client/HazelcastClient.h b/hazelcast/include/hazelcast/client/HazelcastClient.h index 3636cced23..4054c7a1f9 100644 --- a/hazelcast/include/hazelcast/client/HazelcastClient.h +++ b/hazelcast/include/hazelcast/client/HazelcastClient.h @@ -436,6 +436,8 @@ namespace hazelcast { }; /** + * @deprecated "Please use api::IMap getMap(const char *name)." + * * Returns the distributed map instance with the specified name. * * @tparam K key type diff --git a/hazelcast/include/hazelcast/client/IList.h b/hazelcast/include/hazelcast/client/IList.h index 4f91086067..571c2ff856 100644 --- a/hazelcast/include/hazelcast/client/IList.h +++ b/hazelcast/include/hazelcast/client/IList.h @@ -28,6 +28,10 @@ namespace hazelcast { namespace client { + namespace adaptor { + template + class RawPointerList; + } /** * Concurrent, distributed , client implementation of std::list @@ -37,6 +41,7 @@ namespace hazelcast { template class IList : public proxy::IListImpl { friend class HazelcastClient; + friend class adaptor::RawPointerList; public: /** @@ -101,7 +106,7 @@ namespace hazelcast { * @returns all elements as std::vector */ std::vector toArray() { - return toObjectCollection(proxy::IListImpl::toArray()); + return toObjectCollection(proxy::IListImpl::toArrayData()); } /** @@ -200,7 +205,7 @@ namespace hazelcast { * */ boost::shared_ptr get(int index) { - return toObject(proxy::IListImpl::get(index)); + return boost::shared_ptr(toObject(proxy::IListImpl::getData(index))); } /** @@ -213,7 +218,7 @@ namespace hazelcast { * @throws IndexOutOfBoundsException if the index is out of range. */ boost::shared_ptr set(int index, const E &element) { - return toObject(proxy::IListImpl::set(index, toData(element))); + return boost::shared_ptr(toObject(proxy::IListImpl::setData(index, toData(element)))); } /** @@ -236,7 +241,7 @@ namespace hazelcast { * @throws IndexOutOfBoundsException if the index is out of range. */ boost::shared_ptr remove(int index) { - return toObject(proxy::IListImpl::remove(index)); + return boost::shared_ptr(toObject(proxy::IListImpl::removeData(index))); } /** @@ -266,7 +271,7 @@ namespace hazelcast { * @throws IndexOutOfBoundsException if the index is out of range. */ std::vector subList(int fromIndex, int toIndex) { - return toObjectCollection(proxy::IListImpl::subList(fromIndex, toIndex)); + return toObjectCollection(proxy::IListImpl::subListData(fromIndex, toIndex)); } private: diff --git a/hazelcast/include/hazelcast/client/IMap.h b/hazelcast/include/hazelcast/client/IMap.h index 6927e22565..82d09ca8f2 100644 --- a/hazelcast/include/hazelcast/client/IMap.h +++ b/hazelcast/include/hazelcast/client/IMap.h @@ -34,6 +34,10 @@ namespace hazelcast { namespace client { + namespace adaptor { + template + class RawPointerMap; + } /** * Concurrent, distributed, observable and queryable map client. @@ -51,6 +55,7 @@ namespace hazelcast { template class IMap : public proxy::IMapImpl { friend class HazelcastClient; + friend class adaptor::RawPointerMap; public: @@ -82,7 +87,7 @@ namespace hazelcast { * @throws IClassCastException if the type of the specified element is incompatible with the server side. */ boost::shared_ptr get(const K &key) { - return toObject(proxy::IMapImpl::get(toData(key))); + return boost::shared_ptr(toObject(proxy::IMapImpl::getData(toData(key)))); } /** @@ -94,7 +99,7 @@ namespace hazelcast { * then returns NULL in shared_ptr. */ boost::shared_ptr put(const K &key, const V &value) { - return toObject(proxy::IMapImpl::put(toData(key), toData(value))); + return boost::shared_ptr(toObject(proxy::IMapImpl::putData(toData(key), toData(value)))); } /** @@ -105,7 +110,7 @@ namespace hazelcast { * @throws IClassCastException if the type of the specified element is incompatible with the server side. */ boost::shared_ptr remove(const K &key) { - return toObject(proxy::IMapImpl::remove(toData(key))); + return boost::shared_ptr(toObject(proxy::IMapImpl::removeData(toData(key)))); } /** @@ -179,7 +184,7 @@ namespace hazelcast { * then returns NULL in shared_ptr. */ boost::shared_ptr put(const K &key, const V &value, long ttlInMillis) { - return toObject(proxy::IMapImpl::put(toData(key), toData(value), ttlInMillis)); + return boost::shared_ptr(toObject(proxy::IMapImpl::putData(toData(key), toData(value), ttlInMillis))); } /** @@ -219,7 +224,7 @@ namespace hazelcast { * then returns NULL in shared_ptr. */ boost::shared_ptr putIfAbsent(const K &key, const V &value, long ttlInMillis) { - return toObject(proxy::IMapImpl::putIfAbsent(toData(key), toData(value), ttlInMillis)); + return boost::shared_ptr(toObject(proxy::IMapImpl::putIfAbsentData(toData(key), toData(value), ttlInMillis))); } /** @@ -241,7 +246,7 @@ namespace hazelcast { * then returns NULL in shared_ptr. */ boost::shared_ptr replace(const K &key, const V &value) { - return toObject(proxy::IMapImpl::replace(toData(key), toData(value))); + return boost::shared_ptr(toObject(proxy::IMapImpl::replaceData(toData(key), toData(value)))); } /** @@ -465,8 +470,8 @@ namespace hazelcast { */ EntryView getEntryView(const K &key) { serialization::pimpl::Data keyData = toData(key); - std::auto_ptr dataEntryView = proxy::IMapImpl::getEntryView(keyData); - boost::shared_ptr v = toObject(dataEntryView->getValue()); + std::auto_ptr dataEntryView = proxy::IMapImpl::getEntryViewData(keyData); + std::auto_ptr v = toObject(dataEntryView->getValue()); EntryView view(key, *v, *dataEntryView); return view; } @@ -513,12 +518,12 @@ namespace hazelcast { keySet[i++] = toData(*it); } std::map result; - std::vector > entrySet = proxy::IMapImpl::getAll( + std::vector > entrySet = proxy::IMapImpl::getAllData( keySet); for (std::vector >::const_iterator it = entrySet.begin(); it != entrySet.end(); ++it) { - boost::shared_ptr key = toObject(it->first); - boost::shared_ptr value = toObject(it->second); + std::auto_ptr key = toObject(it->first); + std::auto_ptr value = toObject(it->second); result[*key] = *value; } return result; @@ -532,11 +537,11 @@ namespace hazelcast { * @return a vector clone of the keys contained in this map */ std::vector keySet() { - std::vector dataResult = proxy::IMapImpl::keySet(); + std::vector dataResult = proxy::IMapImpl::keySetData(); size_t size = dataResult.size(); std::vector keys(size); for (size_t i = 0; i < size; ++i) { - boost::shared_ptr key = toObject(dataResult[i]); + std::auto_ptr key = toObject(dataResult[i]); keys[i] = *key; } return keys; @@ -553,11 +558,11 @@ namespace hazelcast { * @return result key set of the query */ std::vector keySet(const serialization::IdentifiedDataSerializable &predicate) { - std::vector dataResult = proxy::IMapImpl::keySet(predicate); + std::vector dataResult = proxy::IMapImpl::keySetData(predicate); size_t size = dataResult.size(); std::vector keys(size); for (size_t i = 0; i < size; ++i) { - boost::shared_ptr key = toObject(dataResult[i]); + std::auto_ptr key = toObject(dataResult[i]); keys[i] = *key; } return keys; @@ -571,11 +576,11 @@ namespace hazelcast { * @return a vector clone of the values contained in this map */ std::vector values() { - std::vector dataResult = proxy::IMapImpl::values(); + std::vector dataResult = proxy::IMapImpl::valuesData(); size_t size = dataResult.size(); std::vector values(size); for (size_t i = 0; i < size; ++i) { - boost::shared_ptr value = toObject(dataResult[i]); + std::auto_ptr value = toObject(dataResult[i]); values[i] = *value; } return values; @@ -590,11 +595,11 @@ namespace hazelcast { * @return a vector clone of the values contained in this map */ std::vector values(const serialization::IdentifiedDataSerializable &predicate) { - std::vector dataResult = proxy::IMapImpl::values(predicate); + std::vector dataResult = proxy::IMapImpl::valuesData(predicate); size_t size = dataResult.size(); std::vector values(size); for (size_t i = 0; i < size; ++i) { - boost::shared_ptr value = toObject(dataResult[i]); + std::auto_ptr value = toObject(dataResult[i]); values[i] = *value; } return values; @@ -608,12 +613,12 @@ namespace hazelcast { * @return a vector clone of the keys mappings in this map */ std::vector > entrySet() { - std::vector > dataResult = proxy::IMapImpl::entrySet(); + std::vector > dataResult = proxy::IMapImpl::entrySetData(); size_t size = dataResult.size(); std::vector > entries(size); for (size_t i = 0; i < size; ++i) { - boost::shared_ptr key = toObject(dataResult[i].first); - boost::shared_ptr value = toObject(dataResult[i].second); + std::auto_ptr key = toObject(dataResult[i].first); + std::auto_ptr value = toObject(dataResult[i].second); entries[i] = std::make_pair(*key, *value); } return entries; @@ -630,13 +635,13 @@ namespace hazelcast { * @return result entry vector of the query */ std::vector > entrySet(const serialization::IdentifiedDataSerializable &predicate) { - std::vector > dataResult = proxy::IMapImpl::entrySet( + std::vector > dataResult = proxy::IMapImpl::entrySetData( predicate); size_t size = dataResult.size(); std::vector > entries(size); for (size_t i = 0; i < size; ++i) { - boost::shared_ptr key = toObject(dataResult[i].first); - boost::shared_ptr value = toObject(dataResult[i].second); + std::auto_ptr key = toObject(dataResult[i].first); + std::auto_ptr value = toObject(dataResult[i].second); entries[i] = std::make_pair(*key, *value); } return entries; @@ -694,7 +699,9 @@ namespace hazelcast { */ template boost::shared_ptr executeOnKey(const K &key, EntryProcessor &entryProcessor) { - return proxy::IMapImpl::executeOnKey(key, entryProcessor); + std::auto_ptr resultData = proxy::IMapImpl::executeOnKeyData(key, entryProcessor); + + return boost::shared_ptr(toObject(resultData)); } /** @@ -712,7 +719,14 @@ namespace hazelcast { */ template std::map > executeOnEntries(EntryProcessor &entryProcessor) { - return proxy::IMapImpl::executeOnEntries(entryProcessor); + EntryVector entries = proxy::IMapImpl::executeOnEntriesData(entryProcessor); + std::map > result; + for (size_t i = 0; i < entries.size(); ++i) { + std::auto_ptr keyObj = toObject(entries[i].first); + std::auto_ptr resObj = toObject(entries[i].second); + result[*keyObj] = resObj; + } + return result; } /** @@ -758,7 +772,7 @@ namespace hazelcast { * @param m mappings to be stored in this map */ void putAll(const std::map &entries) { - return proxy::IMapImpl::putAll(toDataEntriesSet(entries)); + return proxy::IMapImpl::putAll(toDataEntries(entries)); } /** diff --git a/hazelcast/include/hazelcast/client/IQueue.h b/hazelcast/include/hazelcast/client/IQueue.h index 28e50d4d7f..eaba26dacd 100644 --- a/hazelcast/include/hazelcast/client/IQueue.h +++ b/hazelcast/include/hazelcast/client/IQueue.h @@ -24,6 +24,10 @@ namespace hazelcast { namespace client { + namespace adaptor { + template + class RawPointerQueue; + } /** * Concurrent, blocking, distributed, observable, client queue. @@ -33,6 +37,7 @@ namespace hazelcast { template class IQueue : public proxy::IQueueImpl { friend class HazelcastClient; + friend class adaptor::RawPointerQueue; public: /** @@ -116,7 +121,8 @@ namespace hazelcast { * @return the head of the queue. If queue is empty waits for specified time. */ boost::shared_ptr poll(long timeoutInMillis) { - return toObject(proxy::IQueueImpl::poll(timeoutInMillis)); + return boost::shared_ptr(boost::shared_ptr(toObject( + proxy::IQueueImpl::pollData(timeoutInMillis)))); } /** @@ -163,9 +169,9 @@ namespace hazelcast { * @return number of elements drained. */ size_t drainTo(std::vector& elements, size_t maxElements) { - std::vector coll = proxy::IQueueImpl::drainTo(maxElements); + std::vector coll = proxy::IQueueImpl::drainToData(maxElements); for (std::vector::const_iterator it = coll.begin(); it != coll.end(); ++it) { - boost::shared_ptr e = context->getSerializationService().template toObject(*it); + std::auto_ptr e = context->getSerializationService().template toObject(*it); elements.push_back(*e); } return coll.size(); @@ -186,7 +192,7 @@ namespace hazelcast { * @return head of queue without removing it. If not available returns empty constructed shared_ptr. */ boost::shared_ptr peek() { - return toObject(proxy::IQueueImpl::peek()); + return boost::shared_ptr(toObject(proxy::IQueueImpl::peekData())); } /** @@ -210,7 +216,7 @@ namespace hazelcast { * @returns all elements as std::vector */ std::vector toArray() { - return toObjectCollection(proxy::IQueueImpl::toArray()); + return toObjectCollection(proxy::IQueueImpl::toArrayData()); } /** diff --git a/hazelcast/include/hazelcast/client/ISet.h b/hazelcast/include/hazelcast/client/ISet.h index 1f4a4ceb13..065c264743 100644 --- a/hazelcast/include/hazelcast/client/ISet.h +++ b/hazelcast/include/hazelcast/client/ISet.h @@ -22,6 +22,10 @@ namespace hazelcast { namespace client { + namespace adaptor { + template + class RawPointerSet; + } /** * Concurrent, distributed client implementation of std::unordered_set. @@ -31,6 +35,7 @@ namespace hazelcast { template class ISet : public proxy::ISetImpl { friend class HazelcastClient; + friend class adaptor::RawPointerSet; public: /** @@ -94,7 +99,7 @@ namespace hazelcast { * @returns all elements as std::vector */ std::vector toArray() { - return toObjectCollection(proxy::ISetImpl::toArray()); + return toObjectCollection(proxy::ISetImpl::toArrayData()); } /** diff --git a/hazelcast/include/hazelcast/client/ITopic.h b/hazelcast/include/hazelcast/client/ITopic.h index 716bb05ebf..a92f3c2099 100644 --- a/hazelcast/include/hazelcast/client/ITopic.h +++ b/hazelcast/include/hazelcast/client/ITopic.h @@ -15,10 +15,6 @@ */ // // Created by sancar koyunlu on 6/20/13. - - - - #ifndef HAZELCAST_TOPIC #define HAZELCAST_TOPIC diff --git a/hazelcast/include/hazelcast/client/MultiMap.h b/hazelcast/include/hazelcast/client/MultiMap.h index 1e0831b353..d9bbdd7b5f 100644 --- a/hazelcast/include/hazelcast/client/MultiMap.h +++ b/hazelcast/include/hazelcast/client/MultiMap.h @@ -27,6 +27,10 @@ namespace hazelcast { namespace client { + namespace adaptor { + template + class RawPointerMultiMap; + } /** * A specialized distributed map client whose keys can be associated with multiple values. @@ -36,6 +40,7 @@ namespace hazelcast { template class MultiMap : public proxy::MultiMapImpl { friend class HazelcastClient; + friend class adaptor::RawPointerMultiMap; public: /** @@ -58,7 +63,7 @@ namespace hazelcast { * @return the multimap of the values associated with the key. */ std::vector get(const K &key) { - return toObjectCollection(proxy::MultiMapImpl::get(toData(key))); + return toObjectCollection(proxy::MultiMapImpl::getData(toData(key))); } /** @@ -80,7 +85,7 @@ namespace hazelcast { * might be modifiable but it has no effect on the multimap */ std::vector remove(const K &key) { - return toObjectCollection(proxy::MultiMapImpl::remove(toData(key))); + return toObjectCollection(proxy::MultiMapImpl::removeData(toData(key))); } /** @@ -90,7 +95,7 @@ namespace hazelcast { * but it has no effect on the multimap */ std::vector keySet() { - return toObjectCollection(proxy::MultiMapImpl::keySet()); + return toObjectCollection(proxy::MultiMapImpl::keySetData()); } /** @@ -100,7 +105,7 @@ namespace hazelcast { * but it has no effect on the multimap */ std::vector values() { - return toObjectCollection(proxy::MultiMapImpl::values()); + return toObjectCollection(proxy::MultiMapImpl::valuesData()); } /** @@ -110,7 +115,7 @@ namespace hazelcast { * but it has no effect on the multimap */ std::vector > entrySet() { - return toObjectEntrySet(proxy::MultiMapImpl::entrySet()); + return toObjectEntrySet(proxy::MultiMapImpl::entrySetData()); } /** diff --git a/hazelcast/include/hazelcast/client/TransactionalList.h b/hazelcast/include/hazelcast/client/TransactionalList.h index bf9aa8e860..7dde61afb4 100644 --- a/hazelcast/include/hazelcast/client/TransactionalList.h +++ b/hazelcast/include/hazelcast/client/TransactionalList.h @@ -15,11 +15,6 @@ */ // // Created by sancar koyunlu on 8/6/13. - - - - - #ifndef HAZELCAST_TransactionalList #define HAZELCAST_TransactionalList diff --git a/hazelcast/include/hazelcast/client/TransactionalMap.h b/hazelcast/include/hazelcast/client/TransactionalMap.h index b14369ebfd..5331296660 100644 --- a/hazelcast/include/hazelcast/client/TransactionalMap.h +++ b/hazelcast/include/hazelcast/client/TransactionalMap.h @@ -15,11 +15,6 @@ */ // // Created by sancar koyunlu on 8/5/13. - - - - - #ifndef HAZELCAST_TransactionalMap #define HAZELCAST_TransactionalMap @@ -32,6 +27,10 @@ namespace hazelcast { } } namespace client { + namespace adaptor { + template + class RawPointerTransactionalMap; + } /** * Transactional implementation of IMap. @@ -43,6 +42,7 @@ namespace hazelcast { template class TransactionalMap : public proxy::TransactionalMapImpl { friend class TransactionContext; + friend class adaptor::RawPointerTransactionalMap; public: /** @@ -60,7 +60,7 @@ namespace hazelcast { * @see IMap#get(keu) */ boost::shared_ptr get(const K& key) { - return toObject(proxy::TransactionalMapImpl::get(toData(&key))); + return boost::shared_ptr(toObject(proxy::TransactionalMapImpl::getData(toData(&key)))); } /** @@ -89,7 +89,7 @@ namespace hazelcast { * @see IMap#put(key, value) */ boost::shared_ptr put(const K& key, const V& value) { - return toObject(proxy::TransactionalMapImpl::put(toData(&key), toData(&value))); + return boost::shared_ptr(toObject(proxy::TransactionalMapImpl::putData(toData(&key), toData(&value)))); }; /** @@ -111,7 +111,7 @@ namespace hazelcast { * @see IMap#putIfAbsent(key, value) */ boost::shared_ptr putIfAbsent(const K& key, const V& value) { - return toObject(proxy::TransactionalMapImpl::putIfAbsent(toData(&key), toData(&value))); + return boost::shared_ptr(toObject(proxy::TransactionalMapImpl::putIfAbsentData(toData(&key), toData(&value)))); }; /** @@ -122,7 +122,7 @@ namespace hazelcast { * @see IMap#replace(key, value) */ boost::shared_ptr replace(const K& key, const V& value) { - return toObject(proxy::TransactionalMapImpl::replace(toData(&key), toData(&value))); + return boost::shared_ptr(toObject(proxy::TransactionalMapImpl::replaceData(toData(&key), toData(&value)))); }; /** @@ -144,7 +144,7 @@ namespace hazelcast { * @see IMap#remove(key) */ boost::shared_ptr remove(const K& key) { - return toObject(proxy::TransactionalMapImpl::remove(toData(&key))); + return boost::shared_ptr(toObject(proxy::TransactionalMapImpl::removeData(toData(&key)))); }; /** @@ -177,7 +177,7 @@ namespace hazelcast { * @see IMap#keySet() */ std::vector keySet() { - return toObjectCollection(proxy::TransactionalMapImpl::keySet()); + return toObjectCollection(proxy::TransactionalMapImpl::keySetData()); } /** @@ -187,7 +187,7 @@ namespace hazelcast { * @see IMap#keySet(predicate) */ std::vector keySet(const serialization::IdentifiedDataSerializable *predicate) { - return toObjectCollection(proxy::TransactionalMapImpl::keySet(predicate)); + return toObjectCollection(proxy::TransactionalMapImpl::keySetData(predicate)); } /** @@ -197,7 +197,7 @@ namespace hazelcast { * @see IMap#values() */ std::vector values() { - return toObjectCollection(proxy::TransactionalMapImpl::values()); + return toObjectCollection(proxy::TransactionalMapImpl::valuesData()); } /** @@ -206,7 +206,7 @@ namespace hazelcast { * @see IMap#values(Predicate) */ std::vector values(const serialization::IdentifiedDataSerializable *predicate) { - return toObjectCollection(proxy::TransactionalMapImpl::values(predicate)); + return toObjectCollection(proxy::TransactionalMapImpl::valuesData(predicate)); } private: @@ -219,6 +219,5 @@ namespace hazelcast { } } - #endif //HAZELCAST_TransactionalMap diff --git a/hazelcast/include/hazelcast/client/TransactionalMultiMap.h b/hazelcast/include/hazelcast/client/TransactionalMultiMap.h index a77d4089ed..077bbe9cb8 100644 --- a/hazelcast/include/hazelcast/client/TransactionalMultiMap.h +++ b/hazelcast/include/hazelcast/client/TransactionalMultiMap.h @@ -16,7 +16,6 @@ // // Created by sancar koyunlu on 8/6/13. - #ifndef HAZELCAST_TransactionalMultiMap #define HAZELCAST_TransactionalMultiMap @@ -24,6 +23,10 @@ namespace hazelcast { namespace client { + namespace adaptor { + template + class RawPointerTransactionalMultiMap; + } /** * @@ -36,6 +39,7 @@ namespace hazelcast { template class TransactionalMultiMap : public proxy::TransactionalMultiMapImpl { friend class TransactionContext; + friend class adaptor::RawPointerTransactionalMultiMap; public: /** @@ -53,7 +57,7 @@ namespace hazelcast { * @see Multimap#get(key) */ std::vector get(const K& key) { - return toObjectCollection(proxy::TransactionalMultiMapImpl::get(toData(&key))); + return toObjectCollection(proxy::TransactionalMultiMapImpl::getData(toData(&key))); }; /** @@ -71,7 +75,7 @@ namespace hazelcast { * @see Multimap#remove(key) */ std::vector remove(const K& key) { - return toObjectCollection(proxy::TransactionalMultiMapImpl::remove(toData(&key))); + return toObjectCollection(proxy::TransactionalMultiMapImpl::removeData(toData(&key))); }; diff --git a/hazelcast/include/hazelcast/client/TransactionalQueue.h b/hazelcast/include/hazelcast/client/TransactionalQueue.h index 683279d928..255730d9f7 100644 --- a/hazelcast/include/hazelcast/client/TransactionalQueue.h +++ b/hazelcast/include/hazelcast/client/TransactionalQueue.h @@ -16,10 +16,6 @@ // // Created by sancar koyunlu on 8/5/13. - - - - #ifndef HAZELCAST_TransactionalQueue #define HAZELCAST_TransactionalQueue @@ -27,6 +23,11 @@ namespace hazelcast { namespace client { + namespace adaptor { + template + class RawPointerTransactionalQueue; + } + /** * Transactional implementation of IQueue. * @@ -36,6 +37,7 @@ namespace hazelcast { template class TransactionalQueue : public proxy::TransactionalQueueImpl { friend class TransactionContext; + friend class adaptor::RawPointerTransactionalQueue; public: /** @@ -71,7 +73,7 @@ namespace hazelcast { * @see IQueue::poll(long timeoutInMillis) */ boost::shared_ptr poll(long timeoutInMillis) { - return toObject(proxy::TransactionalQueueImpl::poll(timeoutInMillis)); + return boost::shared_ptr(toObject(proxy::TransactionalQueueImpl::pollData(timeoutInMillis))); } /** diff --git a/hazelcast/include/hazelcast/client/adaptor/DataArray.h b/hazelcast/include/hazelcast/client/adaptor/DataArray.h new file mode 100644 index 0000000000..ada34a211a --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/DataArray.h @@ -0,0 +1,104 @@ +/* + * 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 ihsan demir on 25 02, 2016. +// +#ifndef HAZELCAST_CLIENT_ADAPTOR_DATAARRAY_H_ +#define HAZELCAST_CLIENT_ADAPTOR_DATAARRAY_H_ + +#include + +#include "hazelcast/util/Util.h" +#include +#include "hazelcast/client/serialization/pimpl/SerializationService.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + template + class DataArray { + public: + DataArray(const std::vector &data, + serialization::pimpl::SerializationService &service) : values(data), + serializationService(&service) { + } + + /** + * @return Returns the number of data items + */ + size_t size() const { + return values.size(); + } + + /** + * Please note that this operation is costly due to de-serialization. It will NOT cache the de-serialized data. + * + * @param index The index of the desired item in the array. + * @return Deserializes the data and returns the pointer for the newly created object for the data at the provided index. + * @throws IllegalArgumentException If provided index is greater than the maximum array index. + */ + std::auto_ptr get(size_t index) const { + checkIndex(index); + return serializationService->toObject(values[index]); + } + + /** + * Please note that this operation is costly due to de-serialization. It will NOT cache the de-serialized data. + * + * @param index The index of the desired item in the array. + * @return Deserializes the data and returns the pointer for the newly created object for the data at the provided index. + * @throws IllegalArgumentException If provided index is greater than the maximum array index. + */ + std::auto_ptr operator[](size_t index) const { + return get(index); + } + private: + std::vector values; + // Made serializationService a pointer rather than a reference in order to allow DataArray be copiable. + // Otherwise, compilation fails telling that SerializationService is not copiable even though it is a reference. + serialization::pimpl::SerializationService *serializationService; + + /** + * @throws IllegalArgumentException If provided index is greater than the maximum array index. + */ + void checkIndex(size_t index) const { + size_t len = values.size(); + if (0 == len) { + char msg[200]; + util::snprintf(msg, 200, + "The are no elements in the array, you should not try accessing any element of the " + "array. Provided index (%lu) id out of range.", index); + throw client::exception::IllegalArgumentException("DataArray", msg); + } + + if (index >= len) { + char msg[200]; + util::snprintf(msg, 200, "Provided index (%lu) id out of range. Maximum allowed index is %lu", + index, (len - 1)); + throw client::exception::IllegalArgumentException("DataArray", msg); + } + } + + // prevent copy operations + DataArray(const DataArray &rhs); + DataArray &operator =(const DataArray &rhs); + }; + } + } +} + +#endif //HAZELCAST_CLIENT_ADAPTOR_DATAARRAY_H_ + diff --git a/hazelcast/include/hazelcast/client/adaptor/EntryArray.h b/hazelcast/include/hazelcast/client/adaptor/EntryArray.h new file mode 100644 index 0000000000..175e50a062 --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/EntryArray.h @@ -0,0 +1,104 @@ +/* + * 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 ihsan demir on 25 02, 2016. +// +#ifndef HAZELCAST_CLIENT_ADAPTOR_ENTRYARRAY_H_ +#define HAZELCAST_CLIENT_ADAPTOR_ENTRYARRAY_H_ + +#include + +#include "hazelcast/util/Util.h" +#include +#include "hazelcast/client/serialization/pimpl/SerializationService.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + template + class EntryArray { + public: + EntryArray(const std::vector > &entries, + serialization::pimpl::SerializationService &service) : dataEntries(entries), + serializationService(service) { + } + + /** + * @return Returns the number of data items + */ + size_t size() const { + return dataEntries.size(); + } + + /** + * Please note that this operation is costly due to de-serialization. It will NOT cache the de-serialized data. + * + * @param index The index of the desired item in the array. + * @return Deserializes the data and returns the key object for the data at the provided index. + * @throws IllegalArgumentException If provided index is greater than the maximum array index. + */ + std::auto_ptr getKey(size_t index) const { + checkIndex(index); + return serializationService.toObject(dataEntries[index].first); + } + + /** + * Please note that this operation is costly due to de-serialization. It will NOT cache the de-serialized data. + * + * @param index The index of the desired item in the array. + * @return Deserializes the data and returns the value object for the data at the provided index. + * @throws IllegalArgumentException If provided index is greater than the maximum array index. + */ + std::auto_ptr getValue(size_t index) const { + checkIndex(index); + return serializationService.toObject(dataEntries[index].second); + } + private: + std::vector > dataEntries; + serialization::pimpl::SerializationService &serializationService; + + /** + * @throws IllegalArgumentException If provided index is greater than the maximum array index. + */ + void checkIndex(size_t index) const { + size_t len = dataEntries.size(); + if (0 == len) { + char msg[200]; + util::snprintf(msg, 200, + "The are no elements in the array, you should not try accessing any element of the " + "array. Provided index (%lu) id out of range.", index); + throw client::exception::IllegalArgumentException("DataArray", msg); + } + + if (index >= len) { + char msg[200]; + util::snprintf(msg, 200, "Provided index (%lu) id out of range. Maximum allowed index is %lu", + index, (len - 1)); + throw client::exception::IllegalArgumentException("EntryArray", msg); + } + + } + + // prevent copy operations + EntryArray(const EntryArray &rhs); + EntryArray &operator =(const EntryArray &rhs); + }; + } + } +} + +#endif //HAZELCAST_CLIENT_ADAPTOR_ENTRYARRAY_H_ + diff --git a/hazelcast/include/hazelcast/client/adaptor/EntryView.h b/hazelcast/include/hazelcast/client/adaptor/EntryView.h new file mode 100644 index 0000000000..df4b45b445 --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/EntryView.h @@ -0,0 +1,132 @@ +/* + * 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 ihsan demir on 29 Feb 2016. + +#ifndef HAZELCAST_CLIENT_ADAPTOR_ENTRYVIEW_H_ +#define HAZELCAST_CLIENT_ADAPTOR_ENTRYVIEW_H_ + +#include "hazelcast/client/map/DataEntryView.h" + +#include +#include + +#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) +#pragma warning(push) +#pragma warning(disable: 4251) //for dll export +#endif + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * EntryView represents a readonly view of a map entry. + */ + template + class EntryView{ + public: + /** + * Constructor + */ + EntryView(std::auto_ptr v, serialization::pimpl::SerializationService &srv) + : dataView(v), serializationService(srv) { + } + + /** + * @return Returns the deserialized key object for the entry, performs lazy deserialization. + */ + std::auto_ptr getKey() const { + return serializationService.toObject(dataView->getKey()); + } + + /** + * @return Returns the deserialized value object for the entry, performs lazy deserialization. + */ + std::auto_ptr getValue() const { + return serializationService.toObject(dataView->getValue()); + } + + /** + * @return Returns the cost for the map entry + */ + long getCost() const { + return dataView->getCost(); + } + + /** + * @return Returns the map entry creation time + */ + long getCreationTime() const { + return dataView->getCreationTime(); + } + + /** + * @return Returns the expiration time of the entry. + */ + long getExpirationTime() const { + return dataView->getExpirationTime(); + } + + /** + * @return Returns the number of hits for the map entry + */ + long getHits() const { + return dataView->getHits(); + } + + /** + * @return Returns the time that the map entry is last accessed + */ + long getLastAccessTime() const { + return dataView->getLastAccessTime(); + } + + /** + * @return Returns the last that that the map entry is stored + */ + long getLastStoredTime() const { + return dataView->getLastStoredTime(); + } + + /** + * @return Returns the time that the entry is last updated. + */ + long getLastUpdateTime() const { + return dataView->getLastAccessTime(); + } + + /** + * @return Returns the version of the map entry. + */ + long getVersion() const { + return dataView->getVersion(); + } + + private: + std::auto_ptr dataView; + + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + +#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) +#pragma warning(pop) +#endif + +#endif //HAZELCAST_CLIENT_ADAPTOR_ENTRYVIEW_H_ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerList.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerList.h new file mode 100644 index 0000000000..a0958e59d4 --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerList.h @@ -0,0 +1,283 @@ +/* + * 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. + */ +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERLIST_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERLIST_H_ + +#include "hazelcast/client/IList.h" +#include "hazelcast/client/adaptor/EntryView.h" +#include "hazelcast/client/adaptor/DataArray.h" +#include "hazelcast/client/adaptor/EntryArray.h" + +#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) +#pragma warning(push) +#pragma warning(disable: 4251) //for dll export +#endif + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * Concurrent, distributed , client implementation of std::list + * + * @param item type + */ + template + class RawPointerList { + public: + RawPointerList(IList &listToBeAdopted): list(listToBeAdopted), serializationService( + list.context->getSerializationService()) { + } + + /** + * + * Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. + * otherwise it will slow down the system. + * + * Warning 2: Do not make a call to hazelcast. It can cause deadlock. + * + * @param listener that will be added + * @param includeValue bool value representing value should be included in ItemEvent or not. + * @returns registrationId that can be used to remove item listener + */ + std::string addItemListener(ItemListener &listener, bool includeValue) { + return list.addItemListener(listener, includeValue); + } + + /** + * Removes the specified item listener. + * Returns false if the specified listener is not added before. + * + * @param registrationId Id of listener registration. + * + * @return true if registration is removed, false otherwise + */ + bool removeItemListener(const std::string ®istrationId) { + return list.removeItemListener(registrationId); + } + + /** + * + * @return size of the distributed list + */ + int size() { + return list.size(); + } + + /** + * + * @return true if empty + */ + bool isEmpty() { + return list.isEmpty(); + } + + /** + * + * @param element + * @returns true if list contains element + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool contains(const T &element) { + return list.contains(element); + } + + /** + * + * @returns all elements in the list + */ + std::auto_ptr > toArray() { + return std::auto_ptr >(new DataArray(list.toArrayData(), serializationService)); + } + + /** + * + * @param element + * @return true if element is added successfully. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool add(const T &element) { + return list.add(element); + } + + /** + * + * @param element + * @return true if element is removed successfully. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool remove(const T &element) { + return list.remove(element); + } + + /** + * + * @param elements Items to look for in the list + * @return true if this list contains all elements given in vector. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool containsAll(const std::vector &elements) { + return list.containsAll(elements); + } + + /** + * + * @param elements Items to be added to the list + * @return true if all elements given in vector can be added to list. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool addAll(const std::vector &elements) { + return list.addAll(elements); + } + + /** + * Adds elements in vector to the list with given order. + * Starts adding elements from given index, + * and shifts others to the right. + * + * @param index start point of insterting given elements + * @param elements vector of elements that will be added to list + * @return true if list elements are added. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + * @throws IndexOutOfBoundsException if the index is out of range. + */ + bool addAll(int index, const std::vector &elements) { + return list.addAll(index, elements); + } + + /** + * + * @param elements Items to be removed from the list + * @return true if all elements are removed successfully. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool removeAll(const std::vector &elements) { + return list.removeAll(elements); + } + + /** + * + * Removes the elements from this list that are not available in given "elements" vector + * @param elements Items to retain in the list + * @return true if operation is successful. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool retainAll(const std::vector &elements) { + return list.retainAll(elements); + } + + /** + * Removes all elements from list. + */ + void clear() { + list.clear(); + } + + /** + * You can check if element is available by + * + * std::auto_ptr e = list.get(5); + * if(e.get() != NULL ) + * //......; + * + * @param index + * @return element in given index. If not available returns empty constructed auto_ptr. + * @throws IndexOutOfBoundsException if the index is out of range. + * + */ + std::auto_ptr get(int index) { + return serializationService.toObject(list.getData(index).get()); + } + + /** + * Replaced the element in the given index. And returns element if there were entry before inserting. + * + * @param index insert position + * @param element to be inserted. + * @return oldElement in given index. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + * @throws IndexOutOfBoundsException if the index is out of range. + */ + std::auto_ptr set(int index, const T &element) { + return serializationService.toObject(list.setData(index, serializationService.toData(&element)).get()); + } + + /** + * Adds the element to the given index. Shifts others to the right. + * + * @param index insert position + * @param element to be inserted. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + * @throws IndexOutOfBoundsException if the index is out of range. + */ + void add(int index, const T &element) { + list.add(index, element); + } + + /** + * + * @param index + * @return element in given index. If not available returns empty constructed auto_ptr. + * @see get + * @throws IndexOutOfBoundsException if the index is out of range. + */ + std::auto_ptr remove(int index) { + return serializationService.toObject(list.removeData(index).get()); + } + + /** + * + * @param element that will be searched + * @return index of first occurrence of given element in the list. + * Returns -1 if element is not in the list. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + int indexOf(const T &element) { + return list.indexOf(element); + } + + /** + * @param element that will be searched + * @return index of last occurrence of given element in the list. + * Returns -1 if element is not in the list. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + int lastIndexOf(const T &element) { + return list.lastIndexOf(element); + } + + /** + * + * @return the sublist between given indexes. + * @throws IndexOutOfBoundsException if the index is out of range. + */ + std::auto_ptr > subList(int fromIndex, int toIndex) { + return std::auto_ptr >(new DataArray(list.subListData(fromIndex, toIndex), serializationService)); + } + + private: + IList &list; + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + +#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) +#pragma warning(pop) +#endif + +#endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERLIST_H_ */ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerMap.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerMap.h new file mode 100644 index 0000000000..73be577793 --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerMap.h @@ -0,0 +1,741 @@ +/* + * 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. + */ +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMAP_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMAP_H_ + +#include "hazelcast/client/IMap.h" +#include "hazelcast/client/adaptor/EntryView.h" +#include "hazelcast/client/adaptor/DataArray.h" +#include "hazelcast/client/adaptor/EntryArray.h" + +#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) +#pragma warning(push) +#pragma warning(disable: 4251) //for dll export +#endif + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * + * + * Adaptor class to IMap which provides releasable raw pointers for returned objects. + * + * Notice that this class have a private constructor. + * You can access get an IMap in the following way + * + * ClientConfig clientConfig; + * HazelcastClient client(clientConfig); + * IMap imap = client.getMap("aKey"); + * + * @param key + * @param value + */ + template + class RawPointerMap { + public: + RawPointerMap(IMap &mapToBeAdopted) : map(mapToBeAdopted), serializationService( + map.context->getSerializationService()) { + } + + /** + * check if this map contains key. + * @param key + * @return true if contains, false otherwise + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool containsKey(const K &key) { + return map.containsKey(key); + } + + /** + * check if this map contains value. + * @param value + * @return true if contains, false otherwise + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool containsValue(const V &value) { + return map.containsValue(value); + } + + /** + * get the value. + * @param key + * @return value value in auto_ptr, if there is no mapping for key + * then return NULL in auto_ptr. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + std::auto_ptr get(const K &key) { + return serializationService.toObject(map.getData(serializationService.toData(&key)).get()); + } + + /** + * put new entry into map. + * @param key + * @param value + * @return the previous value in auto_ptr, if there is no mapping for key + * @throws IClassCastException if the type of the specified elements are incompatible with the server side. + * then returns NULL in auto_ptr. + */ + std::auto_ptr put(const K &key, const V &value) { + return serializationService.toObject( + map.putData(serializationService.toData(&key), + serializationService.toData(&value)).get()); + } + + /** + * remove entry form map + * @param key + * @return the previous value in auto_ptr, if there is no mapping for key + * then returns NULL in auto_ptr. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + std::auto_ptr remove(const K &key) { + return serializationService.toObject(map.removeData(serializationService.toData(&key)).get()); + } + + /** + * removes entry from map if there is an entry with same key and value. + * @param key + * @param value + * @return true if remove is successful false otherwise + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool remove(const K &key, const V &value) { + return map.remove(key, value); + } + + /** + * removes entry from map. + * Does not return anything. + * @param key The key of the map entry to remove. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + void deleteEntry(const K &key) { + map.deleteEntry(key); + } + + /** + * If this map has a MapStore this method flushes + * all the local dirty entries by calling MapStore.storeAll() and/or MapStore.deleteAll() + */ + void flush() { + map.flush(); + } + + /** + * Tries to remove the entry with the given key from this map + * within specified timeout value. If the key is already locked by another + * thread and/or member, then this operation will wait timeout + * amount for acquiring the lock. + * + * @param key key of the entry + * @param timeoutInMillis maximum time in milliseconds to wait for acquiring the lock + * for the key + */ + bool tryRemove(const K &key, long timeoutInMillis) { + return map.tryRemove(key, timeoutInMillis); + } + + /** + * Tries to put the given key, value into this map within specified + * timeout value. If this method returns false, it means that + * the caller thread couldn't acquire the lock for the key within + * timeout duration, thus put operation is not successful. + * + * @param key key of the entry + * @param value value of the entry + * @param timeoutInMillis maximum time to wait in milliseconds + * @return true if the put is successful, false + * otherwise. + */ + bool tryPut(const K &key, const V &value, long timeoutInMillis) { + return map.tryPut(key, value, timeoutInMillis); + } + + /** + * Puts an entry into this map with a given ttl (time to live) value. + * Entry will expire and get evicted after the ttl. If ttl is 0, then + * the entry lives forever. + * + * @param key key of the entry + * @param value value of the entry + * @param ttlInMillis maximum time for this entry to stay in the map in milliseconds,0 means infinite. + * @return the previous value in auto_ptr, if there is no mapping for key + * then returns NULL in auto_ptr. + */ + std::auto_ptr put(const K &key, const V &value, long ttlInMillis) { + return serializationService.toObject( + map.putData(serializationService.toData(&key), serializationService.toData(&value), + ttlInMillis).get()); + } + + /** + * Same as put(K, V, long, TimeUnit) but MapStore, if defined, + * will not be called to store/persist the entry. If ttl is 0, then + * the entry lives forever. + * + * @param key key of the entry + * @param value value of the entry + * @param ttlInMillis maximum time for this entry to stay in the map in milliseconds, 0 means infinite. + */ + void putTransient(const K &key, const V &value, long ttlInMillis) { + map.putTransient(key, value, ttlInMillis); + } + + /** + * Puts an entry into this map, if the specified key is not already associated with a value. + * + * @param key key with which the specified value is to be associated + * @param value + * @return the previous value in auto_ptr, if there is no mapping for key + * then returns NULL in auto_ptr. + */ + std::auto_ptr putIfAbsent(const K &key, const V &value) { + return serializationService.toObject(map.putIfAbsentData(serializationService.toData(&key), + serializationService.toData(&value), + -1).get()); + } + + /** + * Puts an entry into this map with a given ttl (time to live) value + * if the specified key is not already associated with a value. + * Entry will expire and get evicted after the ttl. + * + * @param key key of the entry + * @param value value of the entry + * @param ttlInMillis maximum time in milliseconds for this entry to stay in the map + * @return the previous value of the entry, if there is no mapping for key + * then returns NULL in auto_ptr. + */ + std::auto_ptr putIfAbsent(const K &key, const V &value, long ttlInMillis) { + return serializationService.toObject( + map.putIfAbsentData(serializationService.toData(&key), + serializationService.toData(&value), + ttlInMillis).get()); + } + + /** + * Replaces the entry for a key only if currently mapped to a given value. + * @param key key with which the specified value is associated + * @param oldValue value expected to be associated with the specified key + * @param newValue + * @return true if the value was replaced + */ + bool replace(const K &key, const V &oldValue, const V &newValue) { + return map.replace(key, oldValue, newValue); + } + + /** + * Replaces the entry for a key only if currently mapped to some value. + * @param key key with which the specified value is associated + * @param value + * @return the previous value of the entry, if there is no mapping for key + * then returns NULL in auto_ptr. + */ + std::auto_ptr replace(const K &key, const V &value) { + return serializationService.toObject( + map.replaceData(serializationService.toData(&key), serializationService.toData(&value)).get()); + } + + /** + * Puts an entry into this map. + * Similar to put operation except that set + * doesn't return the old value which is more efficient. + * @param key key with which the specified value is associated + * @param value + * @param ttl maximum time in milliseconds for this entry to stay in the map + 0 means infinite. + */ + void set(const K &key, const V &value, long ttl) { + map.set(key, value, ttl); + } + + /** + * Acquires the lock for the specified key. + *

If the lock is not available then + * the current thread becomes disabled for thread scheduling + * purposes and lies dormant until the lock has been acquired. + * + * Scope of the lock is this map only. + * Acquired lock is only for the key in this map. + * + * Locks are re-entrant so if the key is locked N times then + * it should be unlocked N times before another thread can acquire it. + * + * @param key key to lock. + */ + void lock(const K &key) { + map.lock(key); + } + + /** + * Acquires the lock for the specified key for the specified lease time. + *

After lease time, lock will be released.. + * + *

If the lock is not available then + * the current thread becomes disabled for thread scheduling + * purposes and lies dormant until the lock has been acquired. + * + * Scope of the lock is this map only. + * Acquired lock is only for the key in this map. + * + * Locks are re-entrant so if the key is locked N times then + * it should be unlocked N times before another thread can acquire it. + * + * + * @param key key to lock. + * @param leaseTime time in milliseconds to wait before releasing the lock. + */ + void lock(const K &key, long leaseTime) { + map.lock(key, leaseTime); + } + + /** + * Checks the lock for the specified key. + *

If the lock is acquired then returns true, else false. + * + * + * @param key key to lock to be checked. + * @return true if lock is acquired, false otherwise. + */ + bool isLocked(const K &key) { + return map.isLocked(key); + } + + /** + * Tries to acquire the lock for the specified key. + *

If the lock is not available then the current thread + * doesn't wait and returns false immediately. + * + * + * @param key key to lock. + * @return true if lock is acquired, false otherwise. + */ + bool tryLock(const K &key) { + return map.tryLock(key, 0); + } + + /** + * Tries to acquire the lock for the specified key. + *

If the lock is not available then + * the current thread becomes disabled for thread scheduling + * purposes and lies dormant until one of two things happens: + *

    + *
  • The lock is acquired by the current thread; or + *
  • The specified waiting time elapses + *
+ * + * + * @param key key to lock in this map + * @param timeInMillis maximum time in milliseconds to wait for the lock + * @return true if the lock was acquired and false + * if the waiting time elapsed before the lock was acquired. + */ + bool tryLock(const K &key, long timeInMillis) { + return map.tryLock(key, timeInMillis); + } + + /** + * Releases the lock for the specified key. It never blocks and + * returns immediately. + * + *

If the current thread is the holder of this lock then the hold + * count is decremented. If the hold count is now zero then the lock + * is released. If the current thread is not the holder of this + * lock then IllegalMonitorStateException is thrown. + * + * + * @param key key to lock. + * @throws IllegalMonitorStateException if the current thread does not hold this lock MTODO + */ + void unlock(const K &key) { + map.unlock(key); + } + + /** + * Releases the lock for the specified key regardless of the lock owner. + * It always successfully unlocks the key, never blocks + * and returns immediately. + * + * + * @param key key to lock. + */ + void forceUnlock(const K &key) { + map.forceUnlock(key); + } + + /** + * Adds an interceptor for this map. Added interceptor will intercept operations + * and execute user defined methods and will cancel operations if user defined method throw exception. + * + * + * Interceptor should extend either Portable or IdentifiedSerializable. + * Notice that map interceptor runs on the nodes. Because of that same class should be implemented in java side + * with same classId and factoryId. + * @param interceptor map interceptor + * @return id of registered interceptor + */ + template + std::string addInterceptor(MapInterceptor &interceptor) { + return map.template addInterceptor(interceptor); + } + + /** + * Removes the given interceptor for this map. So it will not intercept operations anymore. + * + * + * @param id registration id of map interceptor + */ + void removeInterceptor(const std::string &id) { + map.removeInterceptor(id); + } + + /** + * Adds an entry listener for this map. + * + * Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. + * otherwise it will slow down the system. + * + * Warning 2: Do not make a call to hazelcast. It can cause deadlock. + * + * @param listener entry listener + * @param includeValue true if EntryEvent should + * contain the value. + * + * @return registrationId of added listener that can be used to remove the entry listener. + */ + std::string addEntryListener(EntryListener &listener, bool includeValue) { + return map.addEntryListener(listener, includeValue); + } + + /** + * Removes the specified entry listener + * Returns silently if there is no such listener added before. + * + * + * @param registrationId id of registered listener + * + * @return true if registration is removed, false otherwise + */ + bool removeEntryListener(const std::string ®istrationId) { + return map.removeEntryListener(registrationId); + } + + + /** + * Adds the specified entry listener for the specified key. + * + * Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. + * otherwise it will slow down the system. + * + * Warning 2: Do not make a call to hazelcast. It can cause deadlock. + * + * @param listener entry listener + * @param key key to listen + * @param includeValue true if EntryEvent should + * contain the value. + */ + std::string addEntryListener(EntryListener &listener, const K &key, bool includeValue) { + return map.addEntryListener(listener, key, includeValue); + } + + /** + * Returns the EntryView for the specified key. + * + * + * @param key key of the entry + * @return EntryView of the specified key + * @see EntryView + */ + std::auto_ptr > getEntryView(const K &key) { + std::auto_ptr dataView = map.getEntryViewData(serializationService.toData(&key)); + return std::auto_ptr >(new adaptor::EntryView(dataView, serializationService)); + } + + /** + * Evicts the specified key from this map. If + * a MapStore defined for this map, then the entry is not + * deleted from the underlying MapStore, evict only removes + * the entry from the memory. + * + * + * @param key key to evict + * @return true if the key is evicted, false otherwise. + */ + bool evict(const K &key) { + return map.evict(key); + } + + /** + * Evicts all keys from this map except locked ones. + *

+ * If a MapStore is defined for this map, deleteAll is not called by this method. + * If you do want to deleteAll to be called use the #clear() method. + *

+ * The EVICT_ALL event is fired for any registered listeners. + * See EntryListener#mapEvicted(MapEvent)}. + * + * @see #clear() + */ + void evictAll() { + map.evictAll(); + } + + /** + * Returns the entries for the given keys. + * + * @param keys keys for which the entries shall be retrieved from the map. + * @return Array of entries for the provided keys + */ + std::auto_ptr > getAll(const std::set &keys) { + std::vector allKeys(keys.size()); + int i = 0; + for (typename std::set::iterator it = keys.begin(); it != keys.end(); ++it) { + allKeys[i++] = serializationService.toData(&(*it)); + } + std::vector > entrySet = map.getAllData( + allKeys); + + return std::auto_ptr >(new EntryArray(entrySet, serializationService)); + } + + /** + * Returns a snaphot of the deys data in the map. + * The vector is NOT backed by the map, + * so changes to the map are NOT reflected in the vector, and vice-versa. + * + * @return DataArray from which the key for each index can be retrieved. + */ + std::auto_ptr > keySet() { + std::vector dataResult = map.keySetData(); + return std::auto_ptr >(new DataArray(dataResult, serializationService)); + } + + /** + * Queries the map based on the specified predicate and + * returns the keys of matching entries. + * + * Specified predicate runs on all members in parallel. + * + * + * @param predicate query criteria + * @return result key set of the query + */ + std::auto_ptr > keySet(const serialization::IdentifiedDataSerializable &predicate) { + std::vector dataResult = map.keySetData(predicate); + return std::auto_ptr >(new DataArray(dataResult, serializationService)); + } + + /** + * Returns a vector clone of the values contained in this map. + * The vector is NOT backed by the map, + * so changes to the map are NOT reflected in the collection, and vice-versa. + * + * @return clone of the values contained in this map + */ + std::auto_ptr > values() { + std::vector dataResult = map.valuesData(); + return std::auto_ptr >(new DataArray(dataResult, serializationService)); + } + + /** + * Returns a vector clone of the values contained in this map. + * The vector is NOT backed by the map, + * so changes to the map are NOT reflected in the collection, and vice-versa. + * + * @param predicate the criteria for values to match + * @return clone of the values contained in this map + */ + std::auto_ptr > values(const serialization::IdentifiedDataSerializable &predicate) { + std::vector dataResult = map.valuesData(predicate); + return std::auto_ptr >(new DataArray(dataResult, serializationService)); + } + + /** + * Returns a std::vector< std::pair > clone of the mappings contained in this map. + * The vector is NOT backed by the map, + * so changes to the map are NOT reflected in the set, and vice-versa. + * + * @return clone of the keys mappings in this map + */ + std::auto_ptr > entrySet() { + EntryVector entries = map.entrySetData(); + return std::auto_ptr >(new EntryArray(entries, serializationService)); + } + + /** + * Queries the map based on the specified predicate and + * returns the matching entries. + * + * Specified predicate runs on all members in parallel. + * + * + * @param predicate query criteria + * @return result entry array of the query + */ + std::auto_ptr > entrySet(const serialization::IdentifiedDataSerializable &predicate) { + EntryVector entries = map.entrySetData(predicate); + return std::auto_ptr >(new EntryArray(entries, serializationService)); + } + + /** + * Adds an index to this map for the specified entries so + * that queries can run faster. + * + * Let's say your map values are Employee objects. + * + * class Employee : public serialization::Portable { + * //... + * private: + * bool active; + * int age; + * std::string name; + * + * } + * + * + * If you are querying your values mostly based on age and active then + * you should consider indexing these fields. + * + * IMap imap = hazelcastInstance.getMap("employees"); + * imap.addIndex("age", true); // ordered, since we have ranged queries for this field + * imap.addIndex("active", false); // not ordered, because boolean field cannot have range + * + * + * In the server side, Index should either have a getter method or be public. + * You should also make sure to add the indexes before adding + * entries to this map. + * + * @param attribute attribute of value + * @param ordered true if index should be ordered, + * false otherwise. + */ + void addIndex(const std::string &attribute, bool ordered) { + map.addIndex(attribute, ordered); + } + + /** + * Applies the user defined EntryProcessor to the entry mapped by the key. + * Returns the the ResultType which is result of the process() method of EntryProcessor. + * + * EntryProcessor should extend either Portable or IdentifiedSerializable. + * Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side + * with same classId and factoryId. + * + * @tparam EntryProcessor type of entry processor class + * @tparam ResultType that entry processor will return + * @param entryProcessor that will be applied + * @param key of entry that entryProcessor will be applied on + * @return result of entry process. + */ + template + std::auto_ptr executeOnKey(const K &key, EntryProcessor &entryProcessor) { + std::auto_ptr resultData = map.template executeOnKeyData( + key, entryProcessor); + return serializationService.toObject(resultData.get()); + } + + /** + * Applies the user defined EntryProcessor to the all entries in the map. + * Returns the results mapped by each key in the map. + * + * + * EntryProcessor should extend either Portable or IdentifiedSerializable. + * Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side + * with same classId and factoryId. + * + * @tparam ResultType that entry processor will return + * @tparam EntryProcessor type of entry processor class + * @param entryProcessor that will be applied + * @return Returns an array of (Key, Result) pairs. + */ + template + std::auto_ptr > executeOnEntries(EntryProcessor &entryProcessor) { + EntryVector results = map.template executeOnEntriesData(entryProcessor); + + return std::auto_ptr >(new EntryArray(results, serializationService)); + } + + /** + * Puts an entry into this map. + * Similar to put operation except that set + * doesn't return the old value which is more efficient. + * @param key + * @param value + */ + void set(const K &key, const V &value) { + set(key, value, -1); + } + + /** + * Returns the number of key-value mappings in this map. If the + * map contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size() { + return map.size(); + } + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + bool isEmpty() { + return map.isEmpty(); + } + + + /** + * Copies all of the mappings from the specified map to this map + * (optional operation). The effect of this call is equivalent to that + * of calling put(k, v) on this map once + * for each mapping from key k to value v in the + * specified map. The behavior of this operation is undefined if the + * specified map is modified while the operation is in progress. + * + * @param m mappings to be stored in this map + */ + void putAll(const std::map &entries) { + map.putAll(entries); + } + + /** + * Removes all of the mappings from this map (optional operation). + * The map will be empty after this call returns. + */ + void clear() { + map.clear(); + } + + + private: + IMap ↦ + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + +#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) +#pragma warning(pop) +#endif + +#endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMAP_H_ */ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerMultiMap.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerMultiMap.h new file mode 100644 index 0000000000..6bdb41981e --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerMultiMap.h @@ -0,0 +1,333 @@ +/* + * 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. + */ +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMULTIMAP_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMULTIMAP_H_ + +#include "hazelcast/client/MultiMap.h" +#include "hazelcast/client/adaptor/DataArray.h" +#include "hazelcast/client/adaptor/EntryArray.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * A specialized distributed map client whose keys can be associated with multiple values. + * + * @see IMap + */ + template + class RawPointerMultiMap { + public: + RawPointerMultiMap(MultiMap &m) :map(m), serializationService(m.context->getSerializationService()) { + } + + /** + * Stores a key-value pair in the multimap. + * + * + * @param key the key to be stored + * @param value the value to be stored + * @return true if size of the multimap is increased, false if the multimap + * already contains the key-value pair. + */ + bool put(const K &key, const V &value) { + return map.put(key, value); + } + + /** + * Returns the multimap of values associated with the key. + * + * @param key the key whose associated values are to be returned + * @return the multimap of the values associated with the key. + */ + std::auto_ptr > get(const K &key) { + return std::auto_ptr >(new DataArray(map.getData(serializationService.toData(&key)), serializationService)); + } + + /** + * Removes the given key value pair from the multimap. + * + * @param key + * @param value + * @return true if the size of the multimap changed after the remove operation, false otherwise. + */ + bool remove(const K &key, const V &value) { + return map.remove(key, value); + } + + /** + * Removes all the entries with the given key. + * + * @param key + * @return the multimap of removed values associated with the given key. Returned multimap + * might be modifiable but it has no effect on the multimap + */ + std::auto_ptr > remove(const K &key) { + return std::auto_ptr >(new DataArray(map.removeData(serializationService.toData(&key)), serializationService)); + } + + /** + * Returns the set of keys in the multimap. + * + * @return the set of keys in the multimap. Returned set might be modifiable + * but it has no effect on the multimap + */ + std::auto_ptr > keySet() { + return std::auto_ptr >(new DataArray(map.keySetData(), serializationService)); + } + + /** + * Returns the multimap of values in the multimap. + * + * @return the multimap of values in the multimap. Returned multimap might be modifiable + * but it has no effect on the multimap + */ + std::auto_ptr > values() { + return std::auto_ptr >(new DataArray(map.valuesData(), serializationService)); + } + + /** + * Returns the set of key-value pairs in the multimap. + * + * @return the set of key-value pairs in the multimap. Returned set might be modifiable + * but it has no effect on the multimap + */ + std::auto_ptr > entrySet() { + return std::auto_ptr >(new EntryArray(map.entrySetData(), serializationService)) ; + } + + /** + * Returns whether the multimap contains an entry with the key. + * + * @param key the key whose existence is checked. + * @return true if the multimap contains an entry with the key, false otherwise. + */ + bool containsKey(const K &key) { + return map.containsKey(key); + } + + /** + * Returns whether the multimap contains an entry with the value. + * + * @param value the value whose existence is checked. + * @return true if the multimap contains an entry with the value, false otherwise. + */ + bool containsValue(const V &value) { + return map.containsValue(value); + } + + /** + * Returns whether the multimap contains the given key-value pair. + * + * @param key the key whose existence is checked. + * @param value the value whose existence is checked. + * @return true if the multimap contains the key-value pair, false otherwise. + */ + bool containsEntry(const K &key, const V &value) { + return map.containsEntry(key, value); + } + + /** + * Returns the number of key-value pairs in the multimap. + * + * @return the number of key-value pairs in the multimap. + */ + int size() { + return map.size(); + } + + /** + * Clears the multimap. Removes all key-value pairs. + */ + void clear() { + map.clear(); + } + + /** + * Returns number of values matching to given key in the multimap. + * + * + * @param key the key whose values count are to be returned + * @return number of values matching to given key in the multimap. + */ + int valueCount(const K &key) { + return map.valueCount(key); + } + + /** + * Adds an entry listener for this multimap. Listener will get notified + * for all multimap add/remove/update/evict events. + * + * Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. + * otherwise it will slow down the system. + * + * Warning 2: Do not make a call to hazelcast. It can cause deadlock. + * + * @param listener entry listener + * @param includeValue true if EntryEvent should + * contain the value. + * @return returns registration id. + */ + std::string addEntryListener(EntryListener &listener, bool includeValue) { + return map.addEntryListener(listener, includeValue); + } + + /** + * Adds the specified entry listener for the specified key. + * The listener will get notified for all + * add/remove/update/evict events of the specified key only. + * + * Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. + * otherwise it will slow down the system. + * + * Warning 2: Do not make a call to hazelcast. It can cause deadlock. + * + * @param listener entry listener + * @param key the key to listen + * @param includeValue true if EntryEvent should + * contain the value. + * @return returns registration id. + */ + std::string addEntryListener(EntryListener &listener, const K &key, bool includeValue) { + return map.addEntryListener(listener, key, includeValue); + } + + /** + * Removes the specified entry listener + * Returns silently if there is no such listener added before. + * + * @param registrationId Id of listener registration + * + * @return true if registration is removed, false otherwise + */ + bool removeEntryListener(const std::string ®istrationId) { + return map.removeEntryListener(registrationId); + } + + /** + * Acquires the lock for the specified key. + *

If the lock is not available then + * the current thread becomes disabled for thread scheduling + * purposes and lies dormant until the lock has been acquired. + * + * Scope of the lock is this multimap only. + * Acquired lock is only for the key in this multimap. + * + * Locks are re-entrant so if the key is locked N times then + * it should be unlocked N times before another thread can acquire it. + * + * + * @param key key to lock. + */ + void lock(const K &key) { + map.lock(key); + } + + /** + * Acquires the lock for the specified key for the specified lease time. + *

After lease time, lock will be released.. + * + *

If the lock is not available then + * the current thread becomes disabled for thread scheduling + * purposes and lies dormant until the lock has been acquired. + * + * Scope of the lock is this map only. + * Acquired lock is only for the key in this map. + * + * Locks are re-entrant so if the key is locked N times then + * it should be unlocked N times before another thread can acquire it. + * @param key key to lock. + * @param leaseTimeInMillis time in milliseconds to wait before releasing the lock. + */ + void lock(const K &key, long leaseTimeInMillis) { + map.lock(key, leaseTimeInMillis); + } + + /** + * Checks the lock for the specified key. + *

If the lock is acquired then returns true, else false. + * + * @param key key to lock to be checked. + * @return true if lock is acquired, false otherwise. + */ + bool isLocked(const K &key) { + return map.isLocked(key); + } + + /** + * Tries to acquire the lock for the specified key. + *

If the lock is not available then the current thread + * doesn't wait and returns false immediately. + * + * + * @param key key to lock. + * @return true if lock is acquired, false otherwise. + */ + bool tryLock(const K &key) { + return map.tryLock(key); + } + + /** + * Tries to acquire the lock for the specified key. + *

If the lock is not available then + * the current thread becomes disabled for thread scheduling + * purposes and lies dormant until one of two things happens: + *

    + *
  • The lock is acquired by the current thread; or + *
  • The specified waiting time elapses + *
+ * + * + * @param key to be locked. + * @param timeoutInMillis the maximum time to wait for the lock + * @return true if the lock was acquired and false + * if the waiting time elapsed before the lock was acquired. + */ + bool tryLock(const K &key, long timeoutInMillis) { + return map.tryLock(key, timeoutInMillis); + } + + /** + * Releases the lock for the specified key. It never blocks and + * returns immediately. + * + * + * @param key key to lock. + */ + void unlock(const K &key) { + map.unlock(key); + } + + /** + * Releases the lock for the specified key regardless of the lock owner. + * It always successfully unlocks the key, never blocks + * and returns immediately. + * @param key key to lock. + */ + void forceUnlock(const K &key) { + map.forceUnlock(key); + } + + private: + MultiMap ↦ + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + +#endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMULTIMAP_H_ */ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerQueue.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerQueue.h new file mode 100644 index 0000000000..d4aefaa47f --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerQueue.h @@ -0,0 +1,261 @@ +/* + * 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. + */ +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERQUEUE_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERQUEUE_H_ + +#include + +#include "hazelcast/client/IQueue.h" +#include "hazelcast/client/adaptor/DataArray.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * Concurrent, blocking, distributed, observable, client queue. + * + * @tparam T item type + */ + template + class RawPointerQueue { + public: + RawPointerQueue(IQueue &q) : queue(q), serializationService(q.context->getSerializationService()) { + } + + /** + * Adds an item listener for this collection. Listener will get notified + * for all collection add/remove events. + * + * Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. + * otherwise it will slow down the system. + * + * Warning 2: Do not make a call to hazelcast. It can cause deadlock. + * + * @param listener item listener + * @param includeValue true updated item should be passed + * to the item listener, false otherwise. + * @return returns registration id. + */ + std::string addItemListener(ItemListener &listener, bool includeValue) { + return queue.addItemListener(listener, includeValue); + } + + /** + * Removes the specified item listener. + * Returns silently if the specified listener is not added before. + * + * @param registrationId Id of listener registration. + * + * @return true if registration is removed, false otherwise + */ + bool removeItemListener(const std::string ®istrationId) { + return queue.removeItemListener(registrationId); + } + + /** + * Inserts the specified element into this queue. + * + * @param element to add + * @return true if the element was added to this queue, else + * false + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool offer(const T &element) { + return queue.offer(element, 0); + } + + /** + * Puts the element into queue. + * If queue is full waits for space to became available. + */ + void put(const T &e) { + queue.offer(e, -1); + } + + /** + * Inserts the specified element into this queue. + * If queue is full waits for space to became available for specified time. + * + * @param element to add + * @param timeoutInMillis how long to wait before giving up, in units of + * @return true if successful, or false if + * the specified waiting time elapses before space is available + */ + bool offer(const T &element, long timeoutInMillis) { + return queue.offer(element, timeoutInMillis); + } + + /** + * + * @return the head of the queue. If queue is empty waits for an item to be added. + */ + std::auto_ptr take() { + return serializationService.toObject(queue.pollData(-1).get()); + } + + /** + * + * @param timeoutInMillis time to wait if item is not available. + * @return the head of the queue. If queue is empty waits for specified time. + */ + std::auto_ptr poll(long timeoutInMillis) { + return serializationService.toObject(queue.pollData(timeoutInMillis).get()); + } + + /** + * + * @return remaining capacity + */ + int remainingCapacity() { + return queue.remainingCapacity(); + } + + /** + * + * @param element to be removed. + * @return true if element removed successfully. + */ + bool remove(const T &element) { + return queue.remove(element); + } + + /** + * + * @param element to be checked. + * @return true if queue contains the element. + */ + bool contains(const T &element) { + return queue.contains(element); + } + + /** + * + * @return The elements in the queue. + */ + std::auto_ptr > drainTo() { + return std::auto_ptr >(new DataArray(queue.drainToData(-1), serializationService)); + } + + /** + * + * @param maxElements upper limit to be filled. + * @return The elements in the queue. + */ + std::auto_ptr > drainTo(size_t maxElements) { + return std::auto_ptr >(new DataArray(queue.drainToData(maxElements), serializationService)); + } + + /** + * Returns immediately without waiting. + * + * @return removes head of the queue and returns it to user . If not available returns empty constructed shared_ptr. + */ + std::auto_ptr poll() { + return serializationService.toObject(queue.pollData(0).get()); + } + + /** + * Returns immediately without waiting. + * + * @return head of queue without removing it. If not available returns empty constructed shared_ptr. + */ + std::auto_ptr peek() { + return serializationService.toObject(queue.peekData().get()); + } + + /** + * + * @return size of this distributed queue + */ + int size() { + return queue.size(); + } + + /** + * + * @return true if queue is empty + */ + bool isEmpty() { + return queue.isEmpty(); + } + + /** + * + * @returns all elements + */ + std::auto_ptr > toArray() { + return std::auto_ptr >(new DataArray(queue.toArrayData(), serializationService)); + } + + /** + * + * @param elements The items to be searched for in the queue. + * @return true if this queue contains all item given in elements. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool containsAll(const std::vector &elements) { + return queue.containsAll(elements); + } + + /** + * + * @param elements he items to be inserted into the queue. + * @return true if all elements given in vector can be added to queue. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool addAll(const std::vector &elements) { + return queue.addAll(elements); + } + + /** + * + * @param elements The items to be removed from the queue + * @return true if all elements are removed successfully. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool removeAll(const std::vector &elements) { + return queue.removeAll(elements); + } + + /** + * + * Removes the elements from this queue that are not available in given "elements" vector + * @param elements The items to be retained in the queue + * @return true if operation is successful. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool retainAll(const std::vector &elements) { + return queue.retainAll(elements); + } + + /** + * Removes all elements from queue. + */ + void clear() { + queue.clear(); + } + + private: + IQueue &queue; + serialization::pimpl::SerializationService &serializationService; + }; + } + + } +} + +#endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERQUEUE_H_ */ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerSet.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerSet.h new file mode 100644 index 0000000000..2d2d036e08 --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerSet.h @@ -0,0 +1,174 @@ +/* + * 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. + */ +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERSET_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERSET_H_ + +#include "hazelcast/client/ISet.h" +#include "hazelcast/client/adaptor/DataArray.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * Concurrent, distributed client implementation of std::unordered_set. + * + * @tparam T item type + */ + template + class RawPointerSet { + public: + RawPointerSet(ISet &s) : set(s), serializationService(s.context->getSerializationService()) { + } + + /** + * Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. + * otherwise it will slow down the system. + * + * Warning 2: Do not make a call to hazelcast. It can cause deadlock. + * + * @param listener to be added + * @param includeValue boolean value representing value should be included in incoming ItemEvent or not. + * @returns registrationId that can be used to remove item listener + */ + std::string addItemListener(ItemListener &listener, bool includeValue) { + return set.addItemListener(listener, includeValue); + } + + /** + * Removes the specified item listener. + * Returns false if the specified listener is not added before. + * + * @param registrationId Id of listener registration. + * + * @return true if registration is removed, false otherwise + */ + bool removeItemListener(const std::string ®istrationId) { + return set.removeItemListener(registrationId); + } + + /** + * + * @returns size of the distributed set + */ + int size() { + return set.size(); + } + + /** + * + * @returns true if empty + */ + bool isEmpty() { + return set.isEmpty(); + } + + /** + * + * @param element to be searched + * @returns true if set contains element + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool contains(const T &element) { + return set.contains(element); + } + + /** + * + * @returns all elements as std::vector + */ + std::auto_ptr > toArray() { + return std::auto_ptr >(new DataArray(set.toArrayData(), serializationService)); + } + + /** + * + * @param element to be added + * @return true if element is added successfully. If elements was already there returns false. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool add(const T &element) { + return set.add(element); + } + + /** + * + * @param element to be removed + * @return true if element is removed successfully. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool remove(const T &element) { + return set.remove(element); + } + + /** + * + * @param elements std::vector + * @return true if this set contains all elements given in vector. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool containsAll(const std::vector &elements) { + return set.containsAll(elements); + } + + /** + * + * @param elements std::vector + * @return true if all elements given in vector can be added to set. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool addAll(const std::vector &elements) { + return set.addAll(elements); + } + + /** + * + * @param elements std::vector + * @return true if all elements are removed successfully. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool removeAll(const std::vector &elements) { + return set.removeAll(elements); + } + + /** + * + * Removes the elements from this set that are not available in given "elements" vector + * @param elements std::vector + * @return true if operation is successful. + * @throws IClassCastException if the type of the specified element is incompatible with the server side. + */ + bool retainAll(const std::vector &elements) { + return set.retainAll(elements); + } + + /** + * + * Removes all elements from set. + */ + void clear() { + set.clear(); + } + + private: + ISet &set; + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + +#endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERSET_H_ */ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalMap.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalMap.h new file mode 100644 index 0000000000..225d6f2721 --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalMap.h @@ -0,0 +1,220 @@ +/* + * 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 ihsan demir on 24/03/16. +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERRawPointerTransactionalMap_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERRawPointerTransactionalMap_H_ + +#include "hazelcast/client/TransactionalMap.h" +#include "hazelcast/client/adaptor/DataArray.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * Transactional implementation of IMap. + * + * @see IMap + * @param key + * @param value + */ + template + class RawPointerTransactionalMap { + public: + RawPointerTransactionalMap(TransactionalMap &m) : map(m), serializationService( + m.context->getSerializationService()) { + } + + /** + * Transactional implementation of IMap#containsKey(Object). + * + * @see IMap#containsKey(key) + */ + bool containsKey(const K &key) { + return map.containsKey(key); + } + + /** + * Transactional implementation of IMap#get(Object). + * + * @see IMap#get(key) + */ + std::auto_ptr get(const K &key) { + return serializationService.toObject(map.getData(serializationService.toData(&key)).get()); + } + + /** + * Transactional implementation of IMap#size(). + * + * @see IMap#size() + */ + int size() { + return map.size(); + } + + /** + * Transactional implementation of IMap#isEmpty(). + * + * @see IMap#isEmpty() + */ + bool isEmpty() { + return map.isEmpty(); + } + + /** + * Transactional implementation of IMap#put(Object, Object). + * + * The object to be put will be accessible only in the current transaction context till transaction is committed. + * + * @see IMap#put(key, value) + */ + std::auto_ptr put(const K &key, const V &value) { + return serializationService.toObject(map.putData(serializationService.toData(&key), + serializationService.toData(&value)).get()); + }; + + /** + * Transactional implementation of IMap#set(key, value). + * + * The object to be set will be accessible only in the current transaction context till transaction is committed. + * + * @see IMap#set(key, value) + */ + void set(const K &key, const V &value) { + map.set(key, value); + } + + /** + * Transactional implementation of IMap#putIfAbsent(key, value) + * + * The object to be put will be accessible only in the current transaction context till transaction is committed. + * + * @see IMap#putIfAbsent(key, value) + */ + std::auto_ptr putIfAbsent(const K &key, const V &value) { + return serializationService.toObject(map.putIfAbsentData(serializationService.toData(&key), + serializationService.toData( + &value)).get()); + }; + + /** + * Transactional implementation of IMap#replace(key, value). + * + * The object to be replaced will be accessible only in the current transaction context till transaction is committed. + * + * @see IMap#replace(key, value) + */ + std::auto_ptr replace(const K &key, const V &value) { + return serializationService.toObject(map.replaceData(serializationService.toData(&key), + serializationService.toData( + &value)).get()); + }; + + /** + * Transactional implementation of IMap#replace(key, value, oldValue). + * + * The object to be replaced will be accessible only in the current transaction context till transaction is committed. + * + * @see IMap#replace(key, value, oldValue) + */ + bool replace(const K &key, const V &oldValue, const V &newValue) { + return map.replace(key, oldValue, newValue); + }; + + /** + * Transactional implementation of IMap#remove(key). + * + * The object to be removed will be removed from only the current transaction context till transaction is committed. + * + * @see IMap#remove(key) + */ + std::auto_ptr remove(const K &key) { + return serializationService.toObject(map.removeData(serializationService.toData(&key)).get()); + }; + + /** + * Transactional implementation of IMap#delete(key). + * + * The object to be deleted will be removed from only the current transaction context till transaction is committed. + * + * @see IMap#delete(keu) + */ + + void deleteEntry(const K &key) { + map.deleteEntry(key); + }; + + /** + * Transactional implementation of IMap#remove(key, value). + * + * The object to be removed will be removed from only the current transaction context till transaction is committed. + * + * @see IMap#remove(key, value) + */ + bool remove(const K &key, const V &value) { + return map.remove(key, value); + } + + /** + * Transactional implementation of IMap#keySet(). + * + * + * @see IMap#keySet() + */ + std::auto_ptr > keySet() { + return std::auto_ptr >(new DataArray(map.keySetData(), serializationService)); + } + + /** + * Transactional implementation of IMap#keySet(Predicate) . + * + * + * @see IMap#keySet(predicate) + */ + std::auto_ptr > keySet(const serialization::IdentifiedDataSerializable *predicate) { + return std::auto_ptr >(new DataArray(map.keySetData(predicate), serializationService)); + } + + /** + * Transactional implementation of IMap#values(). + * + * + * @see IMap#values() + */ + std::auto_ptr > values() { + return std::auto_ptr >(new DataArray(map.valuesData(), serializationService)); + } + + /** + * Transactional implementation of IMap#values(Predicate) . + * + * @see IMap#values(Predicate) + */ + std::auto_ptr > values(const serialization::IdentifiedDataSerializable *predicate) { + return std::auto_ptr >(new DataArray(map.valuesData(predicate), serializationService)); + } + + private: + TransactionalMap ↦ + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + + +#endif //HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERRawPointerTransactionalMap_H_ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalMultiMap.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalMultiMap.h new file mode 100644 index 0000000000..66f1baa44a --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalMultiMap.h @@ -0,0 +1,107 @@ +/* + * 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 ihsan demir on 24/3/16. + +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERTRANSACTIONALMULTIMAP_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERTRANSACTIONALMULTIMAP_H_ + +#include "hazelcast/client/TransactionalMultiMap.h" +#include "hazelcast/client/adaptor/DataArray.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * + * Transactional implementation of MultiMap. + * + * @see MultiMap + * @param key + * @param value + */ + template + class RawPointerTransactionalMultiMap { + public: + RawPointerTransactionalMultiMap(TransactionalMultiMap &m) : map(m), serializationService( + m.context->getSerializationService()) { + } + + /** + * Transactional implementation of Multimap#put(key , value). + * + * @see Multimap#put(key , value) + */ + bool put(const K &key, const V &value) { + return map.put(key, value); + }; + + /** + * Transactional implementation of Multimap#get(key). + * + * @see Multimap#get(key) + */ + std::auto_ptr > get(const K &key) { + return std::auto_ptr >(new DataArray(map.getData(serializationService.toData(&key)), serializationService)); + }; + + /** + * Transactional implementation of Multimap#remove(key , value). + * + * @see Multimap#remove(key , value) + */ + bool remove(const K &key, const V &value) { + return map.remove(key, value); + }; + + /** + * Transactional implementation of Multimap#remove(key). + * + * @see Multimap#remove(key) + */ + std::auto_ptr > remove(const K &key) { + return std::auto_ptr >(new DataArray(map.removeData(serializationService.toData(&key)), serializationService)); + }; + + + /** + * Transactional implementation of Multimap#valueCount(key). + * + * @see Multimap#valueCount(key) + */ + int valueCount(const K &key) { + return map.valueCount(key); + } + + /** + * Transactional implementation of Multimap#size(). + * + * @see Multimap#size() + */ + int size() { + return map.size(); + } + + private : + TransactionalMultiMap ↦ + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + +#endif //HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERTRANSACTIONALMULTIMAP_H_ + diff --git a/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalQueue.h b/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalQueue.h new file mode 100644 index 0000000000..155b7c7743 --- /dev/null +++ b/hazelcast/include/hazelcast/client/adaptor/RawPointerTransactionalQueue.h @@ -0,0 +1,94 @@ +/* + * 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 ihsan demir on 24/3/16. + +#ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERTRANSACTIONALQUEUE_H_ +#define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERTRANSACTIONALQUEUE_H_ + +#include "hazelcast/client/TransactionalQueue.h" + +namespace hazelcast { + namespace client { + namespace adaptor { + /** + * Transactional implementation of IQueue. + * + * @see IQueue + * @param element type + */ + template + class RawPointerTransactionalQueue { + public: + RawPointerTransactionalQueue(TransactionalQueue &q) : queue(q), serializationService( + q.context->getSerializationService()) { + } + + /** + * Transactional implementation of IQueue::offer(const T &e) + * + * @see IQueue::offer(const T &e) + */ + bool offer(const T &e) { + return queue.offer(e); + } + + /** + * Transactional implementation of IQueue::offer(const T &e, long timeoutInMillis) + * + * @see IQueue::offer(const T &e, long timeoutInMillis) + */ + bool offer(const T &e, long timeoutInMillis) { + return queue.offer(e, timeoutInMillis); + } + + /** + * Transactional implementation of IQueue::poll() + * + * @see IQueue::poll() + */ + std::auto_ptr poll() { + return poll(0); + } + + /** + * Transactional implementation of IQueue::poll(long timeoutInMillis) + * + * @see IQueue::poll(long timeoutInMillis) + */ + std::auto_ptr poll(long timeoutInMillis) { + return serializationService.toObject(queue.pollData(timeoutInMillis).get()); + } + + /** + * Transactional implementation of IQueue::size() + * + * @see IQueue::size() + */ + int size() { + return queue.size(); + } + + private: + TransactionalQueue &queue; + serialization::pimpl::SerializationService &serializationService; + }; + } + } +} + +#endif //HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERTRANSACTIONALQUEUE_H_ + diff --git a/hazelcast/include/hazelcast/client/proxy/IListImpl.h b/hazelcast/include/hazelcast/client/proxy/IListImpl.h index 68e1c95c2e..1dd8aef7c5 100644 --- a/hazelcast/include/hazelcast/client/proxy/IListImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/IListImpl.h @@ -39,7 +39,7 @@ namespace hazelcast { bool contains(const serialization::pimpl::Data& element); - std::vector toArray(); + std::vector toArrayData(); bool add(const serialization::pimpl::Data& element); @@ -57,19 +57,19 @@ namespace hazelcast { void clear(); - std::auto_ptr get(int index); + std::auto_ptr getData(int index); - std::auto_ptr set(int index, const serialization::pimpl::Data& element); + std::auto_ptr setData(int index, const serialization::pimpl::Data& element); void add(int index, const serialization::pimpl::Data& element); - std::auto_ptr remove(int index); + std::auto_ptr removeData(int index); int indexOf(const serialization::pimpl::Data& element); int lastIndexOf(const serialization::pimpl::Data& element); - std::vector subList(int fromIndex, int toIndex); + std::vector subListData(int fromIndex, int toIndex); private: int partitionId; diff --git a/hazelcast/include/hazelcast/client/proxy/IMapImpl.h b/hazelcast/include/hazelcast/client/proxy/IMapImpl.h index d71a1b5ca2..c6726d2f48 100644 --- a/hazelcast/include/hazelcast/client/proxy/IMapImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/IMapImpl.h @@ -36,11 +36,11 @@ namespace hazelcast { bool containsValue(const serialization::pimpl::Data& value); - std::auto_ptr get(const serialization::pimpl::Data& key); + std::auto_ptr getData(const serialization::pimpl::Data& key); - std::auto_ptr put(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); + std::auto_ptr putData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::auto_ptr remove(const serialization::pimpl::Data& key); + std::auto_ptr removeData(const serialization::pimpl::Data& key); bool remove(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); @@ -52,15 +52,15 @@ namespace hazelcast { bool tryPut(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value, long timeoutInMillis); - std::auto_ptr put(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value, long ttlInMillis); + std::auto_ptr putData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value, long ttlInMillis); void putTransient(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value, long ttlInMillis); - std::auto_ptr putIfAbsent(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value, long ttlInMillis); + std::auto_ptr putIfAbsentData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value, long ttlInMillis); bool replace(const serialization::pimpl::Data& key, const serialization::pimpl::Data& oldValue, const serialization::pimpl::Data& newValue); - std::auto_ptr replace(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); + std::auto_ptr replaceData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); void set(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value, long ttl); @@ -88,25 +88,27 @@ namespace hazelcast { std::string addEntryListener(impl::BaseEventHandler *entryEventHandler, const serialization::pimpl::Data& key, bool includeValue); - std::auto_ptr getEntryView(const serialization::pimpl::Data& key); + std::auto_ptr getEntryViewData(const serialization::pimpl::Data& key); bool evict(const serialization::pimpl::Data& key); void evictAll(); - EntryVector getAll(const std::vector& keys); + EntryVector getAllData(const std::vector& keys); - std::vector keySet(); + std::vector keySetData(); - std::vector keySet(const serialization::IdentifiedDataSerializable &predicate); + std::vector keySetData( + const serialization::IdentifiedDataSerializable &predicate); - EntryVector entrySet(); + EntryVector entrySetData(); - EntryVector entrySet(const serialization::IdentifiedDataSerializable &predicate); + EntryVector entrySetData(const serialization::IdentifiedDataSerializable &predicate); - std::vector values(); + std::vector valuesData(); - std::vector values(const serialization::IdentifiedDataSerializable &predicate); + std::vector valuesData( + const serialization::IdentifiedDataSerializable &predicate); void addIndex(const std::string& attribute, bool ordered); @@ -118,21 +120,19 @@ namespace hazelcast { void clear(); - template - boost::shared_ptr executeOnKey(const KEY& key, ENTRYPROCESSOR &entryProcessor) { + template + std::auto_ptr executeOnKeyData(const KEY& key, ENTRYPROCESSOR &entryProcessor) { serialization::pimpl::Data keyData = toData(key); serialization::pimpl::Data processor = toData(entryProcessor); int partitionId = getPartitionId(keyData); std::auto_ptr request = protocol::codec::MapExecuteOnKeyCodec::RequestParameters::encode(getName(), processor, keyData, util::getThreadId()); - std::auto_ptr response = invokeAndGetResult, protocol::codec::MapExecuteOnKeyCodec::ResponseParameters>(request, partitionId); - - return toObject(response); + return invokeAndGetResult, protocol::codec::MapExecuteOnKeyCodec::ResponseParameters>(request, partitionId); } - template - std::map > executeOnEntries(ENTRYPROCESSOR &entryProcessor) { + template + EntryVector executeOnEntriesData(ENTRYPROCESSOR &entryProcessor) { serialization::pimpl::Data processor = toData(entryProcessor); std::auto_ptr request = protocol::codec::MapExecuteOnAllKeysCodec::RequestParameters::encode(getName(), processor); @@ -141,15 +141,7 @@ namespace hazelcast { invokeAndGetResult >, protocol::codec::MapExecuteOnAllKeysCodec::ResponseParameters>(request); - std::map > results; - for (std::vector >::const_iterator it = response.begin(); - response.end() != it; ++it) { - KEY key = *toObject(it->first); - boost::shared_ptr value = toObject(it->second); - results[key] = value; - } - - return results; + return response; } }; } diff --git a/hazelcast/include/hazelcast/client/proxy/IQueueImpl.h b/hazelcast/include/hazelcast/client/proxy/IQueueImpl.h index 5b61158339..b07b85c3b6 100644 --- a/hazelcast/include/hazelcast/client/proxy/IQueueImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/IQueueImpl.h @@ -38,7 +38,7 @@ namespace hazelcast { bool offer(const serialization::pimpl::Data& element, long timeoutInMillis); - std::auto_ptr poll(long timeoutInMillis); + std::auto_ptr pollData(long timeoutInMillis); int remainingCapacity(); @@ -46,13 +46,13 @@ namespace hazelcast { bool contains(const serialization::pimpl::Data& element); - std::vector drainTo(size_t maxElements); + std::vector drainToData(size_t maxElements); - std::auto_ptr peek(); + std::auto_ptr peekData(); int size(); - std::vector toArray(); + std::vector toArrayData(); bool containsAll(const std::vector& elements); diff --git a/hazelcast/include/hazelcast/client/proxy/ISetImpl.h b/hazelcast/include/hazelcast/client/proxy/ISetImpl.h index 5634135978..a1f1d2dd62 100644 --- a/hazelcast/include/hazelcast/client/proxy/ISetImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/ISetImpl.h @@ -39,7 +39,7 @@ namespace hazelcast { bool contains(const serialization::pimpl::Data& element); - std::vector toArray(); + std::vector toArrayData(); bool add(const serialization::pimpl::Data& element); diff --git a/hazelcast/include/hazelcast/client/proxy/MultiMapImpl.h b/hazelcast/include/hazelcast/client/proxy/MultiMapImpl.h index 5946d9f151..ec4197bed0 100644 --- a/hazelcast/include/hazelcast/client/proxy/MultiMapImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/MultiMapImpl.h @@ -29,17 +29,17 @@ namespace hazelcast { bool put(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::vector get(const serialization::pimpl::Data& key); + std::vector getData(const serialization::pimpl::Data &key); bool remove(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::vector remove(const serialization::pimpl::Data& key); + std::vector removeData(const serialization::pimpl::Data& key); - std::vector keySet(); + std::vector keySetData(); - std::vector values(); + std::vector valuesData(); - std::vector > entrySet(); + std::vector > entrySetData(); bool containsKey(const serialization::pimpl::Data& key); diff --git a/hazelcast/include/hazelcast/client/proxy/ProxyImpl.h b/hazelcast/include/hazelcast/client/proxy/ProxyImpl.h index b2762e203c..ab4a581161 100644 --- a/hazelcast/include/hazelcast/client/proxy/ProxyImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/ProxyImpl.h @@ -31,19 +31,12 @@ namespace hazelcast { namespace client { - namespace map { - class DataEntryView; - } namespace connection { class Connection; } namespace impl { class BaseEventHandler; - - class BaseRemoveListenerRequest; - - class ClientRequest; } namespace serialization { @@ -79,7 +72,7 @@ namespace hazelcast { * memory ownership is moved to DistributedObject. * * @param partitionId that given request will be send to. - * @param request ClientRequest ptr. + * @param request Client request message to be sent. */ std::auto_ptr invoke(std::auto_ptr request, int partitionId); @@ -102,7 +95,7 @@ namespace hazelcast { /** * Internal API. * - * @param registrationRequest ClientRequest ptr. + * @param registrationRequest ClientMessage ptr. * @param partitionId * @param handler */ @@ -112,8 +105,8 @@ namespace hazelcast { /** * Internal API. * - * @param registrationRequest ClientRequest ptr. - * @param handler + * @param addListenerCodec Codec for encoding the listener addition request and the response. + * @param handler The handler to use when the event arrives. */ std::string registerListener(std::auto_ptr addListenerCodec, impl::BaseEventHandler *handler); @@ -130,14 +123,14 @@ namespace hazelcast { } template - boost::shared_ptr toObject(const serialization::pimpl::Data &data) { + std::auto_ptr toObject(const serialization::pimpl::Data &data) { return context->getSerializationService().template toObject(data); } template - boost::shared_ptr toObject(std::auto_ptr data) { + std::auto_ptr toObject(std::auto_ptr data) { if (NULL == data.get()) { - return boost::shared_ptr(); + return std::auto_ptr(); } else { return toObject(*data); } @@ -146,12 +139,12 @@ namespace hazelcast { template std::vector toObjectCollection(const std::vector &collection) { size_t size = collection.size(); - std::vector multimap(size); + std::vector objectArray(size); for (size_t i = 0; i < size; i++) { - boost::shared_ptr v = toObject(collection[i]); - multimap[i] = *v; + std::auto_ptr v = toObject(collection[i]); + objectArray[i] = *v; } - return multimap; + return objectArray; } template @@ -170,24 +163,23 @@ namespace hazelcast { size_t size = dataEntrySet.size(); std::vector > entrySet(size); for (size_t i = 0; i < size; i++) { - boost::shared_ptr key = toObject(dataEntrySet[i].first); + std::auto_ptr key = toObject(dataEntrySet[i].first); entrySet[i].first = *key; - boost::shared_ptr value = toObject(dataEntrySet[i].second); + std::auto_ptr value = toObject(dataEntrySet[i].second); entrySet[i].second = *value; } return entrySet; } template - EntryVector toDataEntriesSet(std::map const &m) { - std::vector > entryDataSet( + EntryVector toDataEntries(std::map const &m) { + std::vector > entries( m.size()); - typename std::map::const_iterator it; int i = 0; - for (it = m.begin(); it != m.end(); ++it) { - entryDataSet[i++] = std::make_pair(toData(it->first), toData(it->second)); + for (typename std::map::const_iterator it = m.begin(); it != m.end(); ++it) { + entries[i++] = std::make_pair(toData(it->first), toData(it->second)); } - return entryDataSet; + return entries; } template diff --git a/hazelcast/include/hazelcast/client/proxy/TransactionalMapImpl.h b/hazelcast/include/hazelcast/client/proxy/TransactionalMapImpl.h index e143ba93e5..390f705664 100644 --- a/hazelcast/include/hazelcast/client/proxy/TransactionalMapImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/TransactionalMapImpl.h @@ -32,33 +32,33 @@ namespace hazelcast { bool containsKey(const serialization::pimpl::Data& key); - std::auto_ptr get(const serialization::pimpl::Data& key); + std::auto_ptr getData(const serialization::pimpl::Data& key); int size(); - std::auto_ptr put(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); + std::auto_ptr putData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); void set(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::auto_ptr putIfAbsent(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); + std::auto_ptr putIfAbsentData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::auto_ptr replace(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); + std::auto_ptr replaceData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); bool replace(const serialization::pimpl::Data& key, const serialization::pimpl::Data& oldValue, const serialization::pimpl::Data& newValue); - std::auto_ptr remove(const serialization::pimpl::Data& key); + std::auto_ptr removeData(const serialization::pimpl::Data& key); void deleteEntry(const serialization::pimpl::Data& key); bool remove(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::vector keySet(); + std::vector keySetData(); - std::vector keySet(const serialization::IdentifiedDataSerializable *predicate); + std::vector keySetData(const serialization::IdentifiedDataSerializable *predicate); - std::vector values(); + std::vector valuesData(); - std::vector values(const serialization::IdentifiedDataSerializable *predicate); + std::vector valuesData(const serialization::IdentifiedDataSerializable *predicate); TransactionalMapImpl(const std::string& name, txn::TransactionProxy *transactionProxy); }; diff --git a/hazelcast/include/hazelcast/client/proxy/TransactionalMultiMapImpl.h b/hazelcast/include/hazelcast/client/proxy/TransactionalMultiMapImpl.h index ca7a1fcd01..372e1a523f 100644 --- a/hazelcast/include/hazelcast/client/proxy/TransactionalMultiMapImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/TransactionalMultiMapImpl.h @@ -37,11 +37,11 @@ namespace hazelcast { bool put(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::vector get(const serialization::pimpl::Data& key); + std::vector getData(const serialization::pimpl::Data& key); bool remove(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value); - std::vector remove(const serialization::pimpl::Data& key); + std::vector removeData(const serialization::pimpl::Data& key); int valueCount(const serialization::pimpl::Data& key); diff --git a/hazelcast/include/hazelcast/client/proxy/TransactionalObject.h b/hazelcast/include/hazelcast/client/proxy/TransactionalObject.h index 6776da22c5..c955c059b5 100644 --- a/hazelcast/include/hazelcast/client/proxy/TransactionalObject.h +++ b/hazelcast/include/hazelcast/client/proxy/TransactionalObject.h @@ -15,10 +15,6 @@ */ // // Created by sancar koyunlu on 12/11/13. - - - - #ifndef HAZELCAST_TransactionalObject #define HAZELCAST_TransactionalObject @@ -72,17 +68,17 @@ namespace hazelcast { } template - boost::shared_ptr toObject(const serialization::pimpl::Data& data) { + std::auto_ptr toObject(const serialization::pimpl::Data& data) { return context->getSerializationService().template toObject(data); } template - boost::shared_ptr toObject(const serialization::pimpl::Data *data) { + std::auto_ptr toObject(const serialization::pimpl::Data *data) { return context->getSerializationService().template toObject(data); } template - boost::shared_ptr toObject(std::auto_ptr data) { + std::auto_ptr toObject(std::auto_ptr data) { return context->getSerializationService().template toObject(data.get()); } @@ -91,7 +87,7 @@ namespace hazelcast { size_t size = keyDataSet.size(); std::vector keys(size); for (size_t i = 0; i < size; i++) { - boost::shared_ptr v = toObject(keyDataSet[i]); + boost::shared_ptr v(toObject(keyDataSet[i])); keys[i] = *v; } return keys; @@ -109,7 +105,7 @@ namespace hazelcast { return CODEC::decode(*response).response; } - private: + const std::string serviceName; const std::string name; txn::TransactionProxy *context; diff --git a/hazelcast/include/hazelcast/client/proxy/TransactionalQueueImpl.h b/hazelcast/include/hazelcast/client/proxy/TransactionalQueueImpl.h index 5e588bd3b3..24894f6d15 100644 --- a/hazelcast/include/hazelcast/client/proxy/TransactionalQueueImpl.h +++ b/hazelcast/include/hazelcast/client/proxy/TransactionalQueueImpl.h @@ -16,8 +16,6 @@ // // Created by sancar koyunlu on 01/10/14. // - - #ifndef HAZELCAST_TransactionalQueueProxy #define HAZELCAST_TransactionalQueueProxy @@ -32,7 +30,7 @@ namespace hazelcast { bool offer(const serialization::pimpl::Data& e, long timeoutInMillis); - std::auto_ptr poll(long timeoutInMillis); + std::auto_ptr pollData(long timeoutInMillis); int size(); }; diff --git a/hazelcast/include/hazelcast/client/serialization/ObjectDataInput.h b/hazelcast/include/hazelcast/client/serialization/ObjectDataInput.h index f0eeed56c7..df2fe439b3 100644 --- a/hazelcast/include/hazelcast/client/serialization/ObjectDataInput.h +++ b/hazelcast/include/hazelcast/client/serialization/ObjectDataInput.h @@ -195,11 +195,11 @@ namespace hazelcast { * @throws IOException if it reaches end of file before finish reading */ template - boost::shared_ptr readObject() { + std::auto_ptr readObject() { int typeId = readInt(); const pimpl::SerializationConstants& constants = portableContext.getConstants(); if (constants.CONSTANT_TYPE_NULL == typeId) { - return boost::shared_ptr(static_cast(NULL)); + return std::auto_ptr(); } else { std::auto_ptr result(new T); constants.checkClassType(getHazelcastTypeId(result.get()) , typeId); @@ -210,7 +210,7 @@ namespace hazelcast { } else { readInternal(typeId, result.get()); } - return boost::shared_ptr(result.release()); + return std::auto_ptr(result.release()); } } diff --git a/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationService.h b/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationService.h index 1342ceb01c..96445c42a3 100644 --- a/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationService.h +++ b/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationService.h @@ -80,17 +80,17 @@ namespace hazelcast { } template - inline boost::shared_ptr toObject(const Data *data) { + inline std::auto_ptr toObject(const Data *data) { if (NULL == data) { - return boost::shared_ptr(); + return std::auto_ptr(); } return toObject(*data); } template - inline boost::shared_ptr toObject(const Data &data) { + inline std::auto_ptr toObject(const Data &data) { if (isNullData(data)) { - return boost::shared_ptr(); + return std::auto_ptr(); } // Constant 4 is Data::TYPE_OFFSET. Windows DLL export does not @@ -171,54 +171,54 @@ namespace hazelcast { HAZELCAST_API Data SerializationService::toData >(const std::vector *object); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data) ; + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data) ; template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr > SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr > SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr > SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr > SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr > SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr< std::vector > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr< std::vector > SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr > SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr SerializationService::toObject(const Data &data); template<> - HAZELCAST_API boost::shared_ptr > SerializationService::toObject(const Data &data); + HAZELCAST_API std::auto_ptr > SerializationService::toObject(const Data &data); } } } diff --git a/hazelcast/include/hazelcast/client/topic/TopicEventHandler.h b/hazelcast/include/hazelcast/client/topic/TopicEventHandler.h index b4e5d45591..da2e14c8f3 100644 --- a/hazelcast/include/hazelcast/client/topic/TopicEventHandler.h +++ b/hazelcast/include/hazelcast/client/topic/TopicEventHandler.h @@ -53,7 +53,7 @@ namespace hazelcast { const std::string &uuid) { std::auto_ptr member(clusterService.getMember(uuid)); - boost::shared_ptr object = serializationService.toObject(item); + std::auto_ptr object = serializationService.toObject(item); Message listenerMsg(instanceName, *object, (long)publishTime, *member); diff --git a/hazelcast/src/hazelcast/client/proxy/IListImpl.cpp b/hazelcast/src/hazelcast/client/proxy/IListImpl.cpp index 89b4990130..bf6041a84a 100644 --- a/hazelcast/src/hazelcast/client/proxy/IListImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/IListImpl.cpp @@ -91,7 +91,7 @@ namespace hazelcast { partitionId); } - std::vector IListImpl::toArray() { + std::vector IListImpl::toArrayData() { std::auto_ptr request = protocol::codec::ListGetAllCodec::RequestParameters::encode(getName()); @@ -163,7 +163,7 @@ namespace hazelcast { invoke(request, partitionId); } - std::auto_ptr IListImpl::get(int index) { + std::auto_ptr IListImpl::getData(int index) { std::auto_ptr request = protocol::codec::ListGetCodec::RequestParameters::encode(getName(), index); @@ -171,7 +171,7 @@ namespace hazelcast { request, partitionId); } - std::auto_ptr IListImpl::set(int index, + std::auto_ptr IListImpl::setData(int index, const serialization::pimpl::Data &element) { std::auto_ptr request = protocol::codec::ListSetCodec::RequestParameters::encode(getName(), index, element); @@ -187,7 +187,7 @@ namespace hazelcast { invoke(request, partitionId); } - std::auto_ptr IListImpl::remove(int index) { + std::auto_ptr IListImpl::removeData(int index) { std::auto_ptr request = protocol::codec::ListRemoveWithIndexCodec::RequestParameters::encode(getName(), index); @@ -211,7 +211,7 @@ namespace hazelcast { partitionId); } - std::vector IListImpl::subList(int fromIndex, int toIndex) { + std::vector IListImpl::subListData(int fromIndex, int toIndex) { std::auto_ptr request = protocol::codec::ListSubCodec::RequestParameters::encode(getName(), fromIndex, toIndex); diff --git a/hazelcast/src/hazelcast/client/proxy/IMapImpl.cpp b/hazelcast/src/hazelcast/client/proxy/IMapImpl.cpp index 7f7fe75d3f..a74c4448f6 100644 --- a/hazelcast/src/hazelcast/client/proxy/IMapImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/IMapImpl.cpp @@ -105,7 +105,7 @@ namespace hazelcast { return invokeAndGetResult(request); } - std::auto_ptr IMapImpl::get(const serialization::pimpl::Data &key) { + std::auto_ptr IMapImpl::getData(const serialization::pimpl::Data &key) { int partitionId = getPartitionId(key); std::auto_ptr request = @@ -115,7 +115,7 @@ namespace hazelcast { request, partitionId); } - std::auto_ptr IMapImpl::put(const serialization::pimpl::Data &key, + std::auto_ptr IMapImpl::putData(const serialization::pimpl::Data &key, const serialization::pimpl::Data &value) { int partitionId = getPartitionId(key); @@ -127,7 +127,7 @@ namespace hazelcast { request, partitionId); } - std::auto_ptr IMapImpl::remove(const serialization::pimpl::Data &key) { + std::auto_ptr IMapImpl::removeData(const serialization::pimpl::Data &key) { int partitionId = getPartitionId(key); std::auto_ptr request = protocol::codec::MapRemoveCodec::RequestParameters::encode(getName(), key, util::getThreadId()); @@ -188,7 +188,7 @@ namespace hazelcast { partitionId); } - std::auto_ptr IMapImpl::put(const serialization::pimpl::Data &key, + std::auto_ptr IMapImpl::putData(const serialization::pimpl::Data &key, const serialization::pimpl::Data &value, long ttlInMillis) { int partitionId = getPartitionId(key); @@ -214,7 +214,7 @@ namespace hazelcast { invoke(request, partitionId); } - std::auto_ptr IMapImpl::putIfAbsent(const serialization::pimpl::Data &key, + std::auto_ptr IMapImpl::putIfAbsentData(const serialization::pimpl::Data &key, const serialization::pimpl::Data &value, long ttlInMillis) { int partitionId = getPartitionId(key); @@ -241,7 +241,7 @@ namespace hazelcast { partitionId); } - std::auto_ptr IMapImpl::replace(const serialization::pimpl::Data &key, + std::auto_ptr IMapImpl::replaceData(const serialization::pimpl::Data &key, const serialization::pimpl::Data &value) { int partitionId = getPartitionId(key); @@ -351,7 +351,7 @@ namespace hazelcast { return registerListener(codec, partitionId, handler); } - std::auto_ptr IMapImpl::getEntryView(const serialization::pimpl::Data &key) { + std::auto_ptr IMapImpl::getEntryViewData(const serialization::pimpl::Data &key) { int partitionId = getPartitionId(key); std::auto_ptr request = @@ -379,7 +379,7 @@ namespace hazelcast { invoke(request); } - EntryVector IMapImpl::getAll( + EntryVector IMapImpl::getAllData( const std::vector &keys) { std::map > partitionedKeys; @@ -416,7 +416,7 @@ namespace hazelcast { return result; } - std::vector IMapImpl::keySet() { + std::vector IMapImpl::keySetData() { std::auto_ptr request = protocol::codec::MapKeySetCodec::RequestParameters::encode(getName()); @@ -424,7 +424,7 @@ namespace hazelcast { request); } - std::vector IMapImpl::keySet( + std::vector IMapImpl::keySetData( const serialization::IdentifiedDataSerializable &predicate) { std::auto_ptr request = protocol::codec::MapKeySetWithPredicateCodec::RequestParameters::encode(getName(), @@ -434,7 +434,7 @@ namespace hazelcast { request); } - EntryVector IMapImpl::entrySet() { + EntryVector IMapImpl::entrySetData() { std::auto_ptr request = protocol::codec::MapEntrySetCodec::RequestParameters::encode( getName()); @@ -443,7 +443,7 @@ namespace hazelcast { request); } - EntryVector IMapImpl::entrySet( + EntryVector IMapImpl::entrySetData( const serialization::IdentifiedDataSerializable &predicate) { std::auto_ptr request = protocol::codec::MapEntriesWithPredicateCodec::RequestParameters::encode( @@ -453,7 +453,7 @@ namespace hazelcast { request); } - std::vector IMapImpl::values() { + std::vector IMapImpl::valuesData() { std::auto_ptr request = protocol::codec::MapValuesCodec::RequestParameters::encode( getName()); @@ -462,7 +462,7 @@ namespace hazelcast { request); } - std::vector IMapImpl::values( + std::vector IMapImpl::valuesData( const serialization::IdentifiedDataSerializable &predicate) { std::auto_ptr request = protocol::codec::MapValuesWithPredicateCodec::RequestParameters::encode( diff --git a/hazelcast/src/hazelcast/client/proxy/IQueueImpl.cpp b/hazelcast/src/hazelcast/client/proxy/IQueueImpl.cpp index a30a5418d4..8e1ef8b52d 100644 --- a/hazelcast/src/hazelcast/client/proxy/IQueueImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/IQueueImpl.cpp @@ -74,7 +74,7 @@ namespace hazelcast { partitionId); } - std::auto_ptr IQueueImpl::poll(long timeoutInMillis) { + std::auto_ptr IQueueImpl::pollData(long timeoutInMillis) { std::auto_ptr request = protocol::codec::QueuePollCodec::RequestParameters::encode(getName(), timeoutInMillis); @@ -105,7 +105,7 @@ namespace hazelcast { return invokeAndGetResult(request, partitionId); } - std::vector IQueueImpl::drainTo(size_t maxElements) { + std::vector IQueueImpl::drainToData(size_t maxElements) { std::auto_ptr request = protocol::codec::QueueDrainToMaxSizeCodec::RequestParameters::encode(getName(), maxElements); @@ -114,7 +114,7 @@ namespace hazelcast { } - std::auto_ptr IQueueImpl::peek() { + std::auto_ptr IQueueImpl::peekData() { std::auto_ptr request = protocol::codec::QueuePeekCodec::RequestParameters::encode(getName()); @@ -130,7 +130,7 @@ namespace hazelcast { partitionId); } - std::vector IQueueImpl::toArray() { + std::vector IQueueImpl::toArrayData() { std::auto_ptr request = protocol::codec::QueueIteratorCodec::RequestParameters::encode(getName()); diff --git a/hazelcast/src/hazelcast/client/proxy/ISetImpl.cpp b/hazelcast/src/hazelcast/client/proxy/ISetImpl.cpp index 3d2288eae7..0c2d4e50b1 100644 --- a/hazelcast/src/hazelcast/client/proxy/ISetImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/ISetImpl.cpp @@ -73,7 +73,7 @@ namespace hazelcast { return invokeAndGetResult(request, partitionId); } - std::vector ISetImpl::toArray() { + std::vector ISetImpl::toArrayData() { std::auto_ptr request = protocol::codec::SetGetAllCodec::RequestParameters::encode(getName()); diff --git a/hazelcast/src/hazelcast/client/proxy/MultiMapImpl.cpp b/hazelcast/src/hazelcast/client/proxy/MultiMapImpl.cpp index 64edbe17db..2c80cf3443 100644 --- a/hazelcast/src/hazelcast/client/proxy/MultiMapImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/MultiMapImpl.cpp @@ -62,7 +62,7 @@ namespace hazelcast { return invokeAndGetResult(request, partitionId); } - std::vector MultiMapImpl::get(const serialization::pimpl::Data& key) { + std::vector MultiMapImpl::getData(const serialization::pimpl::Data &key) { int partitionId = getPartitionId(key); std::auto_ptr request = @@ -80,7 +80,7 @@ namespace hazelcast { return invokeAndGetResult(request, partitionId); } - std::vector MultiMapImpl::remove(const serialization::pimpl::Data& key) { + std::vector MultiMapImpl::removeData(const serialization::pimpl::Data& key) { int partitionId = getPartitionId(key); std::auto_ptr request = protocol::codec::MultiMapRemoveCodec::RequestParameters::encode(getName(), key, util::getThreadId()); @@ -88,21 +88,21 @@ namespace hazelcast { return invokeAndGetResult, protocol::codec::MultiMapRemoveCodec::ResponseParameters>(request, partitionId); } - std::vector MultiMapImpl::keySet() { + std::vector MultiMapImpl::keySetData() { std::auto_ptr request = protocol::codec::MultiMapKeySetCodec::RequestParameters::encode(getName()); return invokeAndGetResult, protocol::codec::MultiMapKeySetCodec::ResponseParameters>(request); } - std::vector MultiMapImpl::values() { + std::vector MultiMapImpl::valuesData() { std::auto_ptr request = protocol::codec::MultiMapValuesCodec::RequestParameters::encode(getName()); return invokeAndGetResult, protocol::codec::MultiMapValuesCodec::ResponseParameters>(request); } - std::vector > MultiMapImpl::entrySet() { + std::vector > MultiMapImpl::entrySetData() { std::auto_ptr request = protocol::codec::MultiMapEntrySetCodec::RequestParameters::encode(getName()); diff --git a/hazelcast/src/hazelcast/client/proxy/TransactionalMapImpl.cpp b/hazelcast/src/hazelcast/client/proxy/TransactionalMapImpl.cpp index a2e3301f22..a86ac778e3 100644 --- a/hazelcast/src/hazelcast/client/proxy/TransactionalMapImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/TransactionalMapImpl.cpp @@ -56,7 +56,7 @@ namespace hazelcast { return invokeAndGetResult(request); } - std::auto_ptr TransactionalMapImpl::get(const serialization::pimpl::Data& key) { + std::auto_ptr TransactionalMapImpl::getData(const serialization::pimpl::Data& key) { std::auto_ptr request = protocol::codec::TransactionalMapGetCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId(), key); @@ -72,7 +72,7 @@ namespace hazelcast { return invokeAndGetResult(request); } - std::auto_ptr TransactionalMapImpl::put( + std::auto_ptr TransactionalMapImpl::putData( const serialization::pimpl::Data& key, const serialization::pimpl::Data& value) { std::auto_ptr request = @@ -91,7 +91,7 @@ namespace hazelcast { invoke(request); } - std::auto_ptr TransactionalMapImpl::putIfAbsent(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value) { + std::auto_ptr TransactionalMapImpl::putIfAbsentData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value) { std::auto_ptr request = protocol::codec::TransactionalMapPutIfAbsentCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId(), key, value); @@ -99,7 +99,7 @@ namespace hazelcast { return invokeAndGetResult, protocol::codec::TransactionalMapPutIfAbsentCodec::ResponseParameters>(request); } - std::auto_ptr TransactionalMapImpl::replace(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value) { + std::auto_ptr TransactionalMapImpl::replaceData(const serialization::pimpl::Data& key, const serialization::pimpl::Data& value) { std::auto_ptr request = protocol::codec::TransactionalMapReplaceCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId(), key, value); @@ -115,7 +115,7 @@ namespace hazelcast { return invokeAndGetResult(request); } - std::auto_ptr TransactionalMapImpl::remove(const serialization::pimpl::Data& key) { + std::auto_ptr TransactionalMapImpl::removeData(const serialization::pimpl::Data& key) { std::auto_ptr request = protocol::codec::TransactionalMapRemoveCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId(), key); @@ -139,7 +139,7 @@ namespace hazelcast { return invokeAndGetResult(request); } - std::vector TransactionalMapImpl::keySet() { + std::vector TransactionalMapImpl::keySetData() { std::auto_ptr request = protocol::codec::TransactionalMapKeySetCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId()); @@ -147,7 +147,7 @@ namespace hazelcast { return invokeAndGetResult, protocol::codec::TransactionalMapKeySetCodec::ResponseParameters>(request); } - std::vector TransactionalMapImpl::keySet(const serialization::IdentifiedDataSerializable *predicate) { + std::vector TransactionalMapImpl::keySetData(const serialization::IdentifiedDataSerializable *predicate) { std::auto_ptr request = protocol::codec::TransactionalMapKeySetWithPredicateCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId(), toData(predicate)); @@ -155,7 +155,7 @@ namespace hazelcast { return invokeAndGetResult, protocol::codec::TransactionalMapKeySetWithPredicateCodec::ResponseParameters>(request); } - std::vector TransactionalMapImpl::values() { + std::vector TransactionalMapImpl::valuesData() { std::auto_ptr request = protocol::codec::TransactionalMapValuesCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId()); @@ -163,7 +163,7 @@ namespace hazelcast { return invokeAndGetResult, protocol::codec::TransactionalMapValuesCodec::ResponseParameters>(request); } - std::vector TransactionalMapImpl::values(const serialization::IdentifiedDataSerializable *predicate) { + std::vector TransactionalMapImpl::valuesData(const serialization::IdentifiedDataSerializable *predicate) { std::auto_ptr request = protocol::codec::TransactionalMapValuesWithPredicateCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId(), toData(predicate)); diff --git a/hazelcast/src/hazelcast/client/proxy/TransactionalMultiMapImpl.cpp b/hazelcast/src/hazelcast/client/proxy/TransactionalMultiMapImpl.cpp index e3760b2774..bced204901 100644 --- a/hazelcast/src/hazelcast/client/proxy/TransactionalMultiMapImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/TransactionalMultiMapImpl.cpp @@ -48,7 +48,7 @@ namespace hazelcast { request); } - std::vector TransactionalMultiMapImpl::get( + std::vector TransactionalMultiMapImpl::getData( const serialization::pimpl::Data &key) { std::auto_ptr request = protocol::codec::TransactionalMultiMapGetCodec::RequestParameters::encode( @@ -70,7 +70,7 @@ namespace hazelcast { } - std::vector TransactionalMultiMapImpl::remove( + std::vector TransactionalMultiMapImpl::removeData( const serialization::pimpl::Data &key) { std::auto_ptr request = protocol::codec::TransactionalMultiMapRemoveCodec::RequestParameters::encode( diff --git a/hazelcast/src/hazelcast/client/proxy/TransactionalQueueImpl.cpp b/hazelcast/src/hazelcast/client/proxy/TransactionalQueueImpl.cpp index 7b42bf2fee..ca91bd5ec8 100644 --- a/hazelcast/src/hazelcast/client/proxy/TransactionalQueueImpl.cpp +++ b/hazelcast/src/hazelcast/client/proxy/TransactionalQueueImpl.cpp @@ -43,7 +43,7 @@ namespace hazelcast { return invokeAndGetResult(request); } - std::auto_ptr TransactionalQueueImpl::poll(long timeoutInMillis) { + std::auto_ptr TransactionalQueueImpl::pollData(long timeoutInMillis) { std::auto_ptr request = protocol::codec::TransactionalQueuePollCodec::RequestParameters::encode( getName(), getTransactionId(), util::getThreadId(), timeoutInMillis); diff --git a/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationService.cpp b/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationService.cpp index cbc9442d1a..12753b9f7c 100644 --- a/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationService.cpp +++ b/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationService.cpp @@ -33,7 +33,7 @@ namespace hazelcast { namespace pimpl { #define CHECK_NULL(type) \ if (isNullData(data)) { \ - return boost::shared_ptr(); \ + return std::auto_ptr(); \ } SerializationService::SerializationService(const SerializationConfig& serializationConfig) @@ -351,7 +351,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(byte); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -360,7 +360,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_BYTE, typeId); - boost::shared_ptr object(new byte); + std::auto_ptr object(new byte); *object = dataInput.readByte(); @@ -368,7 +368,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(bool); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -377,7 +377,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_BOOLEAN, typeId); - boost::shared_ptr object(new bool); + std::auto_ptr object(new bool); *object = dataInput.readBoolean(); @@ -385,7 +385,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(char); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -394,7 +394,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_CHAR, typeId); - boost::shared_ptr object(new char); + std::auto_ptr object(new char); *object = dataInput.readChar(); @@ -402,7 +402,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(short); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -411,7 +411,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_SHORT, typeId); - boost::shared_ptr object(new short); + std::auto_ptr object(new short); *object = dataInput.readShort(); @@ -419,7 +419,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(int); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -428,7 +428,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_INTEGER, typeId); - boost::shared_ptr object(new int); + std::auto_ptr object(new int); *object = dataInput.readInt(); @@ -436,7 +436,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(long); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -445,7 +445,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_LONG, typeId); - boost::shared_ptr object(new long); + std::auto_ptr object(new long); *object = (long)dataInput.readLong(); @@ -453,7 +453,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(float); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -462,7 +462,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_FLOAT, typeId); - boost::shared_ptr object(new float); + std::auto_ptr object(new float); *object = dataInput.readFloat(); @@ -470,7 +470,7 @@ namespace hazelcast { } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(double); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -479,7 +479,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_DOUBLE, typeId); - boost::shared_ptr object(new double); + std::auto_ptr object(new double); *object = dataInput.readDouble(); @@ -487,7 +487,7 @@ namespace hazelcast { } template<> - boost::shared_ptr > SerializationService::toObject(const Data &data) { + std::auto_ptr > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -496,11 +496,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_CHAR_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readCharArray()); + return std::auto_ptr > (dataInput.readCharArray()); } template<> - boost::shared_ptr > SerializationService::toObject(const Data &data) { + std::auto_ptr > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -509,11 +509,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_BOOLEAN_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readBooleanArray()); + return std::auto_ptr > (dataInput.readBooleanArray()); } template<> - boost::shared_ptr > SerializationService::toObject(const Data &data) { + std::auto_ptr > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -522,11 +522,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_SHORT_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readShortArray()); + return std::auto_ptr > (dataInput.readShortArray()); } template<> - boost::shared_ptr > SerializationService::toObject(const Data &data) { + std::auto_ptr > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -535,11 +535,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_INTEGER_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readIntArray()); + return std::auto_ptr > (dataInput.readIntArray()); } template<> - boost::shared_ptr > SerializationService::toObject(const Data &data) { + std::auto_ptr > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -548,11 +548,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_LONG_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readLongArray()); + return std::auto_ptr > (dataInput.readLongArray()); } template<> - boost::shared_ptr< std::vector > SerializationService::toObject(const Data &data) { + std::auto_ptr< std::vector > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -561,11 +561,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_FLOAT_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readFloatArray()); + return std::auto_ptr > (dataInput.readFloatArray()); } template<> - boost::shared_ptr > SerializationService::toObject(const Data &data) { + std::auto_ptr > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -574,11 +574,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_DOUBLE_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readDoubleArray()); + return std::auto_ptr > (dataInput.readDoubleArray()); } template<> - boost::shared_ptr SerializationService::toObject(const Data &data) { + std::auto_ptr SerializationService::toObject(const Data &data) { CHECK_NULL(std::string); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -587,11 +587,11 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_STRING, typeId); - return boost::shared_ptr (dataInput.readUTF()); + return std::auto_ptr (dataInput.readUTF()); } template<> - boost::shared_ptr > SerializationService::toObject(const Data &data) { + std::auto_ptr > SerializationService::toObject(const Data &data) { CHECK_NULL(std::vector); DataInput dataInput(data.toByteArray(), Data::DATA_OFFSET); @@ -600,7 +600,7 @@ namespace hazelcast { constants.checkClassType(SerializationConstants::CONSTANT_TYPE_STRING_ARRAY, typeId); - return boost::shared_ptr > (dataInput.readUTFArray()); + return std::auto_ptr > (dataInput.readUTFArray()); } const byte SerializationService::getVersion() const { diff --git a/hazelcast/test/src/adaptor/RawPointerListTest.cpp b/hazelcast/test/src/adaptor/RawPointerListTest.cpp new file mode 100644 index 0000000000..6df1b292f1 --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerListTest.cpp @@ -0,0 +1,205 @@ +/* + * 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 ihsan demir on 21/3/16. + +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/client/adaptor/RawPointerList.h" + +#include "HazelcastServer.h" +#include "HazelcastServerFactory.h" +#include "ClientTestSupport.h" + +namespace hazelcast { + namespace client { + namespace test { + namespace adaptor { + class RawPointerListTest : public ClientTestSupport { + public: + RawPointerListTest() : instance(*g_srvFactory), client(getNewClient()), + originalList(client->getList("RawPointerListTest")), list(originalList) { + } + + protected: + class MyListItemListener : public ItemListener { + public: + MyListItemListener(util::CountDownLatch& latch) + : latch(latch) { + + } + + void itemAdded(const ItemEvent& itemEvent) { + latch.countDown(); + } + + void itemRemoved(const ItemEvent& item) { + } + + private: + util::CountDownLatch& latch; + }; + + HazelcastServer instance; + ClientConfig clientConfig; + std::auto_ptr client; + IList originalList; + client::adaptor::RawPointerList list; + }; + + TEST_F(RawPointerListTest, testAddAll) { + + std::vector l; + l.push_back("item1"); + l.push_back("item2"); + ASSERT_TRUE(list.addAll(l)); + + ASSERT_TRUE(list.addAll(1, l)); + ASSERT_EQ(4, list.size()); + + ASSERT_EQ("item1", *(list.get(0))); + ASSERT_EQ("item1", *(list.get(1))); + ASSERT_EQ("item2", *(list.get(2))); + ASSERT_EQ("item2", *(list.get(3))); + } + + TEST_F(RawPointerListTest, testAddSetRemove) { + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item2")); + list.add(0, "item3"); + ASSERT_EQ(3, list.size()); + std::auto_ptr temp = list.set(2, "item4"); + ASSERT_EQ("item2", *temp); + + ASSERT_EQ(3, list.size()); + ASSERT_EQ("item3", *(list.get(0))); + ASSERT_EQ("item1", *(list.get(1))); + ASSERT_EQ("item4", *(list.get(2))); + + ASSERT_FALSE(list.remove("item2")); + ASSERT_TRUE(list.remove("item3")); + + temp = list.remove(1); + ASSERT_EQ("item4", *temp); + + ASSERT_EQ(1, list.size()); + ASSERT_EQ("item1", *(list.get(0))); + } + + TEST_F(RawPointerListTest, testIndexOf) { + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item2")); + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item4")); + + ASSERT_EQ(-1, list.indexOf("item5")); + ASSERT_EQ(0, list.indexOf("item1")); + + ASSERT_EQ(-1, list.lastIndexOf("item6")); + ASSERT_EQ(2, list.lastIndexOf("item1")); + } + + TEST_F(RawPointerListTest, testToArray) { + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item2")); + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item4")); + + std::auto_ptr > ar = list.toArray(); + + ASSERT_EQ((size_t)4, ar->size()); + ASSERT_NE((std::string *)NULL, ar->get(0).get()); + ASSERT_NE((std::string *)NULL, ar->get(1).get()); + ASSERT_NE((std::string *)NULL, ar->get(2).get()); + ASSERT_NE((std::string *)NULL, ar->get(3).get()); + ASSERT_EQ("item1", *((*ar)[0])); + ASSERT_EQ("item2", *ar->get(1)); + ASSERT_EQ("item1", *((*ar)[2])); + ASSERT_EQ("item4", *ar->get(3)); + + ar = list.subList(1, 3); + + ASSERT_EQ((size_t)2, ar->size()); + ASSERT_NE((std::string *)NULL, ar->get(0).get()); + ASSERT_NE((std::string *)NULL, ar->get(1).get()); + ASSERT_EQ("item2", *ar->get(0)); + ASSERT_EQ("item1", *ar->get(1)); + } + + TEST_F(RawPointerListTest, testContains) { + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item2")); + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item4")); + + ASSERT_FALSE(list.contains("item3")); + ASSERT_TRUE(list.contains("item2")); + + std::vector l; + l.push_back("item4"); + l.push_back("item3"); + + ASSERT_FALSE(list.containsAll(l)); + ASSERT_TRUE(list.add("item3")); + ASSERT_TRUE(list.containsAll(l)); + } + + TEST_F(RawPointerListTest, testRemoveRetainAll) { + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item2")); + ASSERT_TRUE(list.add("item1")); + ASSERT_TRUE(list.add("item4")); + + std::vector l; + l.push_back("item4"); + l.push_back("item3"); + + ASSERT_TRUE(list.removeAll(l)); + ASSERT_EQ(3, (int)list.size()); + ASSERT_FALSE(list.removeAll(l)); + ASSERT_EQ(3, (int)list.size()); + + l.clear(); + l.push_back("item1"); + l.push_back("item2"); + ASSERT_FALSE(list.retainAll(l)); + ASSERT_EQ(3, (int)list.size()); + + l.clear(); + ASSERT_TRUE(list.retainAll(l)); + ASSERT_EQ(0, (int)list.size()); + + } + + TEST_F(RawPointerListTest, testListener) { + util::CountDownLatch latch(5); + + MyListItemListener listener(latch); + std::string registrationId = list.addItemListener(listener, true); + + for (int i = 0; i < 5; i++) { + list.add(std::string("item") + util::IOUtil::to_string(i)); + } + + ASSERT_TRUE(latch.await(20)); + + ASSERT_TRUE(list.removeItemListener(registrationId)); + } + } + } + } +} + + diff --git a/hazelcast/test/src/adaptor/RawPointerMapTest.cpp b/hazelcast/test/src/adaptor/RawPointerMapTest.cpp new file mode 100644 index 0000000000..2d71195400 --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerMapTest.cpp @@ -0,0 +1,727 @@ +/* + * 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 sancar koyunlu on 8/27/13. + +#include "hazelcast/client/query/SqlPredicate.h" +#include "hazelcast/util/Util.h" +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/client/adaptor/RawPointerMap.h" +#include "hazelcast/client/EntryAdapter.h" +#include "hazelcast/client/serialization/IdentifiedDataSerializable.h" +#include "hazelcast/client/ClientConfig.h" + +#include "HazelcastServerFactory.h" +#include "serialization/Employee.h" +#include "TestHelperFunctions.h" +#include "ClientTestSupport.h" +#include "HazelcastServer.h" + + +namespace hazelcast { + namespace client { + namespace test { + namespace adaptor { + class RawPointerMapTest : public ClientTestSupport { + public: + RawPointerMapTest() : instance(*g_srvFactory), instance2(*g_srvFactory), client(getNewClient()), + originalMap(client->getMap("RawPointerMapTest")), + imap(new hazelcast::client::adaptor::RawPointerMap(originalMap)) { + } + + void fillMap() { + for (int i = 0; i < 10; i++) { + std::string key = "key"; + key += util::IOUtil::to_string(i); + std::string value = "value"; + value += util::IOUtil::to_string(i); + imap->put(key, value); + } + } + protected: + HazelcastServer instance; + HazelcastServer instance2; + ClientConfig clientConfig; + std::auto_ptr client; + IMap originalMap; + std::auto_ptr > imap; + }; + + class SampleEntryListener : public EntryAdapter { + public: + SampleEntryListener(util::CountDownLatch &addLatch, util::CountDownLatch &removeLatch, + util::CountDownLatch &updateLatch, util::CountDownLatch &evictLatch) + : addLatch(addLatch), removeLatch(removeLatch), updateLatch(updateLatch), + evictLatch(evictLatch) { + } + + void entryAdded(const EntryEvent &event) { + addLatch.countDown(); + } + + void entryRemoved(const EntryEvent &event) { + removeLatch.countDown(); + } + + void entryUpdated(const EntryEvent &event) { + updateLatch.countDown(); + } + + void entryEvicted(const EntryEvent &event) { + evictLatch.countDown(); + } + + private: + util::CountDownLatch &addLatch; + util::CountDownLatch &removeLatch; + util::CountDownLatch &updateLatch; + util::CountDownLatch &evictLatch; + }; + + class MyListener : public EntryAdapter { + public: + MyListener(util::CountDownLatch &latch, util::CountDownLatch &nullLatch) + : latch(latch), nullLatch(nullLatch) { + } + + void entryAdded(const EntryEvent &event) { + latch.countDown(); + } + + void entryEvicted(const EntryEvent &event) { + const std::string &oldValue = event.getOldValue(); + if (oldValue.compare("")) { + nullLatch.countDown(); + } + latch.countDown(); + } + + private: + util::CountDownLatch &latch; + util::CountDownLatch &nullLatch; + }; + + class ClearListener : public EntryAdapter { + public: + ClearListener(util::CountDownLatch &latch) : latch(latch) { + } + + void mapCleared(const MapEvent &event) { + latch.countDown(); + } + + private: + util::CountDownLatch &latch; + }; + + class EvictListener : public EntryAdapter { + public: + EvictListener(util::CountDownLatch &latch) : latch(latch) { + } + + void mapEvicted(const MapEvent &event) { + latch.countDown(); + } + + private: + util::CountDownLatch &latch; + }; + + TEST_F(RawPointerMapTest, testIssue537) { + util::CountDownLatch latch(2); + util::CountDownLatch nullLatch(1); + MyListener myListener(latch, nullLatch); + std::string id = imap->addEntryListener(myListener, true); + + imap->put("key1", "value1", 2 * 1000); + + ASSERT_TRUE(latch.await(10)); + ASSERT_TRUE(nullLatch.await(1)); + + ASSERT_TRUE(imap->removeEntryListener(id)); + + imap->put("key2", "value2"); + ASSERT_EQ(1, imap->size()); + } + + TEST_F(RawPointerMapTest, testContains) { + fillMap(); + + ASSERT_FALSE(imap->containsKey("key10")); + ASSERT_TRUE(imap->containsKey("key1")); + + ASSERT_FALSE(imap->containsValue("value10")); + ASSERT_TRUE(imap->containsValue("value1")); + + } + + TEST_F(RawPointerMapTest, testGet) { + fillMap(); + for (int i = 0; i < 10; i++) { + std::string key = "key"; + key += util::IOUtil::to_string(i); + std::auto_ptr temp = imap->get(key); + + std::string value = "value"; + value += util::IOUtil::to_string(i); + ASSERT_EQ(*temp, value); + } + } + + TEST_F(RawPointerMapTest, testRemoveAndDelete) { + fillMap(); + std::auto_ptr temp = imap->remove("key10"); + ASSERT_EQ(temp.get(), (std::string *) NULL); + imap->deleteEntry("key9"); + ASSERT_EQ(imap->size(), 9); + for (int i = 0; i < 9; i++) { + std::string key = "key"; + key += util::IOUtil::to_string(i); + std::auto_ptr temp2 = imap->remove(key); + std::string value = "value"; + value += util::IOUtil::to_string(i); + ASSERT_EQ(*temp2, value); + } + ASSERT_EQ(imap->size(), 0); + } + + TEST_F(RawPointerMapTest, testRemoveIfSame) { + fillMap(); + + ASSERT_FALSE(imap->remove("key2", "value")); + ASSERT_EQ(10, imap->size()); + + ASSERT_TRUE((imap->remove("key2", "value2"))); + ASSERT_EQ(9, imap->size()); + + } + + TEST_F(RawPointerMapTest, testGetAllPutAll) { + + std::map mapTemp; + + for (int i = 0; i < 100; i++) { + mapTemp[util::IOUtil::to_string(i)] = util::IOUtil::to_string(i); + } + imap->putAll(mapTemp); + ASSERT_EQ(imap->size(), 100); + + for (int i = 0; i < 100; i++) { + std::string expected = util::IOUtil::to_string(i); + std::auto_ptr actual = imap->get(util::IOUtil::to_string(i)); + ASSERT_EQ(expected, *actual); + } + + std::set tempSet; + tempSet.insert(util::IOUtil::to_string(1)); + tempSet.insert(util::IOUtil::to_string(3)); + + std::auto_ptr > m2 = imap->getAll(tempSet); + + ASSERT_EQ(2U, m2->size()); + std::auto_ptr key1 = m2->getKey(0); + ASSERT_NE((std::string *)NULL, key1.get()); + std::auto_ptr value1 = m2->getValue(0); + ASSERT_NE((std::string *)NULL, value1.get()); + ASSERT_EQ(*key1, *value1); + ASSERT_TRUE(*key1 == "1" || *key1 == "3" ); + + std::auto_ptr key2 = m2->getKey(1); + ASSERT_NE((std::string *)NULL, key2.get()); + std::auto_ptr value2 = m2->getValue(1); + ASSERT_NE((std::string *)NULL, value2.get()); + ASSERT_EQ(*key2, *value2); + ASSERT_TRUE(*key2 == "1" || *key2 == "3" ); + ASSERT_NE(*key1, *key2); + } + + void tryPutThread(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + bool result = imap->tryPut("key1", "value3", 1 * 1000); + if (!result) { + latch->countDown(); + } + } + + void tryRemoveThread(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + bool result = imap->tryRemove("key2", 1 * 1000); + if (!result) { + latch->countDown(); + } + } + + TEST_F(RawPointerMapTest, testTryPutRemove) { + + ASSERT_TRUE(imap->tryPut("key1", "value1", 1 * 1000)); + ASSERT_TRUE(imap->tryPut("key2", "value2", 1 * 1000)); + imap->lock("key1"); + imap->lock("key2"); + + util::CountDownLatch latch(2); + + util::Thread t1(tryPutThread, &latch, imap.get()); + util::Thread t2(tryRemoveThread, &latch, imap.get()); + + ASSERT_TRUE(latch.await(20)); + ASSERT_EQ("value1", *(imap->get("key1"))); + ASSERT_EQ("value2", *(imap->get("key2"))); + imap->forceUnlock("key1"); + imap->forceUnlock("key2"); + } + + TEST_F(RawPointerMapTest, testPutTtl) { + util::CountDownLatch dummy(10); + util::CountDownLatch evict(1); + SampleEntryListener sampleEntryListener(dummy, dummy, dummy, evict); + std::string id = imap->addEntryListener(sampleEntryListener, false); + + imap->put("key1", "value1", 2000); + std::auto_ptr temp = imap->get("key1"); + ASSERT_EQ(*temp, "value1"); + ASSERT_TRUE(evict.await(20 * 1000)); + std::auto_ptr temp2 = imap->get("key1"); + ASSERT_EQ(temp2.get(), (std::string *) NULL); + + ASSERT_TRUE(imap->removeEntryListener(id)); + } + + TEST_F(RawPointerMapTest, testPutIfAbsent) { + std::auto_ptr o = imap->putIfAbsent("key1", "value1"); + ASSERT_EQ(o.get(), (std::string *) NULL); + ASSERT_EQ("value1", *(imap->putIfAbsent("key1", "value3"))); + } + + TEST_F(RawPointerMapTest, testPutIfAbsentTtl) { + ASSERT_EQ(imap->putIfAbsent("key1", "value1", 1000).get(), (std::string *) NULL); + ASSERT_EQ("value1", *(imap->putIfAbsent("key1", "value3", 1000))); + + ASSERT_NULL_EVENTUALLY(imap->putIfAbsent("key1", "value3", 1000).get()); + ASSERT_EQ("value3", *(imap->putIfAbsent("key1", "value4", 1000))); + } + + TEST_F(RawPointerMapTest, testSet) { + imap->set("key1", "value1"); + ASSERT_EQ("value1", *(imap->get("key1"))); + + imap->set("key1", "value2"); + ASSERT_EQ("value2", *(imap->get("key1"))); + + imap->set("key1", "value3", 1000); + ASSERT_EQ("value3", *(imap->get("key1"))); + + ASSERT_NULL_EVENTUALLY(imap->get("key1").get()); + } + + void testLockThread(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + imap->tryPut("key1", "value2", 1); + latch->countDown(); + } + + TEST_F(RawPointerMapTest, testLock) { + imap->put("key1", "value1"); + ASSERT_EQ("value1", *(imap->get("key1"))); + imap->lock("key1"); + util::CountDownLatch latch(1); + util::Thread t1(testLockThread, &latch, imap.get()); + ASSERT_TRUE(latch.await(5)); + ASSERT_EQ("value1", *(imap->get("key1"))); + imap->forceUnlock("key1"); + + } + + void testLockTTLThread(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + imap->tryPut("key1", "value2", 5 * 1000); + latch->countDown(); + } + + TEST_F(RawPointerMapTest, testLockTtl) { + imap->put("key1", "value1"); + ASSERT_EQ("value1", *(imap->get("key1"))); + imap->lock("key1", 2 * 1000); + util::CountDownLatch latch(1); + util::Thread t1(testLockTTLThread, &latch, imap.get()); + ASSERT_TRUE(latch.await(10)); + ASSERT_FALSE(imap->isLocked("key1")); + ASSERT_EQ("value2", *(imap->get("key1"))); + imap->forceUnlock("key1"); + + } + + void testLockTTL2Thread(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + if (!imap->tryLock("key1")) { + latch->countDown(); + } + if (imap->tryLock("key1", 5 * 1000)) { + latch->countDown(); + } + } + + TEST_F(RawPointerMapTest, testLockTtl2) { + imap->lock("key1", 3 * 1000); + util::CountDownLatch latch(2); + util::Thread t1(testLockTTL2Thread, &latch, imap.get()); + ASSERT_TRUE(latch.await(10)); + imap->forceUnlock("key1"); + + } + + void testMapTryLockThread1(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + if (!imap->tryLock("key1", 2)) { + latch->countDown(); + } + } + + void testMapTryLockThread2(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + if (imap->tryLock("key1", 20 * 1000)) { + latch->countDown(); + } + } + + TEST_F(RawPointerMapTest, testTryLock) { + + ASSERT_TRUE(imap->tryLock("key1", 2 * 1000)); + util::CountDownLatch latch(1); + util::Thread t1(testMapTryLockThread1, &latch, imap.get()); + + ASSERT_TRUE(latch.await(100)); + + ASSERT_TRUE(imap->isLocked("key1")); + + util::CountDownLatch latch2(1); + util::Thread t2(testMapTryLockThread2, &latch2, imap.get()); + + util::sleep(1); + imap->unlock("key1"); + ASSERT_TRUE(latch2.await(100)); + ASSERT_TRUE(imap->isLocked("key1")); + imap->forceUnlock("key1"); + + } + + void testMapForceUnlockThread(util::ThreadArgs &args) { + util::CountDownLatch *latch = (util::CountDownLatch *) args.arg0; + hazelcast::client::adaptor::RawPointerMap *imap = (hazelcast::client::adaptor::RawPointerMap *) args.arg1; + imap->forceUnlock("key1"); + latch->countDown(); + } + + TEST_F(RawPointerMapTest, testForceUnlock) { + imap->lock("key1"); + util::CountDownLatch latch(1); + util::Thread t2(testMapForceUnlockThread, &latch, imap.get()); + ASSERT_TRUE(latch.await(100)); + t2.join(); + ASSERT_FALSE(imap->isLocked("key1")); + + } + + TEST_F(RawPointerMapTest, testValues) { + + fillMap(); + query::SqlPredicate predicate("this == value1"); + std::auto_ptr > tempVector = imap->values(predicate); + ASSERT_EQ(1U, tempVector->size()); + + ASSERT_EQ("value1", *tempVector->get(0)); + } + + TEST_F(RawPointerMapTest, testReplace) { + std::auto_ptr temp = imap->replace("key1", "value"); + ASSERT_EQ(temp.get(), (std::string *) NULL); + + std::string tempKey = "key1"; + std::string tempValue = "value1"; + imap->put(tempKey, tempValue); + + ASSERT_EQ("value1", *(imap->replace("key1", "value2"))); + ASSERT_EQ("value2", *(imap->get("key1"))); + + ASSERT_EQ(false, imap->replace("key1", "value1", "value3")); + ASSERT_EQ("value2", *(imap->get("key1"))); + + ASSERT_EQ(true, imap->replace("key1", "value2", "value3")); + ASSERT_EQ("value3", *(imap->get("key1"))); + } + + class SampleEntryListenerForPortableKey : public EntryAdapter { + public: + SampleEntryListenerForPortableKey(util::CountDownLatch &latch, util::AtomicInt &atomicInteger) + : latch(latch), atomicInteger(atomicInteger) { + + } + + void entryAdded(const EntryEvent &event) { + ++atomicInteger; + latch.countDown(); + } + + private: + util::CountDownLatch &latch; + util::AtomicInt &atomicInteger; + }; + + + TEST_F(RawPointerMapTest, testPredicateListenerWithPortableKey) { + IMap map = client->getMap("tradeMap"); + hazelcast::client::adaptor::RawPointerMap tradeMap(map); + util::CountDownLatch countDownLatch(1); + util::AtomicInt atomicInteger(0); + SampleEntryListenerForPortableKey listener(countDownLatch, atomicInteger); + Employee key("a", 1); + std::string id = tradeMap.addEntryListener(listener, key, true); + Employee key2("a", 2); + tradeMap.put(key2, 1); + tradeMap.put(key, 3); + ASSERT_TRUE(countDownLatch.await(5)); + ASSERT_EQ(1, (int) atomicInteger); + + ASSERT_TRUE(tradeMap.removeEntryListener(id)); + } + + TEST_F(RawPointerMapTest, testListener) { + util::CountDownLatch latch1Add(5); + util::CountDownLatch latch1Remove(2); + util::CountDownLatch dummy(10); + util::CountDownLatch latch2Add(1); + util::CountDownLatch latch2Remove(1); + + SampleEntryListener listener1(latch1Add, latch1Remove, dummy, dummy); + SampleEntryListener listener2(latch2Add, latch2Remove, dummy, dummy); + + std::string listener1ID = imap->addEntryListener(listener1, false); + std::string listener2ID = imap->addEntryListener(listener2, "key3", true); + + util::sleep(2); + + imap->put("key1", "value1"); + imap->put("key2", "value2"); + imap->put("key3", "value3"); + imap->put("key4", "value4"); + imap->put("key5", "value5"); + + imap->remove("key1"); + imap->remove("key3"); + + ASSERT_TRUE(latch1Add.await(10)); + ASSERT_TRUE(latch1Remove.await(10)); + ASSERT_TRUE(latch2Add.await(5)); + ASSERT_TRUE(latch2Remove.await(5)); + + ASSERT_TRUE(imap->removeEntryListener(listener1ID)); + ASSERT_TRUE(imap->removeEntryListener(listener2ID)); + + } + + TEST_F(RawPointerMapTest, testClearEvent) { + util::CountDownLatch latch(1); + ClearListener clearListener(latch); + std::string listenerId = imap->addEntryListener(clearListener, false); + imap->put("key1", "value1"); + imap->clear(); + ASSERT_TRUE(latch.await(120)); + imap->removeEntryListener(listenerId); + } + + TEST_F(RawPointerMapTest, testEvictAllEvent) { + util::CountDownLatch latch(1); + EvictListener evictListener(latch); + std::string listenerId = imap->addEntryListener(evictListener, false); + imap->put("key1", "value1"); + imap->evictAll(); + ASSERT_TRUE(latch.await(120)); + imap->removeEntryListener(listenerId); + } + + TEST_F(RawPointerMapTest, testBasicPredicate) { + fillMap(); + + query::SqlPredicate predicate("this = 'value1'"); + std::auto_ptr > tempArray = imap->values(predicate); + + std::auto_ptr actual = tempArray->get(0); + ASSERT_NE((std::string *)NULL, actual.get()); + ASSERT_EQ("value1", *actual); + + std::auto_ptr > tempArray2 = imap->keySet(predicate); + + actual = (*tempArray2)[0]; + ASSERT_NE((std::string *)NULL, actual.get()); + ASSERT_EQ("key1", *actual); + + + std::auto_ptr > tempArray3 = imap->entrySet(predicate); + actual = tempArray3->getKey(0); + ASSERT_NE((std::string *)NULL, actual.get()); + ASSERT_EQ("key1", *actual); + + actual = tempArray3->getValue(0); + ASSERT_NE((std::string *)NULL, actual.get()); + ASSERT_EQ("value1", *actual); + } + + TEST_F(RawPointerMapTest, testKeySetAndValuesWithPredicates) { + std::string name = "testKeysetAndValuesWithPredicates"; + IMap mapOriginal = client->getMap(name); + hazelcast::client::adaptor::RawPointerMap map(mapOriginal); + + Employee emp1("abc-123-xvz", 34); + Employee emp2("abc-123-xvz", 20); + + map.put(emp1, emp1); + ASSERT_EQ(map.put(emp2, emp2).get(), (Employee *) NULL); + ASSERT_EQ(2, (int) map.size()); + ASSERT_EQ(2, (int) map.keySet()->size()); + query::SqlPredicate predicate("a = 10"); + ASSERT_EQ(0, (int) map.keySet(predicate)->size()); + predicate.setSql("a = 10"); + ASSERT_EQ(0, (int) map.values(predicate)->size()); + predicate.setSql("a >= 10"); + ASSERT_EQ(2, (int) map.keySet(predicate)->size()); + ASSERT_EQ(2, (int) map.values(predicate)->size()); + ASSERT_EQ(2, (int) map.size()); + ASSERT_EQ(2, (int) map.values()->size()); + } + + TEST_F(RawPointerMapTest, testMapWithPortable) { + IMap employeesMap = client->getMap("employees"); + hazelcast::client::adaptor::RawPointerMap employees(employeesMap); + std::auto_ptr n1 = employees.get(1); + ASSERT_EQ(n1.get(), (Employee *) NULL); + Employee employee("sancar", 24); + std::auto_ptr ptr = employees.put(1, employee); + ASSERT_EQ(ptr.get(), (Employee *) NULL); + ASSERT_FALSE(employees.isEmpty()); + std::auto_ptr > view = employees.getEntryView(1); + ASSERT_EQ(*(view->getValue()), employee); + ASSERT_EQ(*(view->getKey()), 1); + + employees.addIndex("a", true); + employees.addIndex("n", false); + } + + + TEST_F(RawPointerMapTest, testMapStoreRelatedRequests) { + imap->putTransient("ali", "veli", 1100); + imap->flush(); + ASSERT_EQ(1, imap->size()); + ASSERT_FALSE(imap->evict("deli")); + ASSERT_TRUE(imap->evict("ali")); + ASSERT_EQ(imap->get("ali").get(), (std::string *) NULL); + } + + class EntryMultiplier : public serialization::IdentifiedDataSerializable { + public: + EntryMultiplier(int multiplier) : multiplier(multiplier) { } + + /** + * @return factory id + */ + int getFactoryId() const { + return 666; + } + + /** + * @return class id + */ + int getClassId() const { + return 3; + } + + /** + * Defines how this class will be written. + * @param writer ObjectDataOutput + */ + void writeData(serialization::ObjectDataOutput &writer) const { + writer.writeInt(multiplier); + } + + /** + *Defines how this class will be read. + * @param reader ObjectDataInput + */ + void readData(serialization::ObjectDataInput &reader) { + multiplier = reader.readInt(); + } + + int getMultiplier() const { + return multiplier; + } + + private: + int multiplier; + }; + + TEST_F(RawPointerMapTest, testExecuteOnKey) { + IMap employeesMap = client->getMap("executeOnKey"); + hazelcast::client::adaptor::RawPointerMap employees(employeesMap); + + Employee empl1("ahmet", 35); + Employee empl2("mehmet", 21); + + employees.put(3, empl1); + employees.put(4, empl2); + + EntryMultiplier processor(4); + + std::auto_ptr result = employees.executeOnKey(4, processor); + + ASSERT_NE((int *) NULL, result.get()); + ASSERT_EQ(4 * processor.getMultiplier(), *result); + } + + TEST_F(RawPointerMapTest, testExecuteOnEntries) { + IMap employeesMap = client->getMap("testExecuteOnEntries"); + hazelcast::client::adaptor::RawPointerMap employees(employeesMap); + + Employee empl1("ahmet", 35); + Employee empl2("mehmet", 21); + Employee empl3("deniz", 25); + + employees.put(3, empl1); + employees.put(4, empl2); + employees.put(5, empl3); + + EntryMultiplier processor(4); + + std::auto_ptr > result = employees.executeOnEntries( + processor); + + ASSERT_EQ(3, (int) result->size()); + for (size_t i = 0;i < result->size();++i) { + std::auto_ptr key = result->getKey(i); + std::auto_ptr value = result->getValue(i); + ASSERT_TRUE(*key == 3 || *key == 4 || *key == 5); + ASSERT_EQ((*key) * processor.getMultiplier(), (*value)); + } + } + } + } + } +} + diff --git a/hazelcast/test/src/adaptor/RawPointerMultiMapTest.cpp b/hazelcast/test/src/adaptor/RawPointerMultiMapTest.cpp new file mode 100644 index 0000000000..f23b6b926c --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerMultiMapTest.cpp @@ -0,0 +1,271 @@ +/* + * 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 ihsan demir on 24/03/16. +#include +#include "hazelcast/util/Util.h" +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/client/EntryAdapter.h" +#include "hazelcast/client/MultiMap.h" +#include "hazelcast/client/adaptor/RawPointerMultiMap.h" + +#include "HazelcastServerFactory.h" +#include "ClientTestSupport.h" + +namespace hazelcast { + namespace client { + namespace test { + namespace adaptor { + class RawPointerMultiMapTest : public ClientTestSupport { + public: + RawPointerMultiMapTest() + : instance(*g_srvFactory) + , client(getNewClient()) + , originalMultimap(client->getMultiMap("RawPointerMultiMapTest")) + , mm(originalMultimap) { + } + + protected: + HazelcastServer instance; + ClientConfig clientConfig; + std::auto_ptr client; + MultiMap originalMultimap; + client::adaptor::RawPointerMultiMap mm; + + class MyMultiMapListener : public EntryAdapter{ + public: + MyMultiMapListener(util::CountDownLatch& addedLatch, util::CountDownLatch& removedLatch) + : addedLatch(addedLatch), removedLatch(removedLatch) { + } + + void entryAdded(const EntryEvent& event) { + addedLatch.countDown(); + } + + void entryRemoved(const EntryEvent& event) { + removedLatch.countDown(); + } + + private: + util::CountDownLatch& addedLatch; + util::CountDownLatch& removedLatch; + }; + + static void lockTtlThread(util::ThreadArgs& args) { + client::adaptor::RawPointerMultiMap *map = (client::adaptor::RawPointerMultiMap *)args.arg0; + util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1; + + if (!map->tryLock("key1")) { + latch->countDown(); + } + + if (map->tryLock("key1", 5 * 1000)) { + latch->countDown(); + } + } + }; + + TEST_F(RawPointerMultiMapTest, testPutGetRemove) { + ASSERT_TRUE(mm.put("key1", "value1")); + ASSERT_TRUE(mm.put("key1", "value2")); + ASSERT_TRUE(mm.put("key1", "value3")); + + ASSERT_TRUE(mm.put("key2", "value4")); + ASSERT_TRUE(mm.put("key2", "value5")); + + ASSERT_EQ(3, mm.valueCount("key1")); + ASSERT_EQ(2, mm.valueCount("key2")); + ASSERT_EQ(5, mm.size()); + + std::auto_ptr > coll = mm.get("key1"); + ASSERT_EQ(3, (int)coll->size()); + + coll = mm.remove("key2"); + ASSERT_EQ(2, (int)coll->size()); + ASSERT_EQ(0, mm.valueCount("key2")); + ASSERT_EQ(0, (int)mm.get("key2")->size()); + + ASSERT_FALSE(mm.remove("key1", "value4")); + ASSERT_EQ(3, mm.size()); + + ASSERT_TRUE(mm.remove("key1", "value2")); + ASSERT_EQ(2, mm.size()); + + ASSERT_TRUE(mm.remove("key1", "value1")); + ASSERT_EQ(1, mm.size()); + coll = mm.get("key1"); + std::auto_ptr val = coll->get(0); + ASSERT_NE((std::string *)NULL, val.get()); + ASSERT_EQ("value3", *val); + } + + TEST_F(RawPointerMultiMapTest, testKeySetEntrySetAndValues) { + ASSERT_TRUE(mm.put("key1", "value1")); + ASSERT_TRUE(mm.put("key1", "value2")); + ASSERT_TRUE(mm.put("key1", "value3")); + + ASSERT_TRUE(mm.put("key2", "value4")); + ASSERT_TRUE(mm.put("key2", "value5")); + + + ASSERT_EQ(2, (int)mm.keySet()->size()); + ASSERT_EQ(5, (int)mm.values()->size()); + ASSERT_EQ(5, (int)mm.entrySet()->size()); + } + + TEST_F(RawPointerMultiMapTest, testContains) { + ASSERT_TRUE(mm.put("key1", "value1")); + ASSERT_TRUE(mm.put("key1", "value2")); + ASSERT_TRUE(mm.put("key1", "value3")); + + ASSERT_TRUE(mm.put("key2", "value4")); + ASSERT_TRUE(mm.put("key2", "value5")); + + ASSERT_FALSE(mm.containsKey("key3")); + ASSERT_TRUE(mm.containsKey("key1")); + + ASSERT_FALSE(mm.containsValue("value6")); + ASSERT_TRUE(mm.containsValue("value4")); + + ASSERT_FALSE(mm.containsEntry("key1", "value4")); + ASSERT_FALSE(mm.containsEntry("key2", "value3")); + ASSERT_TRUE(mm.containsEntry("key1", "value1")); + ASSERT_TRUE(mm.containsEntry("key2", "value5")); + } + + TEST_F(RawPointerMultiMapTest, testListener) { + util::CountDownLatch latch1Add(8); + util::CountDownLatch latch1Remove(4); + + util::CountDownLatch latch2Add(3); + util::CountDownLatch latch2Remove(3); + + MyMultiMapListener listener1(latch1Add, latch1Remove); + MyMultiMapListener listener2(latch2Add, latch2Remove); + + std::string id1 = mm.addEntryListener(listener1, true); + std::string id2 = mm.addEntryListener(listener2, "key3", true); + + mm.put("key1", "value1"); + mm.put("key1", "value2"); + mm.put("key1", "value3"); + mm.put("key2", "value4"); + mm.put("key2", "value5"); + + mm.remove("key1", "value2"); + + mm.put("key3", "value6"); + mm.put("key3", "value7"); + mm.put("key3", "value8"); + + mm.remove("key3"); + + ASSERT_TRUE(latch1Add.await(20)); + ASSERT_TRUE(latch1Remove.await(20)); + + ASSERT_TRUE(latch2Add.await(20)); + ASSERT_TRUE(latch2Remove.await(20)); + + ASSERT_TRUE(mm.removeEntryListener(id1)); + ASSERT_TRUE(mm.removeEntryListener(id2)); + + } + + void lockThread(util::ThreadArgs& args) { + client::adaptor::RawPointerMultiMap *mm = (client::adaptor::RawPointerMultiMap *)args.arg0; + util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1; + if (!mm->tryLock("key1")) { + latch->countDown(); + } + } + + TEST_F(RawPointerMultiMapTest, testLock) { + mm.lock("key1"); + util::CountDownLatch latch(1); + util::Thread t(lockThread, &mm, &latch); + ASSERT_TRUE(latch.await(5)); + mm.forceUnlock("key1"); + } + + TEST_F(RawPointerMultiMapTest, testLockTtl) { + mm.lock("key1", 3 * 1000); + util::CountDownLatch latch(2); + util::Thread t(lockTtlThread, &mm, &latch); + ASSERT_TRUE(latch.await(10)); + mm.forceUnlock("key1"); + } + + + void tryLockThread(util::ThreadArgs& args) { + client::adaptor::RawPointerMultiMap *mm = (client::adaptor::RawPointerMultiMap *)args.arg0; + util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1; + try { + if (!mm->tryLock("key1", 2)) { + latch->countDown(); + } + } catch (...) { + std::cerr << "Unexpected exception at RawPointerMultiMapTest tryLockThread" << std::endl; + } + } + + void tryLockThread2(util::ThreadArgs& args) { + client::adaptor::RawPointerMultiMap *mm = (client::adaptor::RawPointerMultiMap *)args.arg0; + util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1; + try { + if (mm->tryLock("key1", 20 * 1000)) { + latch->countDown(); + } + } catch (...) { + std::cerr << "Unexpected exception at RawPointerMultiMapTest lockThread2" << std::endl; + } + } + + TEST_F(RawPointerMultiMapTest, testTryLock) { + ASSERT_TRUE(mm.tryLock("key1", 2 * 1000)); + util::CountDownLatch latch(1); + util::Thread t(tryLockThread, &mm, &latch); + ASSERT_TRUE(latch.await(100)); + ASSERT_TRUE(mm.isLocked("key1")); + + util::CountDownLatch latch2(1); + util::Thread t2(tryLockThread2, &mm, &latch2); + + util::sleep(1); + mm.unlock("key1"); + ASSERT_TRUE(latch2.await(100)); + ASSERT_TRUE(mm.isLocked("key1")); + mm.forceUnlock("key1"); + } + + void forceUnlockThread(util::ThreadArgs& args) { + client::adaptor::RawPointerMultiMap *mm = (client::adaptor::RawPointerMultiMap *)args.arg0; + util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1; + mm->forceUnlock("key1"); + latch->countDown(); + } + + TEST_F(RawPointerMultiMapTest, testForceUnlock) { + mm.lock("key1"); + util::CountDownLatch latch(1); + util::Thread t(forceUnlockThread, &mm, &latch); + ASSERT_TRUE(latch.await(100)); + ASSERT_FALSE(mm.isLocked("key1")); + } + } + } + } +} + diff --git a/hazelcast/test/src/adaptor/RawPointerQueueTest.cpp b/hazelcast/test/src/adaptor/RawPointerQueueTest.cpp new file mode 100644 index 0000000000..ade721c92b --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerQueueTest.cpp @@ -0,0 +1,294 @@ +/* + * 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 ihsan demir on 21/3/16. + +#include "HazelcastServer.h" +#include "ClientTestSupport.h" +#include "HazelcastServerFactory.h" + +#include "hazelcast/util/Util.h" +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/client/ItemListener.h" +#include "hazelcast/client/adaptor/RawPointerQueue.h" + +namespace hazelcast { + namespace client { + namespace test { + namespace adaptor { + class RawPointerQueueTest : public ClientTestSupport { + public: + RawPointerQueueTest() : instance(*g_srvFactory), client(getNewClient()), + originalQueue(client->getQueue("RawPointerQueueTest")), + q(originalQueue) { + } + + protected: + HazelcastServer instance; + ClientConfig clientConfig; + std::auto_ptr client; + IQueue originalQueue; + client::adaptor::RawPointerQueue q; + + class QueueTestItemListener : public ItemListener { + public: + QueueTestItemListener(util::CountDownLatch &latch) + : latch(latch) { + + } + + void itemAdded(const ItemEvent &itemEvent) { + latch.countDown(); + } + + void itemRemoved(const ItemEvent &item) { + } + + private: + util::CountDownLatch &latch; + }; + }; + + TEST_F(RawPointerQueueTest, testListener) { + ASSERT_EQ(0, q.size()); + + util::CountDownLatch latch(5); + + QueueTestItemListener listener(latch); + std::string id = q.addItemListener(listener, true); + + util::sleep(1); + + for (int i = 0; i < 5; i++) { + ASSERT_TRUE(q.offer(std::string("event_item") + util::IOUtil::to_string(i))); + } + + ASSERT_TRUE(latch.await(5)); + ASSERT_TRUE(q.removeItemListener(id)); + } + + void testOfferPollThread2(util::ThreadArgs &args) { + client::adaptor::RawPointerQueue *q = (client::adaptor::RawPointerQueue *) args.arg0; + util::sleep(2); + q->offer("item1"); + util::ILogger::getLogger().info("[testOfferPollThread2] item1 is offered"); + } + + TEST_F(RawPointerQueueTest, testOfferPoll) { + for (int i = 0; i < 10; i++) { + bool result = q.offer("item"); + ASSERT_TRUE(result); + } + ASSERT_EQ(10, q.size()); + q.poll(); + bool result = q.offer("item", 5); + ASSERT_TRUE(result); + + for (int i = 0; i < 10; i++) { + ASSERT_NE(q.poll().get(), (std::string *) NULL); + } + ASSERT_EQ(0, q.size()); + + util::Thread t2(testOfferPollThread2, &q); + + std::auto_ptr item = q.poll(30 * 1000); + ASSERT_NE(item.get(), (std::string *) NULL); + ASSERT_EQ("item1", *item); + t2.join(); + } + + TEST_F(RawPointerQueueTest, testRemainingCapacity) { + int capacity = q.remainingCapacity(); + ASSERT_TRUE(capacity > 10000); + q.offer("item"); + ASSERT_EQ(capacity - 1, q.remainingCapacity()); + } + + TEST_F(RawPointerQueueTest, testPeek) { + ASSERT_TRUE(q.offer("peek 1")); + ASSERT_TRUE(q.offer("peek 2")); + ASSERT_TRUE(q.offer("peek 3")); + + std::auto_ptr item = q.peek(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 1", *item); + } + + TEST_F(RawPointerQueueTest, testTake) { + ASSERT_TRUE(q.offer("peek 1")); + ASSERT_TRUE(q.offer("peek 2")); + ASSERT_TRUE(q.offer("peek 3")); + + std::auto_ptr item = q.take(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 1", *item); + + item = q.take(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 2", *item); + + item = q.take(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 3", *item); + + ASSERT_TRUE(q.isEmpty()); + + // start a thread to insert an item + util::Thread t2(testOfferPollThread2, &q); + + item = q.take(); // should block till it gets an item + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("item1", *item); + } + + TEST_F(RawPointerQueueTest, testRemove) { + ASSERT_TRUE(q.offer("item1")); + ASSERT_TRUE(q.offer("item2")); + ASSERT_TRUE(q.offer("item3")); + + ASSERT_FALSE(q.remove("item4")); + ASSERT_EQ(3, q.size()); + + ASSERT_TRUE(q.remove("item2")); + + ASSERT_EQ(2, q.size()); + + ASSERT_EQ("item1", *(q.poll())); + ASSERT_EQ("item3", *(q.poll())); + } + + + TEST_F(RawPointerQueueTest, testContains) { + ASSERT_TRUE(q.offer("item1")); + ASSERT_TRUE(q.offer("item2")); + ASSERT_TRUE(q.offer("item3")); + ASSERT_TRUE(q.offer("item4")); + ASSERT_TRUE(q.offer("item5")); + + + ASSERT_TRUE(q.contains("item3")); + ASSERT_FALSE(q.contains("item")); + + std::vector list; + list.push_back("item4"); + list.push_back("item2"); + + ASSERT_TRUE(q.containsAll(list)); + + list.push_back("item"); + ASSERT_FALSE(q.containsAll(list)); + } + + TEST_F(RawPointerQueueTest, testDrain) { + ASSERT_TRUE(q.offer("item1")); + ASSERT_TRUE(q.offer("item2")); + ASSERT_TRUE(q.offer("item3")); + ASSERT_TRUE(q.offer("item4")); + ASSERT_TRUE(q.offer("item5")); + + std::auto_ptr > list = q.drainTo(2); + ASSERT_EQ((size_t)2U, list->size()); + ASSERT_NE((std::string *)NULL, list->get(0).get()); + ASSERT_NE((std::string *)NULL, list->get(1).get()); + ASSERT_EQ("item1", *list->get(0)); + ASSERT_EQ("item2", *list->get(1)); + + list = q.drainTo(); + ASSERT_EQ((size_t)3U, list->size()); + ASSERT_NE((std::string *)NULL, list->get(0).get()); + ASSERT_NE((std::string *)NULL, list->get(1).get()); + ASSERT_NE((std::string *)NULL, list->get(2).get()); + ASSERT_EQ("item3", *list->get(0)); + ASSERT_EQ("item4", *list->get(1)); + ASSERT_EQ("item5", *list->get(2)); + } + + TEST_F(RawPointerQueueTest, testToArray) { + ASSERT_TRUE(q.offer("item1")); + ASSERT_TRUE(q.offer("item2")); + ASSERT_TRUE(q.offer("item3")); + ASSERT_TRUE(q.offer("item4")); + ASSERT_TRUE(q.offer("item5")); + + std::auto_ptr > array = q.toArray(); + size_t size = array->size(); + ASSERT_EQ(5U, size); + for (size_t i = 0; i < size; i++) { + std::auto_ptr item = (*array)[i]; + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ(std::string("item") + util::IOUtil::to_string(i + 1), *item); + } + } + + TEST_F(RawPointerQueueTest, testAddAll) { + std::vector coll; + coll.push_back("item1"); + coll.push_back("item2"); + coll.push_back("item3"); + coll.push_back("item4"); + + ASSERT_TRUE(q.addAll(coll)); + int size = q.size(); + ASSERT_EQ(size, (int) coll.size()); + } + + TEST_F(RawPointerQueueTest, testRemoveRetain) { + ASSERT_TRUE(q.offer("item1")); + ASSERT_TRUE(q.offer("item2")); + ASSERT_TRUE(q.offer("item3")); + ASSERT_TRUE(q.offer("item4")); + ASSERT_TRUE(q.offer("item5")); + + std::vector list; + list.push_back("item8"); + list.push_back("item9"); + ASSERT_FALSE(q.removeAll(list)); + ASSERT_EQ(5, q.size()); + + list.push_back("item3"); + list.push_back("item4"); + list.push_back("item1"); + ASSERT_TRUE(q.removeAll(list)); + ASSERT_EQ(2, q.size()); + + list.clear(); + list.push_back("item2"); + list.push_back("item5"); + ASSERT_FALSE(q.retainAll(list)); + ASSERT_EQ(2, q.size()); + + list.clear(); + ASSERT_TRUE(q.retainAll(list)); + ASSERT_EQ(0, q.size()); + } + + TEST_F(RawPointerQueueTest, testClear) { + ASSERT_TRUE(q.offer("item1")); + ASSERT_TRUE(q.offer("item2")); + ASSERT_TRUE(q.offer("item3")); + ASSERT_TRUE(q.offer("item4")); + ASSERT_TRUE(q.offer("item5")); + + q.clear(); + + ASSERT_EQ(0, q.size()); + ASSERT_EQ(q.poll().get(), (std::string *) NULL); + } + } + } + } +} + diff --git a/hazelcast/test/src/adaptor/RawPointerSetTest.cpp b/hazelcast/test/src/adaptor/RawPointerSetTest.cpp new file mode 100644 index 0000000000..cf9c15fb30 --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerSetTest.cpp @@ -0,0 +1,190 @@ +/* + * 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 ihsan demir on 21/03/16. + +#include "hazelcast/client/adaptor/RawPointerSet.h" +#include "hazelcast/client/HazelcastClient.h" + +#include "HazelcastServer.h" +#include "ClientTestSupport.h" +#include "HazelcastServerFactory.h" + +namespace hazelcast { + namespace client { + namespace test { + namespace adaptor { + class RawPointerSetTest : public ClientTestSupport { + public: + RawPointerSetTest() + : instance(*g_srvFactory) + , client(getNewClient()) + , originalSet(client->getSet("RawPointerSetTest")) + , set(originalSet) { + } + + protected: + class MySetItemListener : public ItemListener { + public: + MySetItemListener(util::CountDownLatch &latch) + :latch(latch) { + + } + + void itemAdded(const ItemEvent& itemEvent) { + latch.countDown(); + } + + void itemRemoved(const ItemEvent& item) { + } + + private: + util::CountDownLatch &latch; + }; + + HazelcastServer instance; + ClientConfig clientConfig; + std::auto_ptr client; + ISet originalSet; + client::adaptor::RawPointerSet set; + + bool itemExists(const std::vector &items, const std::string &item) const { + bool found = false; + for (std::vector::const_iterator it = items.begin();it != items.end();++it) { + if (item == *it) { + found = true; + break; + } + } + return found; + } + }; + + TEST_F(RawPointerSetTest, testAddAll) { + std::vector l; + l.push_back("item1"); + l.push_back("item2"); + + ASSERT_TRUE(set.addAll(l)); + ASSERT_EQ(2, set.size()); + + ASSERT_FALSE(set.addAll(l)); + ASSERT_EQ(2, set.size()); + } + + TEST_F(RawPointerSetTest, testAddRemove) { + ASSERT_TRUE(set.add("item1")); + ASSERT_TRUE(set.add("item2")); + ASSERT_TRUE(set.add("item3")); + ASSERT_EQ(3, set.size()); + + ASSERT_FALSE(set.add("item3")); + ASSERT_EQ(3, set.size()); + + + ASSERT_FALSE(set.remove("item4")); + ASSERT_TRUE(set.remove("item3")); + + } + + TEST_F(RawPointerSetTest, testContains) { + ASSERT_TRUE(set.add("item1")); + ASSERT_TRUE(set.add("item2")); + ASSERT_TRUE(set.add("item3")); + ASSERT_TRUE(set.add("item4")); + + ASSERT_FALSE(set.contains("item5")); + ASSERT_TRUE(set.contains("item2")); + + std::vector l; + l.push_back("item6"); + l.push_back("item3"); + + ASSERT_FALSE(set.containsAll(l)); + ASSERT_TRUE(set.add("item6")); + ASSERT_TRUE(set.containsAll(l)); + } + + TEST_F(RawPointerSetTest, testToArray) { + ASSERT_TRUE(set.add("item1")); + ASSERT_TRUE(set.add("item2")); + ASSERT_TRUE(set.add("item3")); + ASSERT_TRUE(set.add("item4")); + ASSERT_FALSE(set.add("item4")); + + std::auto_ptr > array = set.toArray(); + + ASSERT_EQ((size_t)4, array->size()); + std::vector items; + + for (size_t i = 0; i < array->size(); ++i) { + std::auto_ptr item = array->get(i); + ASSERT_NE((std::string *)NULL, item.get()); + items.push_back(*item); + } + + ASSERT_TRUE(itemExists(items, "item1")); + ASSERT_TRUE(itemExists(items, "item2")); + ASSERT_TRUE(itemExists(items, "item3")); + ASSERT_TRUE(itemExists(items, "item4")); + } + + TEST_F(RawPointerSetTest, testRemoveRetainAll) { + ASSERT_TRUE(set.add("item1")); + ASSERT_TRUE(set.add("item2")); + ASSERT_TRUE(set.add("item3")); + ASSERT_TRUE(set.add("item4")); + + std::vector l; + l.push_back("item4"); + l.push_back("item3"); + + ASSERT_TRUE(set.removeAll(l)); + ASSERT_EQ(2, set.size()); + ASSERT_FALSE(set.removeAll(l)); + ASSERT_EQ(2, set.size()); + + l.clear(); + l.push_back("item1"); + l.push_back("item2"); + ASSERT_FALSE(set.retainAll(l)); + ASSERT_EQ(2, set.size()); + + l.clear(); + ASSERT_TRUE(set.retainAll(l)); + ASSERT_EQ(0, set.size()); + } + + TEST_F(RawPointerSetTest, testListener) { + util::CountDownLatch latch(6); + + MySetItemListener listener(latch); + std::string registrationId = set.addItemListener(listener, true); + + for (int i = 0; i < 5; i++) { + set.add(std::string("item") + util::IOUtil::to_string(i)); + } + set.add("done"); + + ASSERT_TRUE(latch.await(20 )); + + ASSERT_TRUE(set.removeItemListener(registrationId)); + } + } + } + } +} + diff --git a/hazelcast/test/src/adaptor/RawPointerTxnMapTest.cpp b/hazelcast/test/src/adaptor/RawPointerTxnMapTest.cpp new file mode 100644 index 0000000000..e9d8e7bb17 --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerTxnMapTest.cpp @@ -0,0 +1,159 @@ +/* + * 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 ihsan demir on 24/03/16. + +#include "hazelcast/client/query/SqlPredicate.h" +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/client/adaptor/RawPointerTransactionalMap.h" + +#include "HazelcastServer.h" +#include "HazelcastServerFactory.h" +#include "ClientTestSupport.h" +#include "serialization/Employee.h" + +namespace hazelcast { + namespace client { + namespace test { + class RawPointerClientTxnMapTest : public ClientTestSupport { + public: + RawPointerClientTxnMapTest() + : instance(*g_srvFactory) + , client(getNewClient()) { + } + + protected: + HazelcastServer instance; + ClientConfig clientConfig; + std::auto_ptr client; + }; + + TEST_F(RawPointerClientTxnMapTest, testPutGet) { + std::string name = "defMap"; + + TransactionContext context = client->newTransactionContext(); + context.beginTransaction(); + + TransactionalMap originalMap = context.getMap(name); + client::adaptor::RawPointerTransactionalMap map(originalMap); + + ASSERT_EQ(map.put("key1", "value1").get(), (std::string *)NULL); + ASSERT_EQ("value1", *(map.get("key1"))); + boost::shared_ptr val = client->getMap(name).get("key1"); + ASSERT_EQ(val.get(), (std::string *)NULL); + + context.commitTransaction(); + + ASSERT_EQ("value1", *(client->getMap(name).get("key1"))); + } + + +// @Test MTODO +// public void testGetForUpdate() throws TransactionException { +// final IMap map = hz.getMap("testTxnGetForUpdate"); +// final CountDownLatch latch1 = new CountDownLatch(1); +// final CountDownLatch latch2 = new CountDownLatch(1); +// map.put("var", 0); +// final AtomicBoolean pass = new AtomicBoolean(true); +// +// +// Runnable incrementor = new Runnable() { +// public void run() { +// try { +// latch1.await(100, TimeUnit.SECONDS); +// pass.set(map.tryPut("var", 1, 0, TimeUnit.SECONDS) == false); +// latch2.countDown(); +// } catch (Exception e) { +// } +// } +// } +// new Thread(incrementor).start(); +// boolean b = hz.executeTransaction(new TransactionalTask() { +// public Boolean execute(TransactionalTaskContext context) throws TransactionException { +// try { +// final TransactionalMap txMap = context.getMap("testTxnGetForUpdate"); +// txMap.getForUpdate("var"); +// latch1.countDown(); +// latch2.await(100, TimeUnit.SECONDS); +// } catch (Exception e) { +// } +// return true; +// } +// }); +// assertTrue(b); +// assertTrue(pass.get()); +// assertTrue(map.tryPut("var", 1, 0, TimeUnit.SECONDS)); +// } + + TEST_F(RawPointerClientTxnMapTest, testKeySetValues) { + std::string name = "testKeySetValues"; + IMap map = client->getMap(name); + map.put("key1", "value1"); + map.put("key2", "value2"); + + TransactionContext context = client->newTransactionContext(); + context.beginTransaction(); + TransactionalMap originalMap = context.getMap(name); + client::adaptor::RawPointerTransactionalMap txMap(originalMap); + ASSERT_EQ(txMap.put("key3", "value3").get(), (std::string *)NULL); + + + ASSERT_EQ(3, (int)txMap.size()); + ASSERT_EQ(3, (int)txMap.keySet()->size()); + ASSERT_EQ(3, (int)txMap.values()->size()); + context.commitTransaction(); + + ASSERT_EQ(3, (int)map.size()); + ASSERT_EQ(3, (int)map.keySet().size()); + ASSERT_EQ(3, (int)map.values().size()); + + } + + TEST_F(RawPointerClientTxnMapTest, testKeySetAndValuesWithPredicates) { + std::string name = "testKeysetAndValuesWithPredicates"; + IMap map = client->getMap(name); + + Employee emp1("abc-123-xvz", 34); + Employee emp2("abc-123-xvz", 20); + + map.put(emp1, emp1); + + TransactionContext context = client->newTransactionContext(); + context.beginTransaction(); + + TransactionalMap originalMap = context.getMap(name); + client::adaptor::RawPointerTransactionalMap txMap(originalMap); + + ASSERT_EQ(txMap.put(emp2, emp2).get(), (Employee *)NULL); + + ASSERT_EQ(2, (int)txMap.size()); + ASSERT_EQ(2, (int)txMap.keySet()->size()); + query::SqlPredicate predicate("a = 10"); + ASSERT_EQ(0, (int)txMap.keySet(&predicate)->size()); + ASSERT_EQ(0, (int)txMap.values(&predicate)->size()); + predicate.setSql("a >= 10"); + ASSERT_EQ(2, (int)txMap.keySet(&predicate)->size()); + ASSERT_EQ(2, (int)txMap.values(&predicate)->size()); + + context.commitTransaction(); + + ASSERT_EQ(2, (int)map.size()); + ASSERT_EQ(2, (int)map.values().size()); + } + } + } +} + diff --git a/hazelcast/test/src/adaptor/RawPointerTxnMultiMapTest.cpp b/hazelcast/test/src/adaptor/RawPointerTxnMultiMapTest.cpp new file mode 100644 index 0000000000..462d97a418 --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerTxnMultiMapTest.cpp @@ -0,0 +1,80 @@ +/* + * 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 ihsan demir on24/3/16. +#include +#include +#include "HazelcastServerFactory.h" +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/util/CountDownLatch.h" +#include "hazelcast/client/adaptor/RawPointerTransactionalMultiMap.h" + +namespace hazelcast { + namespace client { + namespace test { + namespace adaptor { + class RawPointerTxnMultiMapTest : public ClientTestSupport { + public: + RawPointerTxnMultiMapTest() + : instance(*g_srvFactory) + , client(getNewClient()) { + } + + protected: + HazelcastServer instance; + ClientConfig clientConfig; + std::auto_ptr client; + }; + + void putGetRemoveTestThread(util::ThreadArgs& args) { + MultiMap *mm = (MultiMap *)args.arg0; + HazelcastClient *client = (HazelcastClient *)args.arg1; + util::CountDownLatch *latch = (util::CountDownLatch *)args.arg2; + std::string key = util::IOUtil::to_string(util::Thread::getThreadID()); + client->getMultiMap("testPutGetRemove").put(key, "value"); + TransactionContext context = client->newTransactionContext(); + context.beginTransaction(); + TransactionalMultiMap originalMultiMap = context.getMultiMap("testPutGetRemove"); + client::adaptor::RawPointerTransactionalMultiMap multiMap(originalMultiMap); + ASSERT_FALSE(multiMap.put(key, "value")); + ASSERT_TRUE(multiMap.put(key, "value1")); + ASSERT_TRUE(multiMap.put(key, "value2")); + ASSERT_EQ(3, (int)multiMap.get(key)->size()); + context.commitTransaction(); + + ASSERT_EQ(3, (int)mm->get(key).size()); + + latch->countDown(); + } + + TEST_F(RawPointerTxnMultiMapTest, testPutGetRemove) { + MultiMap mm = client->getMultiMap("testPutGetRemove"); + int n = 10; + util::CountDownLatch latch(n); + std::vector threads(n); + for (int i = 0; i < n; i++) { + threads[i] = new util::Thread(putGetRemoveTestThread, &mm, client.get(), &latch); + } + ASSERT_TRUE(latch.await(1)); + for (int i = 0; i < n; i++) { + delete threads[i] ; + } + } + } + } + } +} + diff --git a/hazelcast/test/src/adaptor/RawPointerTxnQueueTest.cpp b/hazelcast/test/src/adaptor/RawPointerTxnQueueTest.cpp new file mode 100644 index 0000000000..8a30edb4fd --- /dev/null +++ b/hazelcast/test/src/adaptor/RawPointerTxnQueueTest.cpp @@ -0,0 +1,90 @@ +/* + * 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 ihsan demir on 24/3/16. + +#include "ClientTestSupport.h" +#include "HazelcastServer.h" + +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/client/adaptor/RawPointerTransactionalQueue.h" +#include "hazelcast/util/Thread.h" +#include "hazelcast/util/Util.h" + +namespace hazelcast { + namespace client { + namespace test { + namespace adaptor { + class RawPointerTxnQueueTest : public ClientTestSupport { + public: + RawPointerTxnQueueTest() + : instance(*g_srvFactory) + , client(getNewClient()) { + } + + protected: + HazelcastServer instance; + ClientConfig clientConfig; + std::auto_ptr client; + }; + + TEST_F(RawPointerTxnQueueTest, testTransactionalOfferPoll1) { + std::string name = "defQueue"; + + TransactionContext context = client->newTransactionContext(); + context.beginTransaction(); + TransactionalQueue queue = context.getQueue(name); + client::adaptor::RawPointerTransactionalQueue q(queue); + ASSERT_TRUE(q.offer("ali")); + std::auto_ptr item = q.poll(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("ali", *item); + context.commitTransaction(); + ASSERT_EQ(0, client->getQueue(name).size()); + } + + void testTransactionalOfferPoll2Thread(util::ThreadArgs& args) { + util::CountDownLatch *latch = (util::CountDownLatch *)args.arg0; + HazelcastClient *client = (HazelcastClient *)args.arg1; + latch->await(); + client->getQueue("defQueue0").offer("item0"); + } + + TEST_F(RawPointerTxnQueueTest, testTransactionalOfferPoll2) { + util::CountDownLatch latch(1); + util::Thread t(testTransactionalOfferPoll2Thread, &latch, client.get()); + TransactionContext context = client->newTransactionContext(); + context.beginTransaction(); + TransactionalQueue queue0 = context.getQueue("defQueue0"); + client::adaptor::RawPointerTransactionalQueue q0(queue0); + TransactionalQueue queue1 = context.getQueue("defQueue1"); + client::adaptor::RawPointerTransactionalQueue q1(queue1); + latch.countDown(); + std::auto_ptr item = q0.poll(10 * 1000); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("item0", *item); + ASSERT_TRUE(q1.offer(*item)); + + ASSERT_NO_THROW(context.commitTransaction()); + + ASSERT_EQ(0, client->getQueue("defQueue0").size()); + ASSERT_EQ("item0", *(client->getQueue("defQueue1").poll())); + } + } + } + } +} + diff --git a/hazelcast/test/src/multimap/ClientMultiMapTest.cpp b/hazelcast/test/src/multimap/ClientMultiMapTest.cpp index c321d27435..e081474bce 100644 --- a/hazelcast/test/src/multimap/ClientMultiMapTest.cpp +++ b/hazelcast/test/src/multimap/ClientMultiMapTest.cpp @@ -15,9 +15,6 @@ */ // // Created by sancar koyunlu on 8/27/13. - - - #include "hazelcast/util/Util.h" #include "multimap/ClientMultiMapTest.h" #include "hazelcast/client/HazelcastClient.h" diff --git a/hazelcast/test/src/queue/ClientQueueTest.cpp b/hazelcast/test/src/queue/ClientQueueTest.cpp index b1474af6dd..e696f46995 100644 --- a/hazelcast/test/src/queue/ClientQueueTest.cpp +++ b/hazelcast/test/src/queue/ClientQueueTest.cpp @@ -74,7 +74,7 @@ namespace hazelcast { IQueue *q = (IQueue *) args.arg0; util::sleep(2); q->offer("item1"); - std::cout << "item1 is offered" << std::endl; + util::ILogger::getLogger().info("[testOfferPollThread2] item1 is offered"); } TEST_F(ClientQueueTest, testOfferPoll) { @@ -100,6 +100,43 @@ namespace hazelcast { t2.join(); } + TEST_F(ClientQueueTest, testPeek) { + ASSERT_TRUE(q->offer("peek 1")); + ASSERT_TRUE(q->offer("peek 2")); + ASSERT_TRUE(q->offer("peek 3")); + + boost::shared_ptr item = q->peek(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 1", *item); + } + + TEST_F(ClientQueueTest, testTake) { + ASSERT_TRUE(q->offer("peek 1")); + ASSERT_TRUE(q->offer("peek 2")); + ASSERT_TRUE(q->offer("peek 3")); + + boost::shared_ptr item = q->take(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 1", *item); + + item = q->take(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 2", *item); + + item = q->take(); + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("peek 3", *item); + + ASSERT_TRUE(q->isEmpty()); + + // start a thread to insert an item + util::Thread t2(testOfferPollThread2, q.get()); + + item = q->take(); // should block till it gets an item + ASSERT_NE((std::string *)NULL, item.get()); + ASSERT_EQ("item1", *item); + } + TEST_F(ClientQueueTest, testRemainingCapacity) { int capacity = q->remainingCapacity(); ASSERT_TRUE(capacity > 10000); @@ -179,7 +216,6 @@ namespace hazelcast { for (size_t i = 0; i < size; i++) { ASSERT_EQ(std::string("item") + util::IOUtil::to_string(i + 1), array[i]); } - } TEST_F(ClientQueueTest, testAddAll) { diff --git a/hazelcast/test/src/queue/ClientQueueTest.h b/hazelcast/test/src/queue/ClientQueueTest.h index e5ff300750..215184c166 100644 --- a/hazelcast/test/src/queue/ClientQueueTest.h +++ b/hazelcast/test/src/queue/ClientQueueTest.h @@ -15,10 +15,6 @@ */ // // Created by sancar koyunlu on 9/4/13. - - - - #ifndef HAZELCAST_ClientQueueTest #define HAZELCAST_ClientQueueTest diff --git a/hazelcast/test/src/serialization/ClientSerializationTest.cpp b/hazelcast/test/src/serialization/ClientSerializationTest.cpp index 57124f0990..49a6c17afa 100644 --- a/hazelcast/test/src/serialization/ClientSerializationTest.cpp +++ b/hazelcast/test/src/serialization/ClientSerializationTest.cpp @@ -16,8 +16,6 @@ // // Created by sancar koyunlu on 8/27/13. - - #include "customSerialization/TestCustomSerializerX.h" #include "customSerialization/TestCustomXSerializable.h" #include "customSerialization/TestCustomPersonSerializer.h" @@ -59,13 +57,13 @@ namespace hazelcast { TestCustomXSerializable a(131321); serialization::pimpl::Data data = serializationService.toData(&a); - boost::shared_ptr a2 = serializationService.toObject( + std::auto_ptr a2 = serializationService.toObject( data); ASSERT_EQ(a, *a2); TestCustomPerson b("TestCustomPerson"); serialization::pimpl::Data data1 = serializationService.toData(&b); - boost::shared_ptr b2 = serializationService.toObject(data1); + std::auto_ptr b2 = serializationService.toObject(data1); ASSERT_EQ(b, *b2); } @@ -83,7 +81,7 @@ namespace hazelcast { TestRawDataPortable p(123213, chars, np, 22, "Testing raw portable", ds); serialization::pimpl::Data data = serializationService.toData(&p); - boost::shared_ptr x = serializationService.toObject(data); + std::auto_ptr x = serializationService.toObject(data); ASSERT_EQ(p, *x); } @@ -95,13 +93,13 @@ namespace hazelcast { TestDataSerializable np(4, 'k'); data = serializationService.toData(&np); - boost::shared_ptr tnp1; + std::auto_ptr tnp1; tnp1 = serializationService.toObject(data); ASSERT_EQ(np, *tnp1); int x = 4; data = serializationService.toData(&x); - boost::shared_ptr ptr = serializationService.toObject(data); + std::auto_ptr ptr = serializationService.toObject(data); int y = *ptr; ASSERT_EQ(x, y); } @@ -119,7 +117,7 @@ namespace hazelcast { TestRawDataPortable p(123213, chars, np, 22, "Testing raw portable", ds); serialization::pimpl::Data data = serializationService.toData(&p); - boost::shared_ptr x = serializationService.toObject(data); + std::auto_ptr x = serializationService.toObject(data); ASSERT_EQ(p, *x); } @@ -159,12 +157,12 @@ namespace hazelcast { TestNamedPortableV2 p2("portable-v2", 123); serialization::pimpl::Data data2 = serializationService2.toData(&p2); - boost::shared_ptr t2 = serializationService2.toObject(data); + std::auto_ptr t2 = serializationService2.toObject(data); ASSERT_EQ(std::string("portable-v1"), t2->name); ASSERT_EQ(111, t2->k); ASSERT_EQ(0, t2->v); - boost::shared_ptr t1 = serializationService.toObject(data2); + std::auto_ptr t1 = serializationService.toObject(data2); ASSERT_EQ(std::string("portable-v2"), t1->name); ASSERT_EQ(123 * 10, t1->k); @@ -179,19 +177,19 @@ namespace hazelcast { int x = 3; data = serializationService.toData(&x); - boost::shared_ptr returnedInt = serializationService.toObject(data); + std::auto_ptr returnedInt = serializationService.toObject(data); ASSERT_EQ(x, *returnedInt); short f = 2; data = serializationService.toData(&f); - boost::shared_ptr temp = serializationService.toObject(data); + std::auto_ptr temp = serializationService.toObject(data); ASSERT_EQ(f, *temp); TestNamedPortable np("name", 5); data = serializationService.toData(&np); - boost::shared_ptr tnp1, tnp2; + std::auto_ptr tnp1, tnp2; tnp1 = serializationService.toObject(data); tnp2 = serializationService.toObject(data); @@ -224,7 +222,7 @@ namespace hazelcast { data = serializationService.toData(&inner); - boost::shared_ptr tip1, tip2; + std::auto_ptr tip1, tip2; tip1 = serializationService.toObject(data); tip2 = serializationService.toObject(data); @@ -236,7 +234,7 @@ namespace hazelcast { "this is main portable object created for testing!", inner); data = serializationService.toData(&main); - boost::shared_ptr tmp1, tmp2; + std::auto_ptr tmp1, tmp2; tmp1 = serializationService.toObject(data); tmp2 = serializationService.toObject(data); @@ -283,7 +281,7 @@ namespace hazelcast { data = serializationService.toData(&inner); - boost::shared_ptr tip1, tip2; + std::auto_ptr tip1, tip2; tip1 = serializationService.toObject(data); tip2 = serializationService.toObject(data); @@ -306,19 +304,19 @@ namespace hazelcast { int x = 3; data = serializationService.toData(&x); - boost::shared_ptr returnedInt = serializationService.toObject(data); + std::auto_ptr returnedInt = serializationService.toObject(data); ASSERT_EQ(x, *returnedInt); short f = 2; data = serializationService.toData(&f); - boost::shared_ptr temp = serializationService.toObject(data); + std::auto_ptr temp = serializationService.toObject(data); ASSERT_EQ(f, *temp); TestNamedPortable np("name", 5); data = serializationService.toData(&np); - boost::shared_ptr tnp1, tnp2; + std::auto_ptr tnp1, tnp2; tnp1 = serializationService.toObject(data); tnp2 = serializationService2.toObject(data); @@ -351,7 +349,7 @@ namespace hazelcast { data = serializationService.toData(&inner); - boost::shared_ptr tip1, tip2; + std::auto_ptr tip1, tip2; tip1 = serializationService.toObject(data); tip2 = serializationService2.toObject(data); @@ -363,7 +361,7 @@ namespace hazelcast { "this is main portable object created for testing!", inner); data = serializationService.toData(&main); - boost::shared_ptr tmp1, tmp2; + std::auto_ptr tmp1, tmp2; tmp1 = serializationService.toObject(data); tmp2 = serializationService2.toObject(data); @@ -463,7 +461,7 @@ namespace hazelcast { ObjectCarryingPortable objectCarryingPortable(namedPortable); serialization::pimpl::Data data = ss.toData >( &objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >( + std::auto_ptr > ptr = ss.toObject >( data); ASSERT_EQ(objectCarryingPortable, *ptr); } @@ -476,7 +474,7 @@ namespace hazelcast { ObjectCarryingPortable objectCarryingPortable(testDataSerializable); serialization::pimpl::Data data = ss.toData >( &objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >( + std::auto_ptr > ptr = ss.toObject >( data); ASSERT_EQ(objectCarryingPortable, *ptr); } @@ -493,7 +491,7 @@ namespace hazelcast { ObjectCarryingPortable objectCarryingPortable(customXSerializable); serialization::pimpl::Data data = ss.toData >( &objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >( + std::auto_ptr > ptr = ss.toObject >( data); ASSERT_EQ(objectCarryingPortable, *ptr); } @@ -510,7 +508,7 @@ namespace hazelcast { ObjectCarryingPortable objectCarryingPortable(testCustomPerson); serialization::pimpl::Data data = ss.toData >( &objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >( + std::auto_ptr > ptr = ss.toObject >( data); ASSERT_EQ(objectCarryingPortable, *ptr); } @@ -520,7 +518,7 @@ namespace hazelcast { serialization::pimpl::Data data; SerializationConfig serializationConfig; serialization::pimpl::SerializationService ss(serializationConfig); - boost::shared_ptr ptr = ss.toObject(data); + std::auto_ptr ptr = ss.toObject(data); ASSERT_EQ(ptr.get(), (int *)NULL); } @@ -536,7 +534,7 @@ namespace hazelcast { TestNamedPortableV3 p2("portable-v2", 123); serialization::pimpl::Data data2 = serializationService2.toData(&p2); - boost::shared_ptr t1 = serializationService.toObject(data2); + std::auto_ptr t1 = serializationService.toObject(data2); ASSERT_EQ(std::string("portable-v2"), t1->name); ASSERT_EQ(123, t1->k); } diff --git a/hazelcast/test/src/set/ClientSetTest.cpp b/hazelcast/test/src/set/ClientSetTest.cpp index d8e15fce59..e2a6f20a42 100644 --- a/hazelcast/test/src/set/ClientSetTest.cpp +++ b/hazelcast/test/src/set/ClientSetTest.cpp @@ -23,6 +23,24 @@ namespace hazelcast { namespace client { namespace test { + class MySetItemListener : public ItemListener { + public: + MySetItemListener(util::CountDownLatch &latch) + :latch(latch) { + + } + + void itemAdded(const ItemEvent& itemEvent) { + latch.countDown(); + } + + void itemRemoved(const ItemEvent& item) { + } + + private: + util::CountDownLatch &latch; + }; + ClientSetTest::ClientSetTest() : instance(*g_srvFactory) , client(getNewClient()) @@ -33,6 +51,17 @@ namespace hazelcast { ClientSetTest::~ClientSetTest() { } + bool ClientSetTest::itemExists(const std::vector &items, const std::string &item) const { + bool found = false; + for (std::vector::const_iterator it = items.begin();it != items.end();++it) { + if (item == *it) { + found = true; + break; + } + } + return found; + } + TEST_F(ClientSetTest, testAddAll) { std::vector l; l.push_back("item1"); @@ -79,7 +108,22 @@ namespace hazelcast { ASSERT_TRUE(set->containsAll(l)); } + TEST_F(ClientSetTest, testToArray) { + ASSERT_TRUE(set->add("item1")); + ASSERT_TRUE(set->add("item2")); + ASSERT_TRUE(set->add("item3")); + ASSERT_TRUE(set->add("item4")); + ASSERT_FALSE(set->add("item4")); + + std::vector items = set->toArray(); + ASSERT_EQ((size_t)4, items.size()); + ASSERT_TRUE(itemExists(items, "item1")); + ASSERT_TRUE(itemExists(items, "item2")); + ASSERT_TRUE(itemExists(items, "item3")); + ASSERT_TRUE(itemExists(items, "item4")); + } + TEST_F(ClientSetTest, testRemoveRetainAll) { ASSERT_TRUE(set->add("item1")); ASSERT_TRUE(set->add("item2")); @@ -106,26 +150,7 @@ namespace hazelcast { ASSERT_EQ(0, set->size()); } - - class MySetItemListener : public ItemListener { - public: - MySetItemListener(util::CountDownLatch &latch) - :latch(latch) { - - } - - void itemAdded(const ItemEvent& itemEvent) { - latch.countDown(); - } - - void itemRemoved(const ItemEvent& item) { - } - - private: - util::CountDownLatch &latch; - }; - - + TEST_F(ClientSetTest, testListener) { util::CountDownLatch latch(6); diff --git a/hazelcast/test/src/set/ClientSetTest.h b/hazelcast/test/src/set/ClientSetTest.h index 54326c0a1d..c759e30e82 100644 --- a/hazelcast/test/src/set/ClientSetTest.h +++ b/hazelcast/test/src/set/ClientSetTest.h @@ -15,10 +15,6 @@ */ // // Created by sancar koyunlu on 9/13/13. - - - - #ifndef HAZELCAST_ClientSetTest #define HAZELCAST_ClientSetTest @@ -42,6 +38,8 @@ namespace hazelcast { ClientConfig clientConfig; std::auto_ptr client; std::auto_ptr > set; + + bool itemExists(const std::vector &items, const std::string &item) const; }; } } diff --git a/hazelcast/test/src/txn/ClientTxnMapTest.h b/hazelcast/test/src/txn/ClientTxnMapTest.h index 12d93d1d0e..1d52f68114 100644 --- a/hazelcast/test/src/txn/ClientTxnMapTest.h +++ b/hazelcast/test/src/txn/ClientTxnMapTest.h @@ -16,9 +16,6 @@ // // Created by sancar koyunlu on 9/18/13. - - - #ifndef HAZELCAST_ClientTxnMapTest #define HAZELCAST_ClientTxnMapTest @@ -42,7 +39,6 @@ namespace hazelcast { ClientConfig clientConfig; std::auto_ptr client; }; - } } } diff --git a/hazelcast/test/src/txn/ClientTxnMultiMapTest.h b/hazelcast/test/src/txn/ClientTxnMultiMapTest.h index a9b3a35b65..b6a896349d 100644 --- a/hazelcast/test/src/txn/ClientTxnMultiMapTest.h +++ b/hazelcast/test/src/txn/ClientTxnMultiMapTest.h @@ -15,10 +15,6 @@ */ // // Created by sancar koyunlu on 9/18/13. - - - - #ifndef HAZELCAST_ClientTxnMultiMApTest #define HAZELCAST_ClientTxnMultiMApTest @@ -28,7 +24,6 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { @@ -43,7 +38,6 @@ namespace hazelcast { ClientConfig clientConfig; std::auto_ptr client; }; - } } } diff --git a/hazelcast/test/src/txn/ClientTxnQueueTest.cpp b/hazelcast/test/src/txn/ClientTxnQueueTest.cpp index bd30eff614..3e360d3767 100644 --- a/hazelcast/test/src/txn/ClientTxnQueueTest.cpp +++ b/hazelcast/test/src/txn/ClientTxnQueueTest.cpp @@ -63,7 +63,7 @@ namespace hazelcast { latch.countDown(); s = q0.poll(10 * 1000); ASSERT_EQ("item0", *s); - q1.offer(*s); + ASSERT_TRUE(q1.offer(*s)); ASSERT_NO_THROW(context.commitTransaction());