Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
iqueue.h
1/*
2 * Copyright (c) 2008-2025, 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#include "hazelcast/client/spi/ClientContext.h"
23
24namespace hazelcast {
25namespace client {
30class iqueue : public proxy::IQueueImpl
31{
32 friend class spi::ProxyManager;
33
34public:
35 static constexpr const char* SERVICE_NAME = "hz:impl:queueService";
36
51 boost::future<boost::uuids::uuid> add_item_listener(
52 item_listener&& listener,
53 bool include_value)
54 {
55 std::unique_ptr<
56 impl::item_event_handler<protocol::codec::queue_addlistener_handler>>
57 itemEventHandler(new impl::item_event_handler<
58 protocol::codec::queue_addlistener_handler>(
59 get_name(),
60 get_context().get_logger(),
61 get_context().get_client_cluster_service(),
62 get_context().get_serialization_service(),
63 std::move(listener),
64 include_value));
65
66 return proxy::IQueueImpl::add_item_listener(std::move(itemEventHandler),
67 include_value);
68 }
69
77 template<typename E>
78 boost::future<bool> offer(const E& element)
79 {
80 return offer(element, std::chrono::milliseconds(0));
81 }
82
87 template<typename E>
88 boost::future<void> put(const E& element)
89 {
90 return proxy::IQueueImpl::put(to_data(element));
91 }
92
102 template<typename E>
103 boost::future<bool> offer(const E& element,
104 std::chrono::milliseconds timeout)
105 {
106 return proxy::IQueueImpl::offer(to_data(element), timeout);
107 }
108
114 template<typename E>
115 boost::future<boost::optional<E>> take()
116 {
117 return to_object<E>(proxy::IQueueImpl::take_data());
118 }
119
126 template<typename E>
127 boost::future<boost::optional<E>> poll(std::chrono::milliseconds timeout)
128 {
129 return to_object<E>(proxy::IQueueImpl::poll_data(timeout));
130 }
131
137 template<typename E>
138 boost::future<bool> remove(const E& element)
139 {
140 return proxy::IQueueImpl::remove(to_data(element));
141 }
142
148 template<typename E>
149 boost::future<bool> contains(const E& element)
150 {
151 return proxy::IQueueImpl::contains(to_data(element));
152 }
153
160 template<typename E>
161 boost::future<size_t> drain_to(std::vector<E>& elements)
162 {
163 return to_object_drain(proxy::IQueueImpl::drain_to_data(), elements);
164 }
165
173 template<typename E>
174 boost::future<size_t> drain_to(std::vector<E>& elements,
175 size_t max_elements)
176 {
177 return to_object_drain(proxy::IQueueImpl::drain_to_data(max_elements),
178 elements);
179 }
180
187 template<typename E>
188 boost::future<boost::optional<E>> poll()
189 {
190 return poll<E>(std::chrono::milliseconds(0));
191 }
192
199 template<typename E>
200 boost::future<boost::optional<E>> peek()
201 {
202 return to_object<E>(proxy::IQueueImpl::peek_data());
203 }
204
209 template<typename E>
210 boost::future<std::vector<E>> to_array()
211 {
212 return to_object_vector<E>(proxy::IQueueImpl::to_array_data());
213 }
214
220 template<typename E>
221 boost::future<bool> contains_all(const std::vector<E>& elements)
222 {
223 return proxy::IQueueImpl::contains_all_data(
224 to_data_collection(elements));
225 }
226
232 template<typename E>
233 boost::future<bool> add_all(const std::vector<E>& elements)
234 {
235 return proxy::IQueueImpl::add_all_data(to_data_collection(elements));
236 }
237
243 template<typename E>
244 boost::future<bool> remove_all(const std::vector<E>& elements)
245 {
246 return proxy::IQueueImpl::remove_all_data(to_data_collection(elements));
247 }
248
256 template<typename E>
257 boost::future<bool> retain_all(const std::vector<E>& elements)
258 {
259 return proxy::IQueueImpl::retain_all_data(to_data_collection(elements));
260 }
261
262private:
263 iqueue(const std::string& instance_name, spi::ClientContext* context)
264 : proxy::IQueueImpl(instance_name, context)
265 {}
266};
267} // namespace client
268} // namespace hazelcast
Concurrent, blocking, distributed, observable, client queue.
Definition iqueue.h:31
boost::future< boost::uuids::uuid > add_item_listener(item_listener &&listener, bool include_value)
Adds an item listener for this collection.
Definition iqueue.h:51
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:257
boost::future< boost::optional< E > > poll()
Returns immediately without waiting.
Definition iqueue.h:188
boost::future< bool > add_all(const std::vector< E > &elements)
Definition iqueue.h:233
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:174
boost::future< size_t > drain_to(std::vector< E > &elements)
Note that elements will be pushed_back to vector.
Definition iqueue.h:161
boost::future< bool > remove(const E &element)
Definition iqueue.h:138
boost::future< bool > contains_all(const std::vector< E > &elements)
Definition iqueue.h:221
boost::future< bool > contains(const E &element)
Definition iqueue.h:149
boost::future< boost::optional< E > > poll(std::chrono::milliseconds timeout)
Definition iqueue.h:127
boost::future< bool > remove_all(const std::vector< E > &elements)
Definition iqueue.h:244
boost::future< bool > offer(const E &element)
Inserts the specified element into this queue.
Definition iqueue.h:78
boost::future< boost::optional< E > > take()
Definition iqueue.h:115
boost::future< std::vector< E > > to_array()
Definition iqueue.h:210
boost::future< void > put(const E &element)
Puts the element into queue.
Definition iqueue.h:88
boost::future< boost::optional< E > > peek()
Returns immediately without waiting.
Definition iqueue.h:200
boost::future< bool > offer(const E &element, std::chrono::milliseconds timeout)
Inserts the specified element into this queue.
Definition iqueue.h:103
Item listener for IQueue, ISet and IList.