Hazelcast C++ Client
Hazelcast C++ Client Library
iqueue.h
1 /*
2  * Copyright (c) 2008-2022, 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 #pragma once
17 
18 #include "hazelcast/client/item_listener.h"
19 #include "hazelcast/client/proxy/IQueueImpl.h"
20 #include "hazelcast/client/impl/ItemEventHandler.h"
21 #include "hazelcast/client/protocol/codec/codecs.h"
22 
23 namespace hazelcast {
24 namespace client {
29 class iqueue : public proxy::IQueueImpl
30 {
31  friend class spi::ProxyManager;
32 
33 public:
34  static constexpr const char* SERVICE_NAME = "hz:impl:queueService";
35 
50  boost::future<boost::uuids::uuid> add_item_listener(
51  item_listener&& listener,
52  bool include_value)
53  {
54  std::unique_ptr<
55  impl::item_event_handler<protocol::codec::queue_addlistener_handler>>
56  itemEventHandler(new impl::item_event_handler<
57  protocol::codec::queue_addlistener_handler>(
58  get_name(),
59  get_context().get_client_cluster_service(),
60  get_context().get_serialization_service(),
61  std::move(listener),
62  include_value));
63 
64  return proxy::IQueueImpl::add_item_listener(std::move(itemEventHandler),
65  include_value);
66  }
67 
75  template<typename E>
76  boost::future<bool> offer(const E& element)
77  {
78  return offer(element, std::chrono::milliseconds(0));
79  }
80 
85  template<typename E>
86  boost::future<void> put(const E& element)
87  {
88  return proxy::IQueueImpl::put(to_data(element));
89  }
90 
100  template<typename E>
101  boost::future<bool> offer(const E& element,
102  std::chrono::milliseconds timeout)
103  {
104  return proxy::IQueueImpl::offer(to_data(element), timeout);
105  }
106 
112  template<typename E>
113  boost::future<boost::optional<E>> take()
114  {
115  return to_object<E>(proxy::IQueueImpl::take_data());
116  }
117 
124  template<typename E>
125  boost::future<boost::optional<E>> poll(std::chrono::milliseconds timeout)
126  {
127  return to_object<E>(proxy::IQueueImpl::poll_data(timeout));
128  }
129 
135  template<typename E>
136  boost::future<bool> remove(const E& element)
137  {
138  return proxy::IQueueImpl::remove(to_data(element));
139  }
140 
146  template<typename E>
147  boost::future<bool> contains(const E& element)
148  {
149  return proxy::IQueueImpl::contains(to_data(element));
150  }
151 
158  template<typename E>
159  boost::future<size_t> drain_to(std::vector<E>& elements)
160  {
161  return to_object_drain(proxy::IQueueImpl::drain_to_data(), elements);
162  }
163 
171  template<typename E>
172  boost::future<size_t> drain_to(std::vector<E>& elements,
173  size_t max_elements)
174  {
175  return to_object_drain(proxy::IQueueImpl::drain_to_data(max_elements),
176  elements);
177  }
178 
185  template<typename E>
186  boost::future<boost::optional<E>> poll()
187  {
188  return poll<E>(std::chrono::milliseconds(0));
189  }
190 
197  template<typename E>
198  boost::future<boost::optional<E>> peek()
199  {
200  return to_object<E>(proxy::IQueueImpl::peek_data());
201  }
202 
207  template<typename E>
208  boost::future<std::vector<E>> to_array()
209  {
210  return to_object_vector<E>(proxy::IQueueImpl::to_array_data());
211  }
212 
218  template<typename E>
219  boost::future<bool> contains_all(const std::vector<E>& elements)
220  {
221  return proxy::IQueueImpl::contains_all_data(
222  to_data_collection(elements));
223  }
224 
230  template<typename E>
231  boost::future<bool> add_all(const std::vector<E>& elements)
232  {
233  return proxy::IQueueImpl::add_all_data(to_data_collection(elements));
234  }
235 
241  template<typename E>
242  boost::future<bool> remove_all(const std::vector<E>& elements)
243  {
244  return proxy::IQueueImpl::remove_all_data(to_data_collection(elements));
245  }
246 
254  template<typename E>
255  boost::future<bool> retain_all(const std::vector<E>& elements)
256  {
257  return proxy::IQueueImpl::retain_all_data(to_data_collection(elements));
258  }
259 
260 private:
261  iqueue(const std::string& instance_name, spi::ClientContext* context)
262  : proxy::IQueueImpl(instance_name, context)
263  {}
264 };
265 } // namespace client
266 } // namespace hazelcast
Concurrent, blocking, distributed, observable, client queue.
Definition: iqueue.h:30
boost::future< boost::optional< E > > poll(std::chrono::milliseconds timeout)
Definition: iqueue.h:125
boost::future< bool > remove(const E &element)
Definition: iqueue.h:136
boost::future< bool > contains(const E &element)
Definition: iqueue.h:147
boost::future< boost::optional< E > > peek()
Returns immediately without waiting.
Definition: iqueue.h:198
boost::future< bool > add_all(const std::vector< E > &elements)
Definition: iqueue.h:231
boost::future< size_t > drain_to(std::vector< E > &elements, size_t max_elements)
Note that elements will be pushed_back to vector.
Definition: iqueue.h:172
boost::future< bool > offer(const E &element, std::chrono::milliseconds timeout)
Inserts the specified element into this queue.
Definition: iqueue.h:101
boost::future< boost::optional< E > > poll()
Returns immediately without waiting.
Definition: iqueue.h:186
boost::future< bool > remove_all(const std::vector< E > &elements)
Definition: iqueue.h:242
boost::future< bool > contains_all(const std::vector< E > &elements)
Definition: iqueue.h:219
boost::future< std::vector< E > > to_array()
Definition: iqueue.h:208
boost::future< void > put(const E &element)
Puts the element into queue.
Definition: iqueue.h:86
boost::future< bool > offer(const E &element)
Inserts the specified element into this queue.
Definition: iqueue.h:76
boost::future< boost::uuids::uuid > add_item_listener(item_listener &&listener, bool include_value)
Adds an item listener for this collection.
Definition: iqueue.h:50
boost::future< bool > retain_all(const std::vector< E > &elements)
Removes the elements from this queue that are not available in given "elements" vector.
Definition: iqueue.h:255
boost::future< size_t > drain_to(std::vector< E > &elements)
Note that elements will be pushed_back to vector.
Definition: iqueue.h:159
boost::future< boost::optional< E > > take()
Definition: iqueue.h:113
Item listener for IQueue, ISet and IList.
Definition: item_listener.h:52