16 #ifndef HAZELCAST_CLIENT_CONFIG_NEARCACHECONFIG_H_ 
   17 #define HAZELCAST_CLIENT_CONFIG_NEARCACHECONFIG_H_ 
   23 #include <boost/shared_ptr.hpp> 
   25 #include "hazelcast/client/config/InMemoryFormat.h" 
   26 #include "hazelcast/client/config/EvictionConfig.h" 
   27 #include "hazelcast/client/config/NearCacheConfigBase.h" 
   29 #if  defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 
   31 #pragma warning(disable: 4251) //for dll export  
   41             template <
typename K, 
typename V>
 
   77                                     localUpdatePolicy(
INVALIDATE), invalidateOnChange(true), cacheLocalEntries(false),
 
   81                 NearCacheConfig(
const char *cacheName) : name(cacheName), timeToLiveSeconds(
DEFAULT_TTL_SECONDS),
 
   84                                                          localUpdatePolicy(
INVALIDATE), invalidateOnChange(true),
 
   85                                                          cacheLocalEntries(false),
 
   86                                                          evictionConfig(new EvictionConfig<K, V>()) {
 
   89                 NearCacheConfig(
const char *cacheName, InMemoryFormat memoryFormat) : name(cacheName), timeToLiveSeconds(
DEFAULT_TTL_SECONDS),
 
   91                                                          inMemoryFormat(memoryFormat),
 
   92                                                          localUpdatePolicy(
INVALIDATE), invalidateOnChange(true),
 
   93                                                          cacheLocalEntries(false),
 
   94                                                          evictionConfig(new EvictionConfig<K, V>()) {
 
   97                 NearCacheConfig(int32_t timeToLiveSeconds, int32_t maxIdleSeconds, 
bool invalidateOnChange,
 
   98                                 InMemoryFormat inMemoryFormat, boost::shared_ptr<EvictionConfig<K, V> > evictConfig)
 
   99                         : evictionConfig(new EvictionConfig<K, V>()) {
 
  100                     this->timeToLiveSeconds = timeToLiveSeconds;
 
  101                     this->maxIdleSeconds = maxIdleSeconds;
 
  102                     this->invalidateOnChange = invalidateOnChange;
 
  103                     this->inMemoryFormat = inMemoryFormat;
 
  106                     if (evictConfig.get() != NULL) {
 
  107                         this->evictionConfig = evictConfig;
 
  109                     this->cacheLocalEntries = 
false;
 
  112                 NearCacheConfig(
const NearCacheConfig<K, V> &config) {
 
  113                     name = config.getName();
 
  114                     inMemoryFormat = config.getInMemoryFormat();
 
  115                     invalidateOnChange = config.isInvalidateOnChange();
 
  116                     maxIdleSeconds = config.getMaxIdleSeconds();
 
  117                     timeToLiveSeconds = config.getTimeToLiveSeconds();
 
  118                     cacheLocalEntries = config.isCacheLocalEntries();
 
  119                     localUpdatePolicy = config.localUpdatePolicy;
 
  121                     if (config.evictionConfig.get() != NULL) {
 
  122                         this->evictionConfig = config.evictionConfig;
 
  153                     return timeToLiveSeconds;
 
  165                     this->timeToLiveSeconds = util::Preconditions::checkNotNegative(timeToLiveSeconds,
 
  166                                                                                     "TTL seconds cannot be negative!");
 
  179                     return maxIdleSeconds;
 
  193                     this->maxIdleSeconds = util::Preconditions::checkNotNegative(maxIdleSeconds,
 
  194                                                                                  "Max-Idle seconds cannot be negative!");
 
  207                     return invalidateOnChange;
 
  221                     this->invalidateOnChange = invalidateOnChange;
 
  234                     return inMemoryFormat;
 
  247                     this->inMemoryFormat = inMemoryFormat;
 
  258                     return cacheLocalEntries;
 
  269                     this->cacheLocalEntries = cacheLocalEntries;
 
  274                     return localUpdatePolicy;
 
  277                 NearCacheConfig &setLocalUpdatePolicy(
const LocalUpdatePolicy &localUpdatePolicy) {
 
  278                     this->localUpdatePolicy = localUpdatePolicy;
 
  288                     return evictionConfig;
 
  298                     this->evictionConfig = util::Preconditions::checkNotNull<EvictionConfig<K, V> >(evictionConfig,
 
  299                                                                                                     "EvictionConfig cannot be NULL!");
 
  303                 std::ostream &operator<<(std::ostream &out) {
 
  304                     out << 
"NearCacheConfig{" 
  305                         << 
"timeToLiveSeconds=" << timeToLiveSeconds
 
  306                         << 
", maxIdleSeconds=" << maxIdleSeconds
 
  307                         << 
", invalidateOnChange=" << invalidateOnChange
 
  308                         << 
", inMemoryFormat=" << inMemoryFormat
 
  309                         << 
", cacheLocalEntries=" << cacheLocalEntries
 
  310                         << 
", localUpdatePolicy=" << localUpdatePolicy
 
  319                 int32_t timeToLiveSeconds;
 
  320                 int32_t maxIdleSeconds;
 
  322                 InMemoryFormat inMemoryFormat;
 
  326                 bool invalidateOnChange;
 
  327                 bool cacheLocalEntries;
 
  337                 boost::shared_ptr<EvictionConfig<K, V> > evictionConfig;
 
  339                 int32_t calculateMaxSize(int32_t maxSize) {
 
  340                     return (maxSize == 0) ? INT32_MAX : util::Preconditions::checkNotNegative(maxSize,
 
  341                                                                                               "Max-size cannot be negative!");
 
  345             template<
typename K, 
typename V>
 
  346             const int32_t NearCacheConfig<K, V>::DEFAULT_TTL_SECONDS = 0;
 
  348             template<
typename K, 
typename V>
 
  349             const int32_t NearCacheConfig<K, V>::DEFAULT_MAX_IDLE_SECONDS = 0;
 
  351             template<
typename K, 
typename V>
 
  352             const InMemoryFormat NearCacheConfig<K, V>::DEFAULT_MEMORY_FORMAT = BINARY;
 
  357 #if  defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 
bool isInvalidateOnChange() const 
True to evict the cached entries if the entries are changed (updated or removed). ...
Definition: NearCacheConfig.h:206
 
Configuration for eviction. 
Definition: EvictionConfig.h:42
 
bool isCacheLocalEntries() const 
If true, cache local entries also. 
Definition: NearCacheConfig.h:257
 
NearCacheConfig & setInvalidateOnChange(bool invalidateOnChange)
True to evict the cached entries if the entries are changed (updated or removed). ...
Definition: NearCacheConfig.h:220
 
static const InMemoryFormat DEFAULT_MEMORY_FORMAT
Default value for the in-memory format. 
Definition: NearCacheConfig.h:57
 
This is a marker class to indicate that the derived class is a near cache config. ...
Definition: NearCacheConfigBase.h:32
 
Contains the configuration for a Near Cache. 
Definition: NearCacheConfig.h:42
 
NearCacheConfig & setMaxIdleSeconds(int32_t maxIdleSeconds)
Maximum number of seconds each entry can stay in the Near Cache as untouched (not-read). 
Definition: NearCacheConfig.h:192
 
LocalUpdatePolicy
Local Update Policy enum. 
Definition: NearCacheConfig.h:62
 
int32_t getMaxIdleSeconds() const 
Maximum number of seconds each entry can stay in the Near Cache as untouched (not-read). 
Definition: NearCacheConfig.h:178
 
INVALIDATE POLICY. 
Definition: NearCacheConfig.h:66
 
const std::string & getName() const 
Gets the name of the Near Cache. 
Definition: NearCacheConfig.h:131
 
static const int32_t DEFAULT_MAX_IDLE_SECONDS
Default value of the idle time for eviction in seconds. 
Definition: NearCacheConfig.h:52
 
NearCacheConfig & setEvictionConfig(const boost::shared_ptr< EvictionConfig< K, V > > &evictionConfig)
Sets the eviction configuration. 
Definition: NearCacheConfig.h:297
 
NearCacheConfig & setCacheLocalEntries(bool cacheLocalEntries)
True to cache local entries also. 
Definition: NearCacheConfig.h:268
 
NearCacheConfig & setName(const std::string &name)
Sets the name of the Near Cache. 
Definition: NearCacheConfig.h:141
 
int32_t getTimeToLiveSeconds() const 
Gets the maximum number of seconds for each entry to stay in the Near Cache. 
Definition: NearCacheConfig.h:152
 
CACHE ON UPDATE POLICY. 
Definition: NearCacheConfig.h:71
 
static const int32_t DEFAULT_TTL_SECONDS
Default value of the time to live in seconds. 
Definition: NearCacheConfig.h:47
 
const InMemoryFormat & getInMemoryFormat() const 
Gets the data type used to store entries. 
Definition: NearCacheConfig.h:233
 
NearCacheConfig & setTimeToLiveSeconds(int32_t timeToLiveSeconds)
Sets the maximum number of seconds for each entry to stay in the Near Cache. 
Definition: NearCacheConfig.h:164
 
const boost::shared_ptr< EvictionConfig< K, V > > & getEvictionConfig() const 
The eviction configuration. 
Definition: NearCacheConfig.h:287
 
NearCacheConfig & setInMemoryFormat(const InMemoryFormat &inMemoryFormat)
Sets the data type used to store entries. 
Definition: NearCacheConfig.h:246