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/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/util/SynchronizedMap.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/client/config/ClientConnectionStrategyConfig.h"
36 #include "hazelcast/client/config/ClientFlakeIdGeneratorConfig.h"
37 #include "hazelcast/client/config/matcher/MatchingPointConfigPatternMatcher.h"
38 #include "hazelcast/client/internal/config/ConfigUtils.h"
39 #include "hazelcast/client/config/LoggerConfig.h"
40 
41 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
42 #pragma warning(push)
43 #pragma warning(disable: 4251) //for dll export
44 #endif
45 
46 namespace hazelcast {
47  namespace client {
48  class MembershipListener;
49 
50  class InitialMembershipListener;
51 
52  class LifecycleListener;
53 
54  class InitialMembershipEvent;
55 
59  class HAZELCAST_API ClientConfig {
60  friend class spi::impl::ClientClusterServiceImpl;
61  public:
62 
71  ClientConfig();
72 
82  ClientConfig &addAddress(const Address &address);
83 
93  ClientConfig &addAddresses(const std::vector<Address> &addresses);
94 
103  std::set<Address> getAddresses();
104 
112  ClientConfig &setGroupConfig(const GroupConfig &groupConfig);
113 
118  GroupConfig &getGroupConfig();
119 
125  ClientConfig &setCredentials(Credentials *credentials);
126 
130  const Credentials *getCredentials();
131 
142  ClientConfig &setConnectionAttemptLimit(int connectionAttemptLimit);
143 
153  int getConnectionAttemptLimit() const;
154 
159  ClientConfig &setConnectionTimeout(int connectionTimeoutInMillis);
160 
165  int getConnectionTimeout() const;
166 
175  ClientConfig &setAttemptPeriod(int attemptPeriodInMillis);
176 
184  int getAttemptPeriod() const;
185 
197  ClientConfig &setRedoOperation(bool redoOperation);
198 
204  bool isRedoOperation() const;
205 
212  bool isSmart() const;
213 
226  ClientConfig &setSmart(bool smart);
227 
233  ClientConfig &setSocketInterceptor(SocketInterceptor *socketInterceptor);
234 
238  SocketInterceptor *getSocketInterceptor();
239 
250  ClientConfig &addListener(LifecycleListener *listener);
251 
256  const std::set<LifecycleListener *> &getLifecycleListeners() const;
257 
270  ClientConfig &addListener(MembershipListener *listener);
271 
282  ClientConfig &addListener(const boost::shared_ptr<MembershipListener> &listener);
283 
289  const std::set<MembershipListener *> &getMembershipListeners() const;
290 
297  const std::set<boost::shared_ptr<MembershipListener> > &getManagedMembershipListeners() const;
298 
307  ClientConfig &addListener(InitialMembershipListener *listener);
308 
315  ClientConfig &addListener(const boost::shared_ptr<InitialMembershipListener> &listener);
316 
322  LoadBalancer *const getLoadBalancer();
323 
332  ClientConfig &setLoadBalancer(LoadBalancer *loadBalancer);
333 
344  ClientConfig &setLogLevel(LogLevel loggerLevel);
345 
350  SerializationConfig &getSerializationConfig();
351 
361  ClientConfig &setSerializationConfig(SerializationConfig const &serializationConfig);
362 
368  std::map<std::string, std::string> &getProperties();
369 
379  ClientConfig &setProperty(const std::string &name, const std::string &value);
380 
387  ClientConfig &addReliableTopicConfig(const config::ReliableTopicConfig &reliableTopicConfig);
388 
395  const config::ReliableTopicConfig *getReliableTopicConfig(const std::string &name);
396 
406  template <typename K, typename V>
407  ClientConfig &addNearCacheConfig(const boost::shared_ptr<config::NearCacheConfig<K, V> > nearCacheConfig) {
408  nearCacheConfigMap.put(nearCacheConfig->getName(), nearCacheConfig);
409  return *this;
410  }
411 
421  ClientConfig &addMixedNearCacheConfig(const boost::shared_ptr<mixedtype::config::MixedNearCacheConfig> nearCacheConfig) {
422  nearCacheConfigMap.put(nearCacheConfig->getName(), nearCacheConfig);
423  return *this;
424  }
425 
433  template <typename K, typename V>
434  const boost::shared_ptr<config::NearCacheConfig<K, V> > getNearCacheConfig(const std::string &name) {
435  boost::shared_ptr<config::NearCacheConfigBase> nearCacheConfig = internal::config::ConfigUtils::lookupByPattern<config::NearCacheConfigBase>(
436  configPatternMatcher, nearCacheConfigMap, name);
437  if (nearCacheConfig.get() == NULL) {
438  nearCacheConfig = nearCacheConfigMap.get("default");
439  }
440  // not needed for c++ client since it is always native memory
441  //initDefaultMaxSizeForOnHeapMaps(nearCacheConfig);
442  return boost::static_pointer_cast<config::NearCacheConfig<K, V> >(nearCacheConfig);
443  }
444 
445  const boost::shared_ptr<mixedtype::config::MixedNearCacheConfig> getMixedNearCacheConfig(const std::string &name);
446 
453  config::ClientNetworkConfig &getNetworkConfig();
454 
462  ClientConfig &setNetworkConfig(const config::ClientNetworkConfig &networkConfig);
463 
464  const boost::shared_ptr<std::string> &getInstanceName() const;
465 
466  void setInstanceName(const boost::shared_ptr<std::string> &instanceName);
467 
473  int32_t getExecutorPoolSize() const;
474 
481  void setExecutorPoolSize(int32_t executorPoolSize);
482 
483  config::ClientConnectionStrategyConfig &getConnectionStrategyConfig();
484 
485  ClientConfig &
486  setConnectionStrategyConfig(const config::ClientConnectionStrategyConfig &connectionStrategyConfig);
487 
503  boost::shared_ptr<config::ClientFlakeIdGeneratorConfig> findFlakeIdGeneratorConfig(const std::string &name);
504 
530  boost::shared_ptr<config::ClientFlakeIdGeneratorConfig> getFlakeIdGeneratorConfig(const std::string &name);
531 
540  ClientConfig &addFlakeIdGeneratorConfig(const boost::shared_ptr<config::ClientFlakeIdGeneratorConfig> &config);
541 
542 
547  config::LoggerConfig &getLoggerConfig();
548 
549  private:
550  GroupConfig groupConfig;
551 
552  config::ClientNetworkConfig networkConfig;
553 
554  SerializationConfig serializationConfig;
555 
556  LoadBalancer *loadBalancer;
557 
558  impl::RoundRobinLB defaultLoadBalancer;
559 
560  std::set<MembershipListener *> membershipListeners;
561  std::set<boost::shared_ptr<MembershipListener> > managedMembershipListeners;
562 
563  std::set<LifecycleListener *> lifecycleListeners;
564 
565  std::map<std::string, std::string> properties;
566 
567  bool redoOperation;
568 
569  SocketInterceptor *socketInterceptor;
570 
571  Credentials *credentials;
572 
573  std::map<std::string, config::ReliableTopicConfig> reliableTopicConfigMap;
574 
575  util::SynchronizedMap<std::string, config::NearCacheConfigBase> nearCacheConfigMap;
576 
577  boost::shared_ptr<std::string> instanceName;
578 
582  int32_t executorPoolSize;
583 
584  config::ClientConnectionStrategyConfig connectionStrategyConfig;
585 
586  util::SynchronizedMap<std::string, config::ClientFlakeIdGeneratorConfig> flakeIdGeneratorConfigMap;
587 
589 
590  config::LoggerConfig loggerConfig;
591  };
592 
593  }
594 }
595 
596 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
597 #pragma warning(pop)
598 #endif
599 
600 #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:38
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:407
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:434
SerializationConfig is used to.
Definition: SerializationConfig.h:49
Definition: LoggerConfig.h:45
ClientConfig & addMixedNearCacheConfig(const boost::shared_ptr< mixedtype::config::MixedNearCacheConfig > nearCacheConfig)
Helper method to add a new NearCacheConfig.
Definition: ClientConfig.h:421
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
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
HazelcastClient configuration class.
Definition: ClientConfig.h:59
Definition: ReliableTopicConfig.h:30
This.
Definition: MatchingPointConfigPatternMatcher.h:35