Hazelcast C++ Client
Ringbuffer.h
1 /*
2  * Copyright (c) 2008-2018, 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_MIXEDTYPE_RINGBUFFER_H_
17 #define HAZELCAST_CLIENT_MIXEDTYPE_RINGBUFFER_H_
18 
19 #include <stdint.h>
20 
21 #include "hazelcast/client/TypedData.h"
22 #include "hazelcast/client/proxy/ProxyImpl.h"
23 #include "hazelcast/client/protocol/codec/RingbufferAddCodec.h"
24 
25 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
26 #pragma warning(push)
27 #pragma warning(disable: 4251) //for dll export
28 #endif
29 
30 namespace hazelcast {
31  namespace client {
32  namespace mixedtype {
65  class HAZELCAST_API Ringbuffer : public proxy::ProxyImpl {
66  friend class client::impl::HazelcastClientInstanceImpl;
67 
68  public:
69  Ringbuffer(const Ringbuffer &rhs);
70 
71  virtual ~Ringbuffer();
72 
78  int64_t capacity();
79 
88  int64_t size();
89 
97  int64_t tailSequence();
98 
109  int64_t headSequence();
110 
120  int64_t remainingCapacity();
121 
139  template <typename E>
140  int64_t add(const E &item) {
141  serialization::pimpl::Data itemData = toData<E>(item);
142  std::auto_ptr<protocol::ClientMessage> msg = protocol::codec::RingbufferAddCodec::encodeRequest(
143  getName(), OVERWRITE, itemData);
144  return invokeAndGetResult<int64_t, protocol::codec::RingbufferAddCodec::ResponseParameters>(msg, partitionId);
145  }
146 
180  TypedData readOne(int64_t sequence);
181 
182  private:
183  Ringbuffer(const std::string &objectName, spi::ClientContext *context);
184 
194  enum OverflowPolicy {
195 
204  OVERWRITE = 0
205  };
206 
207  int32_t partitionId;
208  util::Atomic<int64_t> bufferCapacity;
209  };
210  }
211  }
212 }
213 
214 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
215 #pragma warning(pop)
216 #endif
217 
218 #endif //HAZELCAST_CLIENT_MIXEDTYPE_RINGBUFFER_H_
219 
int64_t add(const E &item)
Adds an item to the tail of the Ringbuffer.
Definition: Ringbuffer.h:140
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
A Ringbuffer is a data-structure where the content is stored in a ring like structure.
Definition: Ringbuffer.h:65
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40