@Override public EvictionConfig getEvictionConfig() { return super.getEvictionConfig().getAsReadOnly(); }
@Override public EvictionConfig getEvictionConfig() { return super.getEvictionConfig().getAsReadOnly(); }
private static void checkOnHeapNearCacheMaxSizePolicy(NearCacheConfig nearCacheConfig) { InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat(); if (inMemoryFormat == NATIVE) { return; } MaxSizePolicy maxSizePolicy = nearCacheConfig.getEvictionConfig().getMaximumSizePolicy(); if (!SUPPORTED_ON_HEAP_NEAR_CACHE_MAXSIZE_POLICIES.contains(maxSizePolicy)) { throw new IllegalArgumentException(format("Near Cache maximum size policy %s cannot be used with %s storage." + " Supported maximum size policies are: %s", maxSizePolicy, inMemoryFormat, SUPPORTED_ON_HEAP_NEAR_CACHE_MAXSIZE_POLICIES)); } }
private static void checkOnHeapNearCacheMaxSizePolicy(NearCacheConfig nearCacheConfig) { InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat(); if (inMemoryFormat == NATIVE) { return; } MaxSizePolicy maxSizePolicy = nearCacheConfig.getEvictionConfig().getMaximumSizePolicy(); if (!SUPPORTED_ON_HEAP_NEAR_CACHE_MAXSIZE_POLICIES.contains(maxSizePolicy)) { throw new IllegalArgumentException(format("Near Cache maximum size policy %s cannot be used with %s storage." + " Supported maximum size policies are: %s", maxSizePolicy, inMemoryFormat, SUPPORTED_ON_HEAP_NEAR_CACHE_MAXSIZE_POLICIES)); } }
public static void initDefaultMaxSizeForOnHeapMaps(NearCacheConfig nearCacheConfig) { if (nearCacheConfig == null) { return; } EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); if (nearCacheConfig.getInMemoryFormat() != InMemoryFormat.NATIVE && !evictionConfig.sizeConfigured) { evictionConfig.setSize(EvictionConfig.DEFAULT_MAX_ENTRY_COUNT_FOR_ON_HEAP_MAP); } } }
public static void initDefaultMaxSizeForOnHeapMaps(NearCacheConfig nearCacheConfig) { if (nearCacheConfig == null) { return; } EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); if (nearCacheConfig.getInMemoryFormat() != InMemoryFormat.NATIVE && !evictionConfig.sizeConfigured) { evictionConfig.setSize(EvictionConfig.DEFAULT_MAX_ENTRY_COUNT_FOR_ON_HEAP_MAP); } } }
protected AbstractNearCacheRecordStore(NearCacheConfig nearCacheConfig, NearCacheStatsImpl nearCacheStats, SerializationService serializationService, ClassLoader classLoader) { this.nearCacheConfig = nearCacheConfig; this.timeToLiveMillis = nearCacheConfig.getTimeToLiveSeconds() * MILLI_SECONDS_IN_A_SECOND; this.maxIdleMillis = nearCacheConfig.getMaxIdleSeconds() * MILLI_SECONDS_IN_A_SECOND; this.serializationService = serializationService; this.classLoader = classLoader; this.nearCacheStats = nearCacheStats; this.evictionDisabled = nearCacheConfig.getEvictionConfig().getEvictionPolicy() == EvictionPolicy.NONE; }
@Override public void initialize() { this.records = createNearCacheRecordMap(nearCacheConfig); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); this.evictionChecker = createNearCacheEvictionChecker(evictionConfig, nearCacheConfig); if (!evictionDisabled) { this.evictionStrategy = SamplingEvictionStrategy.INSTANCE; this.evictionPolicyEvaluator = getEvictionPolicyEvaluator(evictionConfig, classLoader); } }
@Override public void initialize() { this.records = createNearCacheRecordMap(nearCacheConfig); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); this.evictionChecker = createNearCacheEvictionChecker(evictionConfig, nearCacheConfig); if (!evictionDisabled) { this.evictionStrategy = SamplingEvictionStrategy.INSTANCE; this.evictionPolicyEvaluator = getEvictionPolicyEvaluator(evictionConfig, classLoader); } }
protected AbstractNearCacheRecordStore(NearCacheConfig nearCacheConfig, NearCacheStatsImpl nearCacheStats, SerializationService serializationService, ClassLoader classLoader) { this.nearCacheConfig = nearCacheConfig; this.inMemoryFormat = nearCacheConfig.getInMemoryFormat(); this.timeToLiveMillis = nearCacheConfig.getTimeToLiveSeconds() * MILLI_SECONDS_IN_A_SECOND; this.maxIdleMillis = nearCacheConfig.getMaxIdleSeconds() * MILLI_SECONDS_IN_A_SECOND; this.serializationService = serializationService; this.classLoader = classLoader; this.nearCacheStats = nearCacheStats; this.evictionDisabled = nearCacheConfig.getEvictionConfig().getEvictionPolicy() == EvictionPolicy.NONE; }
/** * This method creates a copy of {@link NearCacheConfig} <strong>without</strong> copying read-only objects for * class fields, which may contain trash from previous invocations of near cache methods (this problem comes from * the fact, that HZ treats map configs as a const values after cluster startup, but atlassian cache allows to * change them after cluster is stared) * * @param nearCacheConfig {@link NearCacheConfig} to be copied * @return copy of the {@link NearCacheConfig} without read-only objects */ private NearCacheConfig copyNearCacheConfig(@Nonnull NearCacheConfig nearCacheConfig) { NearCacheConfig nearCacheConfigCopy = new NearCacheConfig(nearCacheConfig); EvictionConfig evictionConfigCopy = new EvictionConfig(nearCacheConfig.getEvictionConfig()); nearCacheConfigCopy.setEvictionConfig(evictionConfigCopy); NearCachePreloaderConfig preloaderConfigCopy = new NearCachePreloaderConfig(nearCacheConfigCopy.getPreloaderConfig()); nearCacheConfigCopy.setPreloaderConfig(preloaderConfigCopy); return nearCacheConfigCopy; }
/** * Checks preconditions to create a map proxy with Near Cache. * * @param mapName name of the map that Near Cache will be created for * @param nearCacheConfig the {@link NearCacheConfig} to be checked * @param nativeMemoryConfig the {@link NativeMemoryConfig} of the Hazelcast instance * @param isClient {@code true} if the config is for a Hazelcast client, {@code false} otherwise */ public static void checkNearCacheConfig(String mapName, NearCacheConfig nearCacheConfig, NativeMemoryConfig nativeMemoryConfig, boolean isClient) { checkNotNativeWhenOpenSource(nearCacheConfig.getInMemoryFormat()); checkLocalUpdatePolicy(mapName, nearCacheConfig.getLocalUpdatePolicy()); checkEvictionConfig(nearCacheConfig.getEvictionConfig(), true); checkOnHeapNearCacheMaxSizePolicy(nearCacheConfig); checkNearCacheNativeMemoryConfig(nearCacheConfig.getInMemoryFormat(), nativeMemoryConfig, getBuildInfo().isEnterprise()); if (isClient && nearCacheConfig.isCacheLocalEntries()) { throw new IllegalArgumentException("The Near Cache option `cache-local-entries` is not supported in " + "client configurations."); } checkPreloaderConfig(nearCacheConfig, isClient); }
public static NearCacheConfigHolder of(NearCacheConfig config, SerializationService serializationService) { if (config == null) { return null; } return new NearCacheConfigHolder(config.getName(), config.getInMemoryFormat().name(), config.isSerializeKeys(), config.isInvalidateOnChange(), config.getTimeToLiveSeconds(), config.getMaxIdleSeconds(), EvictionConfigHolder.of(config.getEvictionConfig(), serializationService), config.isCacheLocalEntries(), config.getLocalUpdatePolicy().name(), config.getPreloaderConfig()); } }
public static NearCacheConfigHolder of(NearCacheConfig config, SerializationService serializationService) { if (config == null) { return null; } return new NearCacheConfigHolder(config.getName(), config.getInMemoryFormat().name(), config.isSerializeKeys(), config.isInvalidateOnChange(), config.getTimeToLiveSeconds(), config.getMaxIdleSeconds(), EvictionConfigHolder.of(config.getEvictionConfig(), serializationService), config.isCacheLocalEntries(), config.getLocalUpdatePolicy().name(), config.getPreloaderConfig()); } }
private static ClientConfig newClientConfig(String mapName) { NativeMemoryConfig memoryConfig = new NativeMemoryConfig(); memoryConfig.setEnabled(true); memoryConfig.setSize(new MemorySize(128, MEGABYTES)); memoryConfig.setAllocatorType(STANDARD); NearCacheConfig nearCacheConfig = new NearCacheConfig(); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); evictionConfig.setMaximumSizePolicy(USED_NATIVE_MEMORY_PERCENTAGE); evictionConfig.setSize(90); nearCacheConfig.setInMemoryFormat(NATIVE); nearCacheConfig.setInvalidateOnChange(true); nearCacheConfig.setName(mapName); ClientConfig clientConfig = new ClientConfig(); clientConfig.setNativeMemoryConfig(memoryConfig); clientConfig.addNearCacheConfig(nearCacheConfig); clientConfig.setLicenseKey(ENTERPRISE_LICENSE_KEY); return clientConfig; } }
private static Config newConfig() { NearCacheConfig nearCacheConfig = new NearCacheConfig(); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); evictionConfig.setMaximumSizePolicy(USED_NATIVE_MEMORY_PERCENTAGE); evictionConfig.setSize(90); nearCacheConfig.setInMemoryFormat(NATIVE); nearCacheConfig.setInvalidateOnChange(true); nearCacheConfig.setCacheLocalEntries(true); nearCacheConfig.setName("default"); MapConfig mapConfig = new MapConfig(); mapConfig.setName("default"); mapConfig.setNearCacheConfig(nearCacheConfig); NativeMemoryConfig memoryConfig = new NativeMemoryConfig(); memoryConfig.setEnabled(true); memoryConfig.setSize(new MemorySize(128, MEGABYTES)); memoryConfig.setAllocatorType(STANDARD); Config config = new Config(); config.addMapConfig(mapConfig); config.setNativeMemoryConfig(memoryConfig); config.setLicenseKey(ENTERPRISE_LICENSE_KEY); return config; } }
@SuppressWarnings("deprecation") private static void mapNearCacheConfigXmlGenerator(XmlGenerator gen, NearCacheConfig n) { if (n != null) { if (n.getName() != null) { gen.open("near-cache", "name", n.getName()); } else { gen.open("near-cache"); } gen.node("in-memory-format", n.getInMemoryFormat()) .node("invalidate-on-change", n.isInvalidateOnChange()) .node("time-to-live-seconds", n.getTimeToLiveSeconds()) .node("max-idle-seconds", n.getMaxIdleSeconds()) .node("serialize-keys", n.isSerializeKeys()) .node("cache-local-entries", n.isCacheLocalEntries()) .node("max-size", n.getMaxSize()) .node("eviction-policy", n.getEvictionPolicy()); evictionConfigXmlGenerator(gen, n.getEvictionConfig()); gen.close(); } }
@SuppressWarnings("deprecation") private static void mapNearCacheConfigXmlGenerator(XmlGenerator gen, NearCacheConfig n) { if (n != null) { if (n.getName() != null) { gen.open("near-cache", "name", n.getName()); } else { gen.open("near-cache"); } gen.node("in-memory-format", n.getInMemoryFormat()) .node("invalidate-on-change", n.isInvalidateOnChange()) .node("time-to-live-seconds", n.getTimeToLiveSeconds()) .node("max-idle-seconds", n.getMaxIdleSeconds()) .node("serialize-keys", n.isSerializeKeys()) .node("cache-local-entries", n.isCacheLocalEntries()) .node("max-size", n.getMaxSize()) .node("eviction-policy", n.getEvictionPolicy()); evictionConfigXmlGenerator(gen, n.getEvictionConfig()); gen.close(); } }
private static void nearCache(XmlGenerator gen, String name, NearCacheConfig nearCache) { EvictionConfig eviction = nearCache.getEvictionConfig(); NearCachePreloaderConfig preloader = nearCache.getPreloaderConfig(); gen.open("near-cache", "name", name) .node("in-memory-format", nearCache.getInMemoryFormat()) .node("serialize-keys", nearCache.isSerializeKeys()) .node("invalidate-on-change", nearCache.isInvalidateOnChange()) .node("cache-local-entries", nearCache.isCacheLocalEntries()) .node("time-to-live-seconds", nearCache.getTimeToLiveSeconds()) .node("max-idle-seconds", nearCache.getMaxIdleSeconds()) .node("local-update-policy", nearCache.getLocalUpdatePolicy()) .node("eviction", null, "size", eviction.getSize(), "max-size-policy", eviction.getMaximumSizePolicy(), "eviction-policy", eviction.getEvictionPolicy()) .node("preloader", null, "enabled", preloader.isEnabled(), "directory", preloader.getDirectory(), "store-initial-delay-seconds", preloader.getStoreInitialDelaySeconds(), "store-interval-seconds", preloader.getStoreIntervalSeconds()); //close near-cache gen.close(); }
private static void nearCache(XmlGenerator gen, String name, NearCacheConfig nearCache) { EvictionConfig eviction = nearCache.getEvictionConfig(); NearCachePreloaderConfig preloader = nearCache.getPreloaderConfig(); gen.open("near-cache", "name", name) .node("in-memory-format", nearCache.getInMemoryFormat()) .node("serialize-keys", nearCache.isSerializeKeys()) .node("invalidate-on-change", nearCache.isInvalidateOnChange()) .node("cache-local-entries", nearCache.isCacheLocalEntries()) .node("time-to-live-seconds", nearCache.getTimeToLiveSeconds()) .node("max-idle-seconds", nearCache.getMaxIdleSeconds()) .node("local-update-policy", nearCache.getLocalUpdatePolicy()) .node("eviction", null, "size", eviction.getSize(), "max-size-policy", eviction.getMaximumSizePolicy(), "eviction-policy", eviction.getEvictionPolicy()) .node("preloader", null, "enabled", preloader.isEnabled(), "directory", preloader.getDirectory(), "store-initial-delay-seconds", preloader.getStoreInitialDelaySeconds(), "store-interval-seconds", preloader.getStoreIntervalSeconds()); //close near-cache gen.close(); }