18 #include "hazelcast/client/proxy/RingbufferImpl.h"
20 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
22 #pragma warning(disable: 4251)
59 class HAZELCAST_API
ringbuffer :
public proxy::RingbufferImpl {
60 friend class spi::ProxyManager;
80 boost::future<int64_t>
add(
const E &item) {
81 return add_data(to_data(item));
118 boost::future<boost::optional<E>>
read_one(int64_t sequence) {
119 return to_object<E>(read_one_data(sequence));
155 boost::future<int64_t>
add(
const E &item, rb::overflow_policy overflow_policy) {
156 return addData(to_data(item), overflow_policy);
185 boost::future<int64_t>
186 add_all(
const std::vector<E> &items, rb::overflow_policy overflow_policy) {
187 return add_all_data(to_data_collection(items), overflow_policy);
229 template<
typename IFUNCTION>
230 boost::future<rb::read_result_set>
231 read_many(int64_t start_sequence, int32_t min_count, int32_t max_count,
const IFUNCTION *filter =
nullptr) {
232 auto filter_data = to_data<IFUNCTION>(filter);
233 return read_many_data(start_sequence, min_count, max_count, &filter_data).then(boost::launch::sync, [=] (boost::future<protocol::ClientMessage> f) {
234 return get_result_set(std::move(f));
240 auto *initial_frame =
reinterpret_cast<protocol::ClientMessage::frame_header_t *
>(msg.rd_ptr(
241 protocol::ClientMessage::RESPONSE_HEADER_LEN));
242 auto read_count = msg.get<int32_t>();
243 auto next_seq = msg.get<int64_t>();
245 static_cast<int32_t
>(initial_frame->frame_len) - protocol::ClientMessage::RESPONSE_HEADER_LEN -
246 protocol::ClientMessage::INT32_SIZE -
247 protocol::ClientMessage::INT64_SIZE);
249 auto datas = msg.get<std::vector<serialization::pimpl::data>>();
250 auto item_seqs = msg.get_nullable<std::vector<int64_t>>();
251 return rb::read_result_set(read_count, std::move(datas), get_serialization_service(), item_seqs,
255 boost::future<rb::read_result_set>
256 read_many(int64_t start_sequence, int32_t min_count, int32_t max_count) {
257 return read_many_data(start_sequence, min_count, max_count,
nullptr).then(boost::launch::sync, [=] (boost::future<protocol::ClientMessage> f) {
258 return get_result_set(std::move(f));
263 ringbuffer(
const std::string &object_name, spi::ClientContext *context) : RingbufferImpl(object_name,
269 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
A Ringbuffer is a data-structure where the content is stored in a ring like structure.
boost::future< int64_t > add_all(const std::vector< E > &items, rb::overflow_policy overflow_policy)
Adds all the items of a collection to the tail of the Ringbuffer.
boost::future< rb::read_result_set > read_many(int64_t start_sequence, int32_t min_count, int32_t max_count, const IFUNCTION *filter=nullptr)
Reads a batch of items from the Ringbuffer.
boost::future< int64_t > add(const E &item, rb::overflow_policy overflow_policy)
Asynchronously writes an item with a configurable rb::OverflowPolicy.
boost::future< int64_t > add(const E &item)
Adds an item to the tail of the Ringbuffer.
boost::future< boost::optional< E > > read_one(int64_t sequence)
Reads one item from the Ringbuffer.