Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
IdGenerator.h
1 /*
2  * Copyright (c) 2008-2015, 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_ID_GENERATOR
17 #define HAZELCAST_ID_GENERATOR
18 
19 #include "hazelcast/client/IAtomicLong.h"
20 #include "hazelcast/util/AtomicInt.h"
21 #include <boost/shared_ptr.hpp>
22 #include <string>
23 
24 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25 #pragma warning(push)
26 #pragma warning(disable: 4251) //for dll export
27 #endif
28 
29 namespace hazelcast {
30  namespace client {
31  namespace spi {
32  class ClientContext;
33  }
34 
35  namespace impl {
36  class IdGeneratorSupport;
37  }
38 
42  class HAZELCAST_API IdGenerator : public proxy::ProxyImpl {
43  friend class HazelcastClient;
44 
45  public:
46  enum {
47  BLOCK_SIZE = 1000
48  };
49 
55  bool init(long id);
56 
65  long newId();
66 
67  private:
68 
69  IAtomicLong atomicLong;
70  boost::shared_ptr< util::AtomicInt > local;
71  boost::shared_ptr< util::AtomicInt > residue;
72  boost::shared_ptr< util::Mutex > localLock;
73  IdGenerator(const std::string &instanceName, spi::ClientContext *context);
74 
75  void onDestroy();
76 
77  };
78  }
79 }
80 
81 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
82 #pragma warning(pop)
83 #endif
84 
85 #endif /* HAZELCAST_ID_GENERATOR */
Cluster-wide unique id generator.
Definition: IdGenerator.h:42
IAtomicLong is a distributed atomic long implementation.
Definition: IAtomicLong.h:38
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:410