Hazelcast C++ Client
Ringbuffer.h
1 /*
2  * Copyright (c) 2008-2017, 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 namespace hazelcast {
26  namespace client {
27  namespace mixedtype {
60  class HAZELCAST_API Ringbuffer : public proxy::ProxyImpl {
61  friend class client::HazelcastClient;
62 
63  public:
64  virtual ~Ringbuffer();
65 
71  int64_t capacity();
72 
81  int64_t size();
82 
90  int64_t tailSequence();
91 
102  int64_t headSequence();
103 
113  int64_t remainingCapacity();
114 
132  template <typename E>
133  int64_t add(const E &item) {
134  serialization::pimpl::Data itemData = toData<E>(item);
135  std::auto_ptr<protocol::ClientMessage> msg = protocol::codec::RingbufferAddCodec::RequestParameters::encode(
136  getName(), OVERWRITE, itemData);
137  return invokeAndGetResult<int64_t, protocol::codec::RingbufferAddCodec::ResponseParameters>(msg, partitionId);
138  }
139 
173  TypedData readOne(int64_t sequence);
174 
175  private:
176  Ringbuffer(const std::string &objectName, spi::ClientContext *context);
177 
187  enum OverflowPolicy {
188 
197  OVERWRITE = 0
198  };
199 
200  int32_t partitionId;
201  util::Atomic<int64_t> bufferCapacity;
202  };
203  }
204  }
205 }
206 
207 #endif //HAZELCAST_CLIENT_MIXEDTYPE_RINGBUFFER_H_
208 
int64_t add(const E &item)
Adds an item to the tail of the Ringbuffer.
Definition: Ringbuffer.h:133
Definition: MapEntryView.h:32
A Ringbuffer is a data-structure where the content is stored in a ring like structure.
Definition: Ringbuffer.h:60
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:459