Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
RawPointerQueue.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_RAWPOINTERQUEUE_H_
17 #define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERQUEUE_H_
18 
19 #include <memory>
20 
21 #include "hazelcast/client/IQueue.h"
22 #include "hazelcast/client/impl/DataArrayImpl.h"
23 
24 namespace hazelcast {
25  namespace client {
26  namespace adaptor {
32  template<typename T>
34  public:
35  RawPointerQueue(IQueue<T> &q) : queue(q), serializationService(q.context->getSerializationService()) {
36  }
37 
52  std::string addItemListener(ItemListener<T> &listener, bool includeValue) {
53  return queue.addItemListener(listener, includeValue);
54  }
55 
64  bool removeItemListener(const std::string &registrationId) {
65  return queue.removeItemListener(registrationId);
66  }
67 
76  bool offer(const T &element) {
77  return queue.offer(element, 0);
78  }
79 
84  void put(const T &e) {
85  queue.offer(e, -1);
86  }
87 
97  bool offer(const T &element, long timeoutInMillis) {
98  return queue.offer(element, timeoutInMillis);
99  }
100 
105  std::auto_ptr<T> take() {
106  return serializationService.toObject<T>(queue.pollData(-1).get());
107  }
108 
114  std::auto_ptr<T> poll(long timeoutInMillis) {
115  return serializationService.toObject<T>(queue.pollData(timeoutInMillis).get());
116  }
117 
123  return queue.remainingCapacity();
124  }
125 
131  bool remove(const T &element) {
132  return queue.remove(element);
133  }
134 
140  bool contains(const T &element) {
141  return queue.contains(element);
142  }
143 
148  std::auto_ptr<DataArray<T> > drainTo() {
149  return std::auto_ptr<DataArray<T> >(new hazelcast::client::impl::DataArrayImpl<T>(queue.drainToData(-1), serializationService));
150  }
151 
157  std::auto_ptr<DataArray<T> > drainTo(size_t maxElements) {
158  return std::auto_ptr<DataArray<T> >(new hazelcast::client::impl::DataArrayImpl<T>(queue.drainToData(maxElements), serializationService));
159  }
160 
166  std::auto_ptr<T> poll() {
167  return serializationService.toObject<T>(queue.pollData(0).get());
168  }
169 
175  std::auto_ptr<T> peek() {
176  return serializationService.toObject<T>(queue.peekData().get());
177  }
178 
183  int size() {
184  return queue.size();
185  }
186 
191  bool isEmpty() {
192  return queue.isEmpty();
193  }
194 
199  std::auto_ptr<DataArray<T> > toArray() {
200  return std::auto_ptr<DataArray<T> >(new hazelcast::client::impl::DataArrayImpl<T>(queue.toArrayData(), serializationService));
201  }
202 
209  bool containsAll(const std::vector<T> &elements) {
210  return queue.containsAll(elements);
211  }
212 
219  bool addAll(const std::vector<T> &elements) {
220  return queue.addAll(elements);
221  }
222 
229  bool removeAll(const std::vector<T> &elements) {
230  return queue.removeAll(elements);
231  }
232 
240  bool retainAll(const std::vector<T> &elements) {
241  return queue.retainAll(elements);
242  }
243 
247  void clear() {
248  queue.clear();
249  }
250 
251  private:
252  IQueue<T> &queue;
253  serialization::pimpl::SerializationService &serializationService;
254  };
255  }
256 
257  }
258 }
259 
260 #endif /* HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERQUEUE_H_ */
261 
void clear()
Removes all elements from queue.
Definition: IQueue.h:270
bool removeItemListener(const std::string &registrationId)
Removes the specified item listener.
Definition: RawPointerQueue.h:64
bool offer(const E &element)
Inserts the specified element into this queue.
Definition: IQueue.h:85
Concurrent, blocking, distributed, observable, client queue.
Definition: RawPointerQueue.h:33
bool isEmpty()
Definition: RawPointerQueue.h:191
bool contains(const E &element)
Definition: IQueue.h:150
std::string addItemListener(ItemListener< T > &listener, bool includeValue)
Adds an item listener for this collection.
Definition: RawPointerQueue.h:52
bool removeAll(const std::vector< E > &elements)
Definition: IQueue.h:250
std::auto_ptr< T > poll(long timeoutInMillis)
Definition: RawPointerQueue.h:114
int remainingCapacity()
Definition: RawPointerQueue.h:122
int remainingCapacity()
Definition: IQueue.h:132
std::auto_ptr< T > peek()
Returns immediately without waiting.
Definition: RawPointerQueue.h:175
bool removeItemListener(const std::string &registrationId)
Removes the specified item listener.
Definition: IQueue.h:73
std::auto_ptr< DataArray< T > > toArray()
Definition: RawPointerQueue.h:199
std::string addItemListener(ItemListener< E > &listener, bool includeValue)
Adds an item listener for this collection.
Definition: IQueue.h:57
bool retainAll(const std::vector< T > &elements)
Removes the elements from this queue that are not available in given "elements" vector.
Definition: RawPointerQueue.h:240
std::auto_ptr< DataArray< T > > drainTo()
Definition: RawPointerQueue.h:148
bool contains(const T &element)
Definition: RawPointerQueue.h:140
int size()
Definition: IQueue.h:202
bool offer(const T &element)
Inserts the specified element into this queue.
Definition: RawPointerQueue.h:76
int size()
Definition: RawPointerQueue.h:183
bool isEmpty()
Definition: IQueue.h:210
bool retainAll(const std::vector< E > &elements)
Removes the elements from this queue that are not available in given "elements" vector.
Definition: IQueue.h:262
std::auto_ptr< T > take()
Definition: RawPointerQueue.h:105
Item listener for IQueue, ISet and IList.
Definition: ItemListener.h:40
void put(const T &e)
Puts the element into queue.
Definition: RawPointerQueue.h:84
std::auto_ptr< T > poll()
Returns immediately without waiting.
Definition: RawPointerQueue.h:166
bool containsAll(const std::vector< E > &elements)
Definition: IQueue.h:228
bool containsAll(const std::vector< T > &elements)
Definition: RawPointerQueue.h:209
bool addAll(const std::vector< E > &elements)
Definition: IQueue.h:239
bool offer(const T &element, long timeoutInMillis)
Inserts the specified element into this queue.
Definition: RawPointerQueue.h:97
bool removeAll(const std::vector< T > &elements)
Definition: RawPointerQueue.h:229
std::auto_ptr< DataArray< T > > drainTo(size_t maxElements)
Definition: RawPointerQueue.h:157
bool remove(const E &element)
Definition: IQueue.h:141
void clear()
Removes all elements from queue.
Definition: RawPointerQueue.h:247
bool addAll(const std::vector< T > &elements)
Definition: RawPointerQueue.h:219