private static CacheConfig createCacheConfig(String cacheName) { return (CacheConfig) new CacheConfig() .setEvictionConfig(createEvictionConfig()) .setInMemoryFormat(InMemoryFormat.NATIVE) .setName(cacheName) .setStatisticsEnabled(true); }
private static CacheConfig createCacheConfig(String cacheName, boolean useExpiryPolicyFactory) { CacheConfig config = new CacheConfig().setName(cacheName); if (useExpiryPolicyFactory) { config.setExpiryPolicyFactory(new Factory<ExpiryPolicy>() { @Override public ExpiryPolicy create() { return new MyExpiryPolicy(); } }); } return config; }
target.setAsyncBackupCount(getAsyncBackupCount()); target.setBackupCount(getBackupCount()); target.setDisablePerEntryInvalidationEvents(isDisablePerEntryInvalidationEvents()); target.setEvictionConfig(getEvictionConfig()); target.setHotRestartConfig(getHotRestartConfig()); target.setInMemoryFormat(getInMemoryFormat()); if (resolved) { target.setKeyType(getKeyType()); target.setValueType(getValueType()); } else { target.setKeyClassName(getKeyClassName()); target.setValueClassName(getValueClassName()); target.listenerConfigurations = createConcurrentSet(); for (DeferredValue<CacheEntryListenerConfiguration<K, V>> lazyEntryListenerConfig : listenerConfigurations) { target.listenerConfigurations.add(lazyEntryListenerConfig.shallowCopy()); target.setManagementEnabled(isManagementEnabled()); target.setManagerPrefix(getManagerPrefix()); target.setMergePolicy(getMergePolicy()); target.setName(getName()); target.setPartitionLostListenerConfigs(getPartitionLostListenerConfigs()); target.setQuorumName(getQuorumName()); target.setReadThrough(isReadThrough()); target.setStatisticsEnabled(isStatisticsEnabled()); target.setStoreByValue(isStoreByValue()); target.setUriString(getUriString()); target.setWanReplicationRef(getWanReplicationRef()); target.setWriteThrough(isWriteThrough());
protected <K, V> CacheConfig<K, V> createCacheConfig(String cacheName, InMemoryFormat inMemoryFormat) { return new CacheConfig<K, V>() .setName(DEFAULT_CACHE_NAME) .setInMemoryFormat(inMemoryFormat); }
protected static CacheConfig newCacheConfig(String cacheName, String mergePolicy) { CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setName(cacheName); cacheConfig.setMergePolicy(mergePolicy); return cacheConfig; }
@Override @SuppressWarnings("unchecked") public void readData(ObjectDataInput in) throws IOException { config.setName(in.readUTF()); config.setManagerPrefix(in.readUTF()); config.setUriString(in.readUTF()); config.setBackupCount(in.readInt()); config.setAsyncBackupCount(in.readInt()); config.setInMemoryFormat(InMemoryFormat.valueOf(resultInMemoryFormat)); LegacyCacheEvictionConfig legacyConfig = in.readObject(LegacyCacheEvictionConfig.class); config.setEvictionConfig(legacyConfig.getConfig()); config.setWanReplicationRef((WanReplicationRef) in.readObject()); config.setKeyType((Class<K>) in.readObject()); config.setValueType((Class<V>) in.readObject()); config.setCacheLoaderFactory((Factory<? extends CacheLoader<K, V>>) in.readObject()); config.setCacheWriterFactory((Factory<? extends CacheWriter<? super K, ? super V>>) in.readObject()); config.setExpiryPolicyFactory((Factory<? extends ExpiryPolicy>) in.readObject()); config.setReadThrough(in.readBoolean()); config.setWriteThrough(in.readBoolean()); config.setStoreByValue(in.readBoolean()); config.setManagementEnabled(in.readBoolean()); config.setStatisticsEnabled(in.readBoolean()); config.getHotRestartConfig().setEnabled(in.readBoolean()); config.getHotRestartConfig().setFsync(in.readBoolean()); config.setQuorumName(in.readUTF());
@Override public void writeData(ObjectDataOutput out) throws IOException { out.writeUTF(config.getName()); out.writeUTF(config.getManagerPrefix()); out.writeUTF(config.getUriString()); out.writeInt(config.getBackupCount()); out.writeInt(config.getAsyncBackupCount()); out.writeUTF(config.getInMemoryFormat().name()); out.writeObject(new LegacyCacheEvictionConfig(config.getEvictionConfig())); out.writeObject(config.getWanReplicationRef()); out.writeObject(config.getKeyType()); out.writeObject(config.getValueType()); out.writeObject(config.getCacheLoaderFactory()); out.writeObject(config.getCacheWriterFactory()); out.writeObject(config.getExpiryPolicyFactory()); out.writeBoolean(config.isReadThrough()); out.writeBoolean(config.isWriteThrough()); out.writeBoolean(config.isStoreByValue()); out.writeBoolean(config.isManagementEnabled()); out.writeBoolean(config.isStatisticsEnabled()); out.writeBoolean(config.getHotRestartConfig().isEnabled()); out.writeBoolean(config.getHotRestartConfig().isFsync()); out.writeUTF(config.getQuorumName()); (Set<CacheEntryListenerConfiguration<K, V>>) config.getCacheEntryListenerConfigurations();
|| ((manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass) == null))) { cacheEntryList = new ConcurrentSkipListSet<>(); cacheConfig = new CacheConfig<K, T>(); cacheConfig.setTypes(keyClass, persistentClass); if (properties.getProperty(JCACHE_READ_THROUGH_PROPERTY_KEY) != null) { cacheConfig.setReadThrough(Boolean.valueOf(properties.getProperty(JCACHE_READ_THROUGH_PROPERTY_KEY))); } else { cacheConfig.setReadThrough(true); cacheConfig.setWriteThrough(Boolean.valueOf(properties.getProperty(JCACHE_WRITE_THROUGH_PROPERTY_KEY))); } else { cacheConfig.setWriteThrough(true); cacheConfig.setStoreByValue(Boolean.valueOf(properties.getProperty(JCACHE_STORE_BY_VALUE_PROPERTY_KEY))); cacheConfig.setStatisticsEnabled(Boolean.valueOf(properties.getProperty(JCACHE_STATISTICS_PROPERTY_KEY))); cacheConfig.setStatisticsEnabled(Boolean.valueOf(properties.getProperty(JCACHE_MANAGEMENT_PROPERTY_KEY))); cacheConfig.getEvictionConfig() .setEvictionPolicy(EvictionPolicy.valueOf(properties.getProperty(JCACHE_EVICTION_POLICY_PROPERTY_KEY))); cacheConfig.getEvictionConfig() .setMaximumSizePolicy(EvictionConfig.MaxSizePolicy .valueOf(properties.getProperty(JCACHE_EVICTION_MAX_SIZE_POLICY_PROPERTY_KEY))); cacheConfig.getEvictionConfig() .setSize(Integer.valueOf(properties.getProperty(JCACHE_EVICTION_SIZE_PROPERTY_KEY)));
CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class); System.out.println("key type: " + cacheConfig.getKeyType()); System.out.println("value type: " + cacheConfig.getValueType()); System.out.println("statistics enabled: " + cacheConfig.isStatisticsEnabled()); System.out.println("management enabled: " + cacheConfig.isManagementEnabled()); System.out.println("read-through enabled: " + cacheConfig.isReadThrough()); System.out.println("write-through enabled: " + cacheConfig.isWriteThrough()); System.out.println("loader factory: " + cacheConfig.getCacheLoaderFactory()); System.out.println("writer factory: " + cacheConfig.getCacheWriterFactory()); System.out.println("expiry policy factory: " + cacheConfig.getExpiryPolicyFactory()); = cacheConfig.getCacheEntryListenerConfigurations(); for (CacheEntryListenerConfiguration cacheEntryListenerConfiguration : cacheEntryListenerConfigurations) { System.out.println("listener factory: " + cacheEntryListenerConfiguration.getCacheEntryListenerFactory()); System.out.println("in-memory-format: " + cacheConfig.getInMemoryFormat()); System.out.println("backup count: " + cacheConfig.getBackupCount()); System.out.println("async backup count: " + cacheConfig.getAsyncBackupCount()); EvictionConfig evictionConfig = cacheConfig.getEvictionConfig(); System.out.println("max-size: " + evictionConfig.getSize()); System.out.println("max-size-policy: " + evictionConfig.getMaximumSizePolicy());
this.eventJournalConfig = nodeEngine.getConfig().findCacheEventJournalConfig(cacheConfig.getName()); this.evictionConfig = cacheConfig.getEvictionConfig(); if (evictionConfig == null) { throw new IllegalStateException("Eviction config cannot be null!"); this.disablePerEntryInvalidationEvents = cacheConfig.isDisablePerEntryInvalidationEvents(); if (cacheConfig.isStatisticsEnabled()) { statistics = cacheService.createCacheStatIfAbsent(cacheNameWithPrefix); if (cacheConfig.getCacheLoaderFactory() != null) { Factory<CacheLoader> cacheLoaderFactory = cacheConfig.getCacheLoaderFactory(); injectDependencies(cacheLoaderFactory); cacheLoader = cacheLoaderFactory.create(); injectDependencies(cacheLoader); if (cacheConfig.getCacheWriterFactory() != null) { Factory<CacheWriter> cacheWriterFactory = cacheConfig.getCacheWriterFactory(); injectDependencies(cacheWriterFactory); cacheWriter = cacheWriterFactory.create(); injectDependencies(cacheWriter); if (cacheConfig.getExpiryPolicyFactory() != null) { Factory<ExpiryPolicy> expiryPolicyFactory = cacheConfig.getExpiryPolicyFactory(); injectDependencies(expiryPolicyFactory); defaultExpiryPolicy = expiryPolicyFactory.create(); this.objectNamespace = CacheService.getObjectNamespace(cacheNameWithPrefix); this.persistWanReplicatedData = canPersistWanReplicatedData(cacheConfig, nodeEngine); this.cacheRecordFactory = new CacheRecordFactory(cacheConfig.getInMemoryFormat(), ss);
@SuppressWarnings("unchecked") protected <K, V, C extends Configuration<K, V>> CacheConfig<K, V> createCacheConfig(String cacheName, C configuration) { CacheConfig<K, V> cacheConfig; if (configuration instanceof CompleteConfiguration) { cacheConfig = new CacheConfig<K, V>((CompleteConfiguration<K, V>) configuration); } else { cacheConfig = new CacheConfig<K, V>(); cacheConfig.setStoreByValue(configuration.isStoreByValue()); Class<K> keyType = configuration.getKeyType(); Class<V> valueType = configuration.getValueType(); cacheConfig.setTypes(keyType, valueType); } cacheConfig.setName(cacheName); cacheConfig.setManagerPrefix(this.cacheNamePrefix); cacheConfig.setUriString(getURI().toString()); return cacheConfig; }
@SuppressWarnings("unused") public LegacyCacheConfig() { config = new CacheConfig<K, V>(); }
@Setup public void setup() { counters = targetInstance.getList(name + "counters"); RecordingCacheLoader<Integer> loader = new RecordingCacheLoader<Integer>(); loader.loadDelayMs = getDelayMs; RecordingCacheWriter<Integer, Integer> writer = new RecordingCacheWriter<Integer, Integer>(); writer.writeDelayMs = putDelayMs; writer.deleteDelayMs = removeDelayMs; config = new CacheConfig<Integer, Integer>(); config.setReadThrough(true); config.setWriteThrough(true); config.setCacheLoaderFactory(FactoryBuilder.factoryOf(loader)); config.setCacheWriterFactory(FactoryBuilder.factoryOf(writer)); CacheManager cacheManager = createCacheManager(targetInstance); cacheManager.createCache(name, config); cache = cacheManager.getCache(name); }
CacheConfig cacheConfig = new CacheConfig(cacheSimpleConfig); cacheConfig.setManagerPrefix(HazelcastCacheManager.CACHE_MANAGER_PREFIX); return new CacheProxy(cacheConfig, nodeEngine, this); } else { throw new CacheNotExistsException("Couldn't find cache config with name " + cacheNameWithPrefix); cacheConfig.setManagerPrefix(HazelcastCacheManager.CACHE_MANAGER_PREFIX); Object mergePolicy = mergePolicyProvider.getMergePolicy(cacheConfig.getMergePolicy()); checkMergePolicySupportsInMemoryFormat(cacheConfig.getName(), mergePolicy, cacheConfig.getInMemoryFormat(), true, logger);
@Override public CacheConfig findCacheConfig(String simpleName) { if (simpleName == null) { return null; } CacheSimpleConfig cacheSimpleConfig = nodeEngine.getConfig().findCacheConfigOrNull(simpleName); if (cacheSimpleConfig == null) { return null; } try { // Set name explicitly, because found config might have a wildcard name. return new CacheConfig(cacheSimpleConfig).setName(simpleName); } catch (Exception e) { throw new CacheException(e); } }
/** * Create a new {@link CacheConfig} with configured settings before {@link CacheManagerAware} implementor. */ private CacheConfig<?, ?> newCacheConfig(final String name) { final CacheConfig<?, ?> config = new CacheConfig<>(name); config.setEvictionConfig(new EvictionConfig().setEvictionPolicy(EvictionPolicy.LRU) .setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT)); config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ETERNAL)); // Post configuration postConfigure(config); return config; }
private static CacheConfig createCacheConfig(String cacheName, boolean evictionPolicyComparatorByName) { EvictionConfig evictionConfig = evictionPolicyComparatorByName ? new EvictionConfig().setComparatorClassName(MyEvictionPolicyComparator.class.getName()) : new EvictionConfig().setComparator(new MyEvictionPolicyComparator()); return new CacheConfig() .setName(cacheName) .setEvictionConfig(evictionConfig); }
private static Cache<Integer, String> createCache(HazelcastInstance instance) { CachingProvider cachingProvider = HazelcastServerCachingProvider .createCachingProvider(instance); CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>("cache"); cacheConfig.getHotRestartConfig().setEnabled(true); return cachingProvider.getCacheManager().createCache("cache", cacheConfig); } }
protected void readFactories(ObjectDataInput in) throws IOException { setCacheLoaderFactory(in.<Factory<? extends CacheLoader<K, V>>>readObject()); setCacheWriterFactory(in.<Factory<? extends CacheWriter<? super K, ? super V>>>readObject()); setExpiryPolicyFactory(in.<Factory<? extends ExpiryPolicy>>readObject()); }
protected void writeFactories(ObjectDataOutput out) throws IOException { out.writeObject(getCacheLoaderFactory()); out.writeObject(getCacheWriterFactory()); out.writeObject(getExpiryPolicyFactory()); }