Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
ClientConfig.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_CONFIG
17 #define HAZELCAST_CLIENT_CONFIG
18 
19 #include <vector>
20 #include <set>
21 #include <memory>
22 
23 #include "hazelcast/client/Address.h"
24 #include "hazelcast/client/GroupConfig.h"
25 #include "hazelcast/client/SerializationConfig.h"
26 #include "hazelcast/client/Credentials.h"
27 #include "hazelcast/client/SocketInterceptor.h"
28 #include "hazelcast/client/LoadBalancer.h"
29 #include "hazelcast/client/impl/RoundRobinLB.h"
30 #include "hazelcast/util/ILogger.h"
31 #include "hazelcast/client/config/ReliableTopicConfig.h"
32 #include "hazelcast/client/config/NearCacheConfig.h"
33 #include "hazelcast/client/config/ClientNetworkConfig.h"
34 #include "hazelcast/util/SynchronizedMap.h"
35 
36 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
37 #pragma warning(push)
38 #pragma warning(disable: 4251) //for dll export
39 #endif
40 
41 namespace hazelcast {
42  namespace client {
43  class MembershipListener;
44 
45  class InitialMembershipListener;
46 
47  class LifecycleListener;
48 
52  class HAZELCAST_API ClientConfig {
53  public:
54 
63  ClientConfig();
64 
72  ClientConfig &addAddress(const Address &address);
73 
81  ClientConfig &addAddresses(const std::vector<Address> &addresses);
82 
89  std::set<Address, addressComparator> &getAddresses();
90 
98  ClientConfig &setGroupConfig(GroupConfig &groupConfig);
99 
104  GroupConfig &getGroupConfig();
105 
111  ClientConfig &setCredentials(Credentials *credentials);
112 
116  const Credentials *getCredentials();
117 
126  ClientConfig &setConnectionAttemptLimit(int connectionAttemptLimit);
127 
135  int getConnectionAttemptLimit() const;
136 
141  ClientConfig &setConnectionTimeout(int connectionTimeoutInMillis);
142 
147  int getConnectionTimeout() const;
148 
155  ClientConfig &setAttemptPeriod(int attemptPeriodInMillis);
156 
162  int getAttemptPeriod() const;
163 
175  ClientConfig &setRedoOperation(bool redoOperation);
176 
182  bool isRedoOperation() const;
183 
188  bool isSmart() const;
189 
200  ClientConfig &setSmart(bool smart);
201 
207  ClientConfig &setSocketInterceptor(SocketInterceptor *socketInterceptor);
208 
212  SocketInterceptor *getSocketInterceptor();
213 
224  ClientConfig &addListener(LifecycleListener *listener);
225 
230  const std::set<LifecycleListener *> &getLifecycleListeners() const;
231 
242  ClientConfig &addListener(MembershipListener *listener);
243 
249  const std::set<MembershipListener *> &getMembershipListeners() const;
250 
257  ClientConfig &addListener(InitialMembershipListener *listener);
258 
264  const std::set<InitialMembershipListener *> &getInitialMembershipListeners() const;
265 
271  LoadBalancer *const getLoadBalancer();
272 
281  ClientConfig &setLoadBalancer(LoadBalancer *loadBalancer);
282 
292  ClientConfig &setLogLevel(LogLevel loggerLevel);
293 
294 
299  SerializationConfig &getSerializationConfig();
300 
310  ClientConfig &setSerializationConfig(SerializationConfig const &serializationConfig);
311 
317  std::map<std::string, std::string> &getProperties();
318 
328  ClientConfig &setProperty(const std::string &name, const std::string &value);
329 
336  ClientConfig &addReliableTopicConfig(const config::ReliableTopicConfig &reliableTopicConfig);
337 
344  const config::ReliableTopicConfig *getReliableTopicConfig(const std::string &name);
345 
355  template <typename K, typename V>
356  ClientConfig &addNearCacheConfig(const boost::shared_ptr<config::NearCacheConfig<K, V> > nearCacheConfig) {
357  nearCacheConfigMap.put(nearCacheConfig->getName(), nearCacheConfig);
358  return *this;
359  }
360 
368  template <typename K, typename V>
369  const config::NearCacheConfig<K, V> *getNearCacheConfig(const std::string &name) {
370  boost::shared_ptr<config::NearCacheConfigBase> nearCacheConfig = lookupByPattern(name);
371  if (nearCacheConfig.get() == NULL) {
372  nearCacheConfig = nearCacheConfigMap.get("default");
373  }
374  // not needed for c++ client since it is always native memory
375  //initDefaultMaxSizeForOnHeapMaps(nearCacheConfig);
376  return boost::static_pointer_cast<config::NearCacheConfig<K, V> >(nearCacheConfig).get();
377  }
378 
385  config::ClientNetworkConfig &getNetworkConfig();
386 
394  ClientConfig &setNetworkConfig(const config::ClientNetworkConfig &networkConfig);
395 
396  private:
397 
398  GroupConfig groupConfig;
399 
400  config::ClientNetworkConfig networkConfig;
401 
402  SerializationConfig serializationConfig;
403 
404  std::set<Address, addressComparator> addressList;
405 
406  LoadBalancer *loadBalancer;
407 
408  std::auto_ptr<impl::RoundRobinLB> defaultLoadBalancer;
409 
410  std::set<MembershipListener *> membershipListeners;
411 
412  std::set<InitialMembershipListener *> initialMembershipListeners;
413 
414  std::set<LifecycleListener *> lifecycleListeners;
415 
416  std::map<std::string, std::string> properties;
417 
418  bool smart;
419 
420  bool redoOperation;
421 
422  int connectionAttemptLimit;
423 
424  int attemptPeriod;
425 
426  SocketInterceptor *socketInterceptor;
427 
428  Credentials *credentials;
429 
430  std::map<std::string, config::ReliableTopicConfig> reliableTopicConfigMap;
431 
432  util::SynchronizedMap<std::string, config::NearCacheConfigBase> nearCacheConfigMap;
433 
434  const boost::shared_ptr<config::NearCacheConfigBase> lookupByPattern(const std::string &name) {
435  // TODO: implement the lookup
436  return nearCacheConfigMap.get(name);
437  }
438  };
439 
440  }
441 }
442 
443 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
444 #pragma warning(pop)
445 #endif
446 
447 #endif /* HAZELCAST_CLIENT_CONFIG */
Credentials is a container object for endpoint (Members and Clients) security attributes.
Definition: Credentials.h:35
Contains configuration parameters for client network related behaviour.
Definition: ClientNetworkConfig.h:37
Contains the configuration for a Near Cache.
Definition: NearCacheConfig.h:42
Base class for socketInterceptor classes to inherit from.
Definition: SocketInterceptor.h:33
Contains the configuration for Hazelcast groups.
Definition: GroupConfig.h:36
Cluster membership listener.
Definition: MembershipListener.h:51
IP Address.
Definition: Address.h:36
ClientConfig & addNearCacheConfig(const boost::shared_ptr< config::NearCacheConfig< K, V > > nearCacheConfig)
Helper method to add a new NearCacheConfig.
Definition: ClientConfig.h:356
SerializationConfig is used to.
Definition: SerializationConfig.h:44
Listener object for listening lifecycle events of hazelcast instance.
Definition: LifecycleListener.h:44
const config::NearCacheConfig< K, V > * getNearCacheConfig(const std::string &name)
Gets the NearCacheConfig configured for the map / cache with name.
Definition: ClientConfig.h:369
The InitializingMembershipListener is a MembershipListener that will first receives a InitialMembersh...
Definition: InitialMembershipListener.h:50
LoadBalancer allows you to send operations to one of a number of endpoints(Members).
Definition: LoadBalancer.h:40
HazelcastClient configuration class.
Definition: ClientConfig.h:52
Definition: ReliableTopicConfig.h:30