Hazelcast C++ Client
Ringbuffer.h
1 /*
2  * Copyright (c) 2008-2019, 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 //
17 // Created by ihsan demir on 16/20/13.
18 #ifndef HZELCAST_CLIENT_RINGBUFFER_H_
19 #define HZELCAST_CLIENT_RINGBUFFER_H_
20 
21 #include <memory>
22 #include <stdint.h>
23 
24 #include "hazelcast/client/DistributedObject.h"
25 #include "hazelcast/client/ringbuffer/ReadResultSet.h"
26 #include "hazelcast/client/ICompletableFuture.h"
27 
28 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
29 #pragma warning(push)
30 #pragma warning(disable: 4251) //for dll export
31 #endif
32 
33 namespace hazelcast {
34  namespace client {
68  template<typename E>
69  class Ringbuffer : public virtual DistributedObject {
70  public:
81 
90  OVERWRITE = 0,
91 
102  FAIL = 1
103  };
104 
105 
106  virtual ~Ringbuffer() {
107  }
108 
114  virtual int64_t capacity() = 0;
115 
124  virtual int64_t size() = 0;
125 
133  virtual int64_t tailSequence() = 0;
134 
145  virtual int64_t headSequence() = 0;
146 
156  virtual int64_t remainingCapacity() = 0;
157 
175  virtual int64_t add(const E &item) = 0;
176 
210  virtual std::auto_ptr<E> readOne(int64_t sequence) = 0;
211 
244  virtual boost::shared_ptr<ICompletableFuture<int64_t> >
245  addAsync(const E &item, OverflowPolicy overflowPolicy) = 0;
246 
271  virtual boost::shared_ptr<ICompletableFuture<int64_t> >
272  addAllAsync(const std::vector<E> &items, OverflowPolicy overflowPolicy) = 0;
273 
313  template<typename IFUNCTION>
314  boost::shared_ptr<ICompletableFuture<ringbuffer::ReadResultSet<E> > >
315  readManyAsync(int64_t startSequence, int32_t minCount, int32_t maxCount, const IFUNCTION *filter) {
316  return readManyAsyncInternal(startSequence, minCount, maxCount,
317  getSerializationService().template toData<IFUNCTION>(filter));
318  }
319 
320  protected:
321  virtual boost::shared_ptr<ICompletableFuture<ringbuffer::ReadResultSet<E> > >
322  readManyAsyncInternal(int64_t startSequence, int32_t minCount, int32_t maxCount,
323  const serialization::pimpl::Data &filterData) = 0;
324 
325  virtual serialization::pimpl::SerializationService &getSerializationService() = 0;
326  };
327  }
328 }
329 
330 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
331 #pragma warning(pop)
332 #endif
333 
334 #endif //HZELCAST_CLIENT_RINGBUFFER_H_
335 
virtual int64_t capacity()=0
Returns the capacity of this Ringbuffer.
Using this policy the oldest item is overwritten no matter it is not old enough to retire...
Definition: Ringbuffer.h:90
Using this policy the call will fail immediately and the oldest item will not be overwritten before i...
Definition: Ringbuffer.h:102
virtual boost::shared_ptr< ICompletableFuture< int64_t > > addAsync(const E &item, OverflowPolicy overflowPolicy)=0
Asynchronously writes an item with a configurable OverflowPolicy.
OverflowPolicy
Using this policy one can control the behavior what should to be done when an item is about to be add...
Definition: Ringbuffer.h:80
virtual int64_t tailSequence()=0
Returns the sequence of the tail.
virtual std::auto_ptr< E > readOne(int64_t sequence)=0
Reads one item from the Ringbuffer.
Base class for all distributed objects.
Definition: DistributedObject.h:58
A Ringbuffer is a data-structure where the content is stored in a ring like structure.
Definition: Ringbuffer.h:69
virtual int64_t headSequence()=0
Returns the sequence of the head.
virtual int64_t size()=0
Returns number of items in the ringbuffer.
virtual int64_t add(const E &item)=0
Adds an item to the tail of the Ringbuffer.
virtual boost::shared_ptr< ICompletableFuture< int64_t > > addAllAsync(const std::vector< E > &items, OverflowPolicy overflowPolicy)=0
Adds all the items of a collection to the tail of the Ringbuffer.
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
virtual int64_t remainingCapacity()=0
Returns the remaining capacity of the ringbuffer.
boost::shared_ptr< ICompletableFuture< ringbuffer::ReadResultSet< E > > > readManyAsync(int64_t startSequence, int32_t minCount, int32_t maxCount, const IFUNCTION *filter)
Reads a batch of items from the Ringbuffer.
Definition: Ringbuffer.h:315