@Override public InMemoryFormat getInMemoryFormat() { return nearCacheConfig.getInMemoryFormat(); }
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)); } }
protected NearCacheRecordStore<K, V> createNearCacheRecordStore(String name, NearCacheConfig nearCacheConfig) { InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat(); if (inMemoryFormat == null) { inMemoryFormat = DEFAULT_MEMORY_FORMAT; } switch (inMemoryFormat) { case BINARY: return new NearCacheDataRecordStore<K, V>(name, nearCacheConfig, serializationService, classLoader); case OBJECT: return new NearCacheObjectRecordStore<K, V>(name, nearCacheConfig, serializationService, classLoader); default: throw new IllegalArgumentException("Invalid in memory format: " + inMemoryFormat); } }
private static NearCacheConfig checkNearCacheConfig(NearCacheConfig nearCacheConfig, NativeMemoryConfig nativeMemoryConfig) { InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat(); if (inMemoryFormat != NATIVE) { return nearCacheConfig; } checkTrue(nativeMemoryConfig.isEnabled(), "Enable native memory config to use NATIVE in-memory-format for Near Cache"); return nearCacheConfig; }
protected NearCacheRecordStore<K, V> createNearCacheRecordStore(String name, NearCacheConfig nearCacheConfig) { InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat(); if (inMemoryFormat == null) { inMemoryFormat = DEFAULT_MEMORY_FORMAT; } switch (inMemoryFormat) { case BINARY: return new NearCacheDataRecordStore<K, V>(name, nearCacheConfig, serializationService, classLoader); case OBJECT: return new NearCacheObjectRecordStore<K, V>(name, nearCacheConfig, serializationService, classLoader); default: throw new IllegalArgumentException("Invalid in memory format: " + inMemoryFormat); } }
private static NearCacheConfig checkNearCacheConfig(NearCacheConfig nearCacheConfig, NativeMemoryConfig nativeMemoryConfig) { InMemoryFormat inMemoryFormat = nearCacheConfig.getInMemoryFormat(); if (inMemoryFormat != NATIVE) { return nearCacheConfig; } checkTrue(nativeMemoryConfig.isEnabled(), "Enable native memory config to use NATIVE in-memory-format for Near Cache"); return nearCacheConfig; }
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 <K, V> ICache<K, V> createCacheWithNearCache(String cacheName, NearCacheConfig nearCacheConfig) { CacheConfig<K, V> cacheConfig = createCacheConfig(nearCacheConfig.getInMemoryFormat()); return createCacheWithNearCache(cacheName, cacheConfig, nearCacheConfig); }
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; }
/** * 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); }
/** * 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); }
<K, V> HiDensityNearCacheSupportContext<K, V> createHiDensityCacheWithHiDensityNearCache(String cacheName, NearCacheConfig nearCacheConfig) { ClientConfig clientConfig = createClientConfig() .addNearCacheConfig(nearCacheConfig); HazelcastClientProxy client = (HazelcastClientProxy) HazelcastClient.newHazelcastClient(clientConfig); CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client); HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager(); CacheConfig<K, V> cacheConfig = createCacheConfig(nearCacheConfig.getInMemoryFormat()); ICache<K, V> cache = cacheManager.createCache(cacheName, cacheConfig); clients.add(client); EnterpriseSerializationService enterpriseSerializationService = (EnterpriseSerializationService) client.getSerializationService(); return new HiDensityNearCacheSupportContext<K, V>(cache, enterpriseSerializationService.getMemoryManager()); }
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()); } }
@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(); }