Hazelcast C++ Client
RawPointerMultiMap.h
1 /*
2  * Copyright (c) 2008-2017, 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 hazelcast::client::impl::DataArrayImpl<V>(
58  map.getData(serializationService.toData<K>(&key)), serializationService));
59  }
60 
68  bool remove(const K &key, const V &value) {
69  return map.remove(key, value);
70  }
71 
79  std::auto_ptr<DataArray<V> > remove(const K &key) {
80  return std::auto_ptr<DataArray<V> >(new hazelcast::client::impl::DataArrayImpl<V>(
81  map.removeData(serializationService.toData<K>(&key)), serializationService));
82  }
83 
90  std::auto_ptr<DataArray<K> > keySet() {
91  return std::auto_ptr<DataArray<K> >(new hazelcast::client::impl::DataArrayImpl<K>(
92  map.keySetData(), serializationService));
93  }
94 
101  std::auto_ptr<DataArray<V> > values() {
102  return std::auto_ptr<DataArray<V> >(new hazelcast::client::impl::DataArrayImpl<V>(
103  map.valuesData(), serializationService));
104  }
105 
112  std::auto_ptr<EntryArray<K, V> > entrySet() {
113  return std::auto_ptr<EntryArray<K, V> >(new hazelcast::client::impl::EntryArrayImpl<K, V>(
114  map.entrySetData(), serializationService)) ;
115  }
116 
123  bool containsKey(const K &key) {
124  return map.containsKey(key);
125  }
126 
133  bool containsValue(const V &value) {
134  return map.containsValue(value);
135  }
136 
144  bool containsEntry(const K &key, const V &value) {
145  return map.containsEntry(key, value);
146  }
147 
153  int size() {
154  return map.size();
155  }
156 
160  void clear() {
161  map.clear();
162  }
163 
171  int valueCount(const K &key) {
172  return map.valueCount(key);
173  }
174 
189  std::string addEntryListener(EntryListener<K, V> &listener, bool includeValue) {
190  return map.addEntryListener(listener, includeValue);
191  }
192 
209  std::string addEntryListener(EntryListener<K, V> &listener, const K &key, bool includeValue) {
210  return map.addEntryListener(listener, key, includeValue);
211  }
212 
221  bool removeEntryListener(const std::string &registrationId) {
222  return map.removeEntryListener(registrationId);
223  }
224 
240  void lock(const K &key) {
241  map.lock(key);
242  }
243 
260  void lock(const K &key, long leaseTimeInMillis) {
261  map.lock(key, leaseTimeInMillis);
262  }
263 
271  bool isLocked(const K &key) {
272  return map.isLocked(key);
273  }
274 
284  bool tryLock(const K &key) {
285  return map.tryLock(key);
286  }
287 
304  bool tryLock(const K &key, long timeoutInMillis) {
305  return map.tryLock(key, timeoutInMillis);
306  }
307 
315  void unlock(const K &key) {
316  map.unlock(key);
317  }
318 
325  void forceUnlock(const K &key) {
326  map.forceUnlock(key);
327  }
328 
329  private:
330  MultiMap<K, V> &map;
331  serialization::pimpl::SerializationService &serializationService;
332  };
333  }
334  }
335 }
336 
337 #endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMULTIMAP_H_ */
338 
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: RawPointerMultiMap.h:209
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:240
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: RawPointerMultiMap.h:271
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: RawPointerMultiMap.h:325
bool tryLock(const K &key, long timeoutInMillis)
Tries to acquire the lock for the specified key.
Definition: RawPointerMultiMap.h:304
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:315
std::auto_ptr< DataArray< K > > keySet()
Returns the set of keys in the multimap.
Definition: RawPointerMultiMap.h:90
int size()
Returns the number of key-value pairs in the multimap.
Definition: RawPointerMultiMap.h:153
void clear()
Clears the multimap.
Definition: RawPointerMultiMap.h:160
bool containsEntry(const K &key, const V &value)
Returns whether the multimap contains the given key-value pair.
Definition: RawPointerMultiMap.h:144
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this multimap.
Definition: RawPointerMultiMap.h:189
std::auto_ptr< EntryArray< K, V > > entrySet()
Returns the set of key-value pairs in the multimap.
Definition: RawPointerMultiMap.h:112
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:133
std::auto_ptr< DataArray< V > > values()
Returns the multimap of values in the multimap.
Definition: RawPointerMultiMap.h:101
int valueCount(const K &key)
Returns number of values matching to given key in the multimap.
Definition: RawPointerMultiMap.h:171
void lock(const K &key, long leaseTimeInMillis)
Acquires the lock for the specified key for the specified lease time.
Definition: RawPointerMultiMap.h:260
A specialized distributed map client whose keys can be associated with multiple values.
Definition: RawPointerMultiMap.h:32
Definition: MapEntryView.h:32
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: RawPointerMultiMap.h:284
bool removeEntryListener(const std::string &registrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: RawPointerMultiMap.h:221
bool containsKey(const K &key)
Returns whether the multimap contains an entry with the key.
Definition: RawPointerMultiMap.h:123