Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
RawPointerMultiMap.h
1 /*
2  * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMULTIMAP_H_
17 #define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMULTIMAP_H_
18 
19 #include "hazelcast/client/MultiMap.h"
20 #include "hazelcast/client/impl/DataArrayImpl.h"
21 #include "hazelcast/client/impl/EntryArrayImpl.h"
22 
23 namespace hazelcast {
24  namespace client {
25  namespace adaptor {
31  template<typename K, typename V>
33  public:
34  RawPointerMultiMap(MultiMap<K, V> &m) :map(m), serializationService(m.context->getSerializationService()) {
35  }
36 
46  bool put(const K &key, const V &value) {
47  return map.put(key, value);
48  }
49 
56  std::auto_ptr<DataArray<V> > get(const K &key) {
57  return std::auto_ptr<DataArray<V> >(new impl::DataArrayImpl<V>(map.getData(serializationService.toData<K>(&key)), serializationService));
58  }
59 
67  bool remove(const K &key, const V &value) {
68  return map.remove(key, value);
69  }
70 
78  std::auto_ptr<DataArray<V> > remove(const K &key) {
79  return std::auto_ptr<DataArray<V> >(new impl::DataArrayImpl<V>(map.removeData(serializationService.toData<K>(&key)), serializationService));
80  }
81 
88  std::auto_ptr<DataArray<K> > keySet() {
89  return std::auto_ptr<DataArray<K> >(new impl::DataArrayImpl<K>(map.keySetData(), serializationService));
90  }
91 
98  std::auto_ptr<DataArray<V> > values() {
99  return std::auto_ptr<DataArray<V> >(new impl::DataArrayImpl<V>(map.valuesData(), serializationService));
100  }
101 
108  std::auto_ptr<EntryArray<K, V> > entrySet() {
109  return std::auto_ptr<EntryArray<K, V> >(new impl::EntryArrayImpl<K, V>(map.entrySetData(), serializationService)) ;
110  }
111 
118  bool containsKey(const K &key) {
119  return map.containsKey(key);
120  }
121 
128  bool containsValue(const V &value) {
129  return map.containsValue(value);
130  }
131 
139  bool containsEntry(const K &key, const V &value) {
140  return map.containsEntry(key, value);
141  }
142 
148  int size() {
149  return map.size();
150  }
151 
155  void clear() {
156  map.clear();
157  }
158 
166  int valueCount(const K &key) {
167  return map.valueCount(key);
168  }
169 
184  std::string addEntryListener(EntryListener<K, V> &listener, bool includeValue) {
185  return map.addEntryListener(listener, includeValue);
186  }
187 
204  std::string addEntryListener(EntryListener<K, V> &listener, const K &key, bool includeValue) {
205  return map.addEntryListener(listener, key, includeValue);
206  }
207 
216  bool removeEntryListener(const std::string &registrationId) {
217  return map.removeEntryListener(registrationId);
218  }
219 
235  void lock(const K &key) {
236  map.lock(key);
237  }
238 
255  void lock(const K &key, long leaseTimeInMillis) {
256  map.lock(key, leaseTimeInMillis);
257  }
258 
266  bool isLocked(const K &key) {
267  return map.isLocked(key);
268  }
269 
279  bool tryLock(const K &key) {
280  return map.tryLock(key);
281  }
282 
299  bool tryLock(const K &key, long timeoutInMillis) {
300  return map.tryLock(key, timeoutInMillis);
301  }
302 
310  void unlock(const K &key) {
311  map.unlock(key);
312  }
313 
320  void forceUnlock(const K &key) {
321  map.forceUnlock(key);
322  }
323 
324  private:
325  MultiMap<K, V> &map;
326  serialization::pimpl::SerializationService &serializationService;
327  };
328  }
329  }
330 }
331 
332 #endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMULTIMAP_H_ */
333 
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: RawPointerMultiMap.h:204
Map Entry listener to get notified when a map entry is added, removed, updated or evicted...
Definition: EntryListener.h:45
void lock(const K &key)
Acquires the lock for the specified key.
Definition: RawPointerMultiMap.h:235
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: RawPointerMultiMap.h:266
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: RawPointerMultiMap.h:320
bool tryLock(const K &key, long timeoutInMillis)
Tries to acquire the lock for the specified key.
Definition: RawPointerMultiMap.h:299
A specialized distributed map client whose keys can be associated with multiple values.
Definition: MultiMap.h:41
void unlock(const K &key)
Releases the lock for the specified key.
Definition: RawPointerMultiMap.h:310
std::auto_ptr< DataArray< K > > keySet()
Returns the set of keys in the multimap.
Definition: RawPointerMultiMap.h:88
int size()
Returns the number of key-value pairs in the multimap.
Definition: RawPointerMultiMap.h:148
void clear()
Clears the multimap.
Definition: RawPointerMultiMap.h:155
bool containsEntry(const K &key, const V &value)
Returns whether the multimap contains the given key-value pair.
Definition: RawPointerMultiMap.h:139
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this multimap.
Definition: RawPointerMultiMap.h:184
std::auto_ptr< EntryArray< K, V > > entrySet()
Returns the set of key-value pairs in the multimap.
Definition: RawPointerMultiMap.h:108
bool put(const K &key, const V &value)
Stores a key-value pair in the multimap.
Definition: RawPointerMultiMap.h:46
bool containsValue(const V &value)
Returns whether the multimap contains an entry with the value.
Definition: RawPointerMultiMap.h:128
std::auto_ptr< DataArray< V > > values()
Returns the multimap of values in the multimap.
Definition: RawPointerMultiMap.h:98
int valueCount(const K &key)
Returns number of values matching to given key in the multimap.
Definition: RawPointerMultiMap.h:166
void lock(const K &key, long leaseTimeInMillis)
Acquires the lock for the specified key for the specified lease time.
Definition: RawPointerMultiMap.h:255
A specialized distributed map client whose keys can be associated with multiple values.
Definition: RawPointerMultiMap.h:32
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: RawPointerMultiMap.h:279
bool removeEntryListener(const std::string &registrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: RawPointerMultiMap.h:216
bool containsKey(const K &key)
Returns whether the multimap contains an entry with the key.
Definition: RawPointerMultiMap.h:118