Hazelcast C++ Client
ClientConfig.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_CONFIG
17 #define HAZELCAST_CLIENT_CONFIG
18 
19 #include <vector>
20 #include <set>
21 #include <boost/shared_ptr.hpp>
22 
23 #include "hazelcast/client/config/ClientConnectionStrategyConfig.h"
24 #include "hazelcast/client/Address.h"
25 #include "hazelcast/client/GroupConfig.h"
26 #include "hazelcast/client/SerializationConfig.h"
27 #include "hazelcast/client/Credentials.h"
28 #include "hazelcast/client/SocketInterceptor.h"
29 #include "hazelcast/client/LoadBalancer.h"
30 #include "hazelcast/client/impl/RoundRobinLB.h"
31 #include "hazelcast/util/ILogger.h"
32 #include "hazelcast/client/config/ReliableTopicConfig.h"
33 #include "hazelcast/client/config/NearCacheConfig.h"
34 #include "hazelcast/client/config/ClientNetworkConfig.h"
35 #include "hazelcast/util/SynchronizedMap.h"
36 
37 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
38 #pragma warning(push)
39 #pragma warning(disable: 4251) //for dll export
40 #endif
41 
42 namespace hazelcast {
43  namespace client {
44  class MembershipListener;
45 
46  class InitialMembershipListener;
47 
48  class LifecycleListener;
49 
50  class InitialMembershipEvent;
51 
55  class HAZELCAST_API ClientConfig {
56  friend class spi::impl::ClientClusterServiceImpl;
57  public:
58 
67  ClientConfig();
68 
78  ClientConfig &addAddress(const Address &address);
79 
89  ClientConfig &addAddresses(const std::vector<Address> &addresses);
90 
99  std::set<Address> getAddresses();
100 
108  ClientConfig &setGroupConfig(const GroupConfig &groupConfig);
109 
114  GroupConfig &getGroupConfig();
115 
121  ClientConfig &setCredentials(Credentials *credentials);
122 
126  const Credentials *getCredentials();
127 
138  ClientConfig &setConnectionAttemptLimit(int connectionAttemptLimit);
139 
149  int getConnectionAttemptLimit() const;
150 
155  ClientConfig &setConnectionTimeout(int connectionTimeoutInMillis);
156 
161  int getConnectionTimeout() const;
162 
171  ClientConfig &setAttemptPeriod(int attemptPeriodInMillis);
172 
180  int getAttemptPeriod() const;
181 
193  ClientConfig &setRedoOperation(bool redoOperation);
194 
200  bool isRedoOperation() const;
201 
208  bool isSmart() const;
209 
222  ClientConfig &setSmart(bool smart);
223 
229  ClientConfig &setSocketInterceptor(SocketInterceptor *socketInterceptor);
230 
234  SocketInterceptor *getSocketInterceptor();
235 
246  ClientConfig &addListener(LifecycleListener *listener);
247 
252  const std::set<LifecycleListener *> &getLifecycleListeners() const;
253 
266  ClientConfig &addListener(MembershipListener *listener);
267 
278  ClientConfig &addListener(const boost::shared_ptr<MembershipListener> &listener);
279 
285  const std::set<MembershipListener *> &getMembershipListeners() const;
286 
293  const std::set<boost::shared_ptr<MembershipListener> > &getManagedMembershipListeners() const;
294 
303  ClientConfig &addListener(InitialMembershipListener *listener);
304 
311  ClientConfig &addListener(const boost::shared_ptr<InitialMembershipListener> &listener);
312 
318  LoadBalancer *const getLoadBalancer();
319 
328  ClientConfig &setLoadBalancer(LoadBalancer *loadBalancer);
329 
340  ClientConfig &setLogLevel(LogLevel loggerLevel);
341 
346  SerializationConfig &getSerializationConfig();
347 
357  ClientConfig &setSerializationConfig(SerializationConfig const &serializationConfig);
358 
364  std::map<std::string, std::string> &getProperties();
365 
375  ClientConfig &setProperty(const std::string &name, const std::string &value);
376 
383  ClientConfig &addReliableTopicConfig(const config::ReliableTopicConfig &reliableTopicConfig);
384 
391  const config::ReliableTopicConfig *getReliableTopicConfig(const std::string &name);
392 
402  template <typename K, typename V>
403  ClientConfig &addNearCacheConfig(const boost::shared_ptr<config::NearCacheConfig<K, V> > nearCacheConfig) {
404  nearCacheConfigMap.put(nearCacheConfig->getName(), nearCacheConfig);
405  return *this;
406  }
407 
417  ClientConfig &addMixedNearCacheConfig(const boost::shared_ptr<mixedtype::config::MixedNearCacheConfig> nearCacheConfig) {
418  nearCacheConfigMap.put(nearCacheConfig->getName(), nearCacheConfig);
419  return *this;
420  }
421 
429  template <typename K, typename V>
430  const boost::shared_ptr<config::NearCacheConfig<K, V> > getNearCacheConfig(const std::string &name) {
431  boost::shared_ptr<config::NearCacheConfigBase> nearCacheConfig = lookupByPattern(name);
432  if (nearCacheConfig.get() == NULL) {
433  nearCacheConfig = nearCacheConfigMap.get("default");
434  }
435  // not needed for c++ client since it is always native memory
436  //initDefaultMaxSizeForOnHeapMaps(nearCacheConfig);
437  return boost::static_pointer_cast<config::NearCacheConfig<K, V> >(nearCacheConfig);
438  }
439 
440  const boost::shared_ptr<mixedtype::config::MixedNearCacheConfig> getMixedNearCacheConfig(const std::string &name);
441 
448  config::ClientNetworkConfig &getNetworkConfig();
449 
457  ClientConfig &setNetworkConfig(const config::ClientNetworkConfig &networkConfig);
458 
459  const boost::shared_ptr<std::string> &getInstanceName() const;
460 
461  void setInstanceName(const boost::shared_ptr<std::string> &instanceName);
462 
468  int32_t getExecutorPoolSize() const;
469 
476  void setExecutorPoolSize(int32_t executorPoolSize);
477 
478  config::ClientConnectionStrategyConfig &getConnectionStrategyConfig();
479 
480  ClientConfig &
481  setConnectionStrategyConfig(const config::ClientConnectionStrategyConfig &connectionStrategyConfig);
482 
483  private:
484  GroupConfig groupConfig;
485 
486  config::ClientNetworkConfig networkConfig;
487 
488  SerializationConfig serializationConfig;
489 
490  LoadBalancer *loadBalancer;
491 
492  impl::RoundRobinLB defaultLoadBalancer;
493 
494  std::set<MembershipListener *> membershipListeners;
495  std::set<boost::shared_ptr<MembershipListener> > managedMembershipListeners;
496 
497  std::set<LifecycleListener *> lifecycleListeners;
498 
499  std::map<std::string, std::string> properties;
500 
501  bool redoOperation;
502 
503  SocketInterceptor *socketInterceptor;
504 
505  Credentials *credentials;
506 
507  std::map<std::string, config::ReliableTopicConfig> reliableTopicConfigMap;
508 
509  util::SynchronizedMap<std::string, config::NearCacheConfigBase> nearCacheConfigMap;
510 
511  boost::shared_ptr<std::string> instanceName;
512 
516  int32_t executorPoolSize;
517 
518  config::ClientConnectionStrategyConfig connectionStrategyConfig;
519 
520  const boost::shared_ptr<config::NearCacheConfigBase> lookupByPattern(const std::string &name);
521  };
522 
523  }
524 }
525 
526 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
527 #pragma warning(pop)
528 #endif
529 
530 #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:44
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:64
IP Address.
Definition: Address.h:41
Client connection strategy configuration is used for setting custom strategies and configuring strate...
Definition: ClientConnectionStrategyConfig.h:32
ClientConfig & addNearCacheConfig(const boost::shared_ptr< config::NearCacheConfig< K, V > > nearCacheConfig)
Helper method to add a new NearCacheConfig.
Definition: ClientConfig.h:403
const boost::shared_ptr< config::NearCacheConfig< K, V > > getNearCacheConfig(const std::string &name)
Gets the NearCacheConfig configured for the map / cache with name.
Definition: ClientConfig.h:430
SerializationConfig is used to.
Definition: SerializationConfig.h:49
ClientConfig & addMixedNearCacheConfig(const boost::shared_ptr< mixedtype::config::MixedNearCacheConfig > nearCacheConfig)
Helper method to add a new NearCacheConfig.
Definition: ClientConfig.h:417
Listener object for listening lifecycle events of hazelcast instance.
Definition: LifecycleListener.h:44
The InitializingMembershipListener is a MembershipListener that will first receives a InitialMembersh...
Definition: InitialMembershipListener.h:57
LoadBalancer allows you to send operations to one of a number of endpoints(Members).
Definition: LoadBalancer.h:38
Definition: MapEntryView.h:32
HazelcastClient configuration class.
Definition: ClientConfig.h:55
Definition: ReliableTopicConfig.h:30