Class MutableConfiguration<K,V>
- Type Parameters:
K- the type of keys maintained the cacheV- the type of cached values
- All Implemented Interfaces:
Serializable, CompleteConfiguration<K,V>, Configuration<K, V>
Configuration.- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Factory<CacheLoader<K, V>> TheFactoryfor theCacheLoader.protected Factory<CacheWriter<? super K, ? super V>> TheFactoryfor theCacheWriter.protected Factory<ExpiryPolicy> TheFactoryfor theExpiryPolicy.protected booleanWhether management is enabledprotected booleanA flag indicating if "read-through" mode is required.protected booleanA flag indicating if statistics gathering is enabled.protected booleanA flag indicating if the cache will be store-by-value or store-by-reference.protected booleanA flag indicating if "write-through" mode is required.The type of keys forCaches configured with thisConfiguration.protected HashSet<CacheEntryListenerConfiguration<K, V>> TheCacheEntryListenerConfigurations for theConfiguration.static final longThe serialVersionUID required forSerializable.The type of values forCaches configured with thisConfiguration. -
Constructor Summary
ConstructorsConstructorDescriptionDefault JavaBean constructor.MutableConfiguration(CompleteConfiguration<K, V> configuration) Constructs aMutableConfigurationbased on anotherCompleteConfiguration. -
Method Summary
Modifier and TypeMethodDescriptionaddCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Add a configuration for aCacheEntryListener.booleanFactory<CacheLoader<K, V>> Gets theFactoryfor theCacheLoader, if any.Factory<CacheWriter<? super K, ? super V>> Gets theFactoryfor theCacheWriter, if any.Gets theFactoryfor theExpiryPolicyto be used for caches.Determines the required type of keys forCaches configured with thisConfiguration.Determines the required type of values forCaches configured with thisConfiguration.inthashCode()booleanChecks whether management is enabled on this cache.booleanDetermines if aCacheshould operate in read-through mode.booleanChecks whether statistics collection is enabled in this cache.booleanWhether storeByValue (true) or storeByReference (false).booleanDetermines if aCacheshould operate in write-through mode.removeCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Remove a configuration for aCacheEntryListener.setCacheLoaderFactory(Factory<? extends CacheLoader<K, V>> factory) Set theCacheLoaderfactory.setCacheWriterFactory(Factory<? extends CacheWriter<? super K, ? super V>> factory) Set theCacheWriterfactory.setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory) Set theFactoryfor theExpiryPolicy.setManagementEnabled(boolean enabled) Sets whether management is enabled on a cache.setReadThrough(boolean isReadThrough) Set if read-through caching should be used.setStatisticsEnabled(boolean enabled) Sets whether statistics gathering is enabled on a cache.setStoreByValue(boolean isStoreByValue) Set if a configured cache should use store-by-value or store-by-reference semantics.Sets the expected type of keys and values for aCacheconfigured with thisConfiguration.setWriteThrough(boolean isWriteThrough) Set if write-through caching should be used.
-
Field Details
-
serialVersionUID
-
keyType
The type of keys forCaches configured with thisConfiguration. -
valueType
The type of values forCaches configured with thisConfiguration. -
listenerConfigurations
TheCacheEntryListenerConfigurations for theConfiguration. -
cacheLoaderFactory
TheFactoryfor theCacheLoader. -
cacheWriterFactory
TheFactoryfor theCacheWriter. -
expiryPolicyFactory
TheFactoryfor theExpiryPolicy. -
isReadThrough
protected boolean isReadThroughA flag indicating if "read-through" mode is required. -
isWriteThrough
protected boolean isWriteThroughA flag indicating if "write-through" mode is required. -
isStatisticsEnabled
protected boolean isStatisticsEnabledA flag indicating if statistics gathering is enabled. -
isStoreByValue
protected boolean isStoreByValueA flag indicating if the cache will be store-by-value or store-by-reference. -
isManagementEnabled
protected boolean isManagementEnabledWhether management is enabled
-
-
Constructor Details
-
MutableConfiguration
public MutableConfiguration()Default JavaBean constructor.Creates a default configuration. Default configurations have no runtime type checking and are set for eternal expiry.
To enable runtime type enforcement, if supported by the implementation, call
setTypes(Class, Class)after construction.After construction set any other configuration parameters in the fluent style. e.g.
CacheConfiguration<Integer, String> = new MutableConfiguration<Integer, String>() .setTypes(Integer.class, String.class) .setReadThrough(true) . . .- See Also:
-
MutableConfiguration
Constructs aMutableConfigurationbased on anotherCompleteConfiguration.- Parameters:
configuration- theCompleteConfiguration
-
-
Method Details
-
getKeyType
Determines the required type of keys forCaches configured with thisConfiguration.- Specified by:
getKeyTypein interfaceConfiguration<K,V> - Returns:
- the key type or
Object.classif the type is undefined
-
getValueType
Determines the required type of values forCaches configured with thisConfiguration.- Specified by:
getValueTypein interfaceConfiguration<K,V> - Returns:
- the value type or
Object.classif the type is undefined
-
setTypes
Sets the expected type of keys and values for aCacheconfigured with thisConfiguration. Setting both toObject.classmeans type-safety checks are not required.This is used by
CacheManagerto ensure that the key and value types are the same as those configured for theCacheprior to returning a requested cache from this method.Implementations may further perform type checking on mutative cache operations and throw a
ClassCastExceptionif these checks fail.- Parameters:
keyType- the expected key typevalueType- the expected value type- Returns:
- the
MutableConfigurationto permit fluent-style method calls - Throws:
NullPointerException- should the key or value type be null- See Also:
-
getCacheEntryListenerConfigurations
- Specified by:
getCacheEntryListenerConfigurationsin interfaceCompleteConfiguration<K,V> - Returns:
- an
Iterableover theCacheEntryListenerConfigurations
-
addCacheEntryListenerConfiguration
public MutableConfiguration<K,V> addCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Add a configuration for aCacheEntryListener.- Parameters:
cacheEntryListenerConfiguration- theCacheEntryListenerConfiguration- Returns:
- the
MutableConfigurationto permit fluent-style method calls - Throws:
IllegalArgumentException- is the same CacheEntryListenerConfiguration is used more than once
-
removeCacheEntryListenerConfiguration
public MutableConfiguration<K,V> removeCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Remove a configuration for aCacheEntryListener.- Parameters:
cacheEntryListenerConfiguration- theCacheEntryListenerConfigurationto remove- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
getCacheLoaderFactory
Gets theFactoryfor theCacheLoader, if any.A CacheLoader should be configured for "Read Through" caches to load values when a cache miss occurs using either the
Cache.get(Object)and/orCache.getAll(java.util.Set)methods.The default value is
null.- Specified by:
getCacheLoaderFactoryin interfaceCompleteConfiguration<K,V> - Returns:
- the
Factoryfor theCacheLoaderor null if none has been set.
-
setCacheLoaderFactory
Set theCacheLoaderfactory.- Parameters:
factory- theCacheLoaderFactory- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
getCacheWriterFactory
- Specified by:
getCacheWriterFactoryin interfaceCompleteConfiguration<K,V> - Returns:
- the
Factoryfor theCacheWriteror null if none has been set.
-
setCacheWriterFactory
public MutableConfiguration<K,V> setCacheWriterFactory(Factory<? extends CacheWriter<? super K, ? super V>> factory) Set theCacheWriterfactory.- Parameters:
factory- theCacheWriterFactory- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
getExpiryPolicyFactory
Gets theFactoryfor theExpiryPolicyto be used for caches.The default value is a
Factorythat will produce aEternalExpiryPolicyinstance.- Specified by:
getExpiryPolicyFactoryin interfaceCompleteConfiguration<K,V> - Returns:
- the
FactoryforExpiryPolicy(must not benull)
-
setExpiryPolicyFactory
Set theFactoryfor theExpiryPolicy. Ifnullis specified the defaultExpiryPolicyis used.Only one expiry policy can be set for a cache. The last policy applied before cache construction will be the one used.
- Parameters:
factory- theExpiryPolicyFactory- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
isReadThrough
public boolean isReadThrough()Determines if aCacheshould operate in read-through mode.When in "read-through" mode, cache misses that occur due to cache entries not existing as a result of performing a "get" will appropriately cause the configured
CacheLoaderto be invoked.The default value is
false.- Specified by:
isReadThroughin interfaceCompleteConfiguration<K,V> - Returns:
truewhen aCacheis in "read-through" mode.- See Also:
-
setReadThrough
Set if read-through caching should be used.It is an invalid configuration to set this to true without specifying a
CacheLoaderFactory.- Parameters:
isReadThrough-trueif read-through is required- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
isWriteThrough
public boolean isWriteThrough()Determines if aCacheshould operate in write-through mode.When in "write-through" mode, cache updates that occur as a result of performing "put" operations called via one of
Cache.put(Object, Object),Cache.getAndRemove(Object),Cache.removeAll(),Cache.getAndPut(Object, Object)Cache.getAndRemove(Object),Cache.getAndReplace(Object, Object),Cache.invoke(Object, javax.cache.processor.EntryProcessor, Object...),Cache.invokeAll(java.util.Set, javax.cache.processor.EntryProcessor, Object...)will appropriately cause the configuredCacheWriterto be invoked.The default value is
false.- Specified by:
isWriteThroughin interfaceCompleteConfiguration<K,V> - Returns:
truewhen aCacheis in "write-through" mode.- See Also:
-
setWriteThrough
Set if write-through caching should be used.It is an invalid configuration to set this to true without specifying a
CacheWriterFactory.- Parameters:
isWriteThrough-trueif write-through is required- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
isStoreByValue
public boolean isStoreByValue()Whether storeByValue (true) or storeByReference (false). When true, both keys and values are stored by value.When false, both keys and values are stored by reference. Caches stored by reference are capable of mutation by any threads holding the reference. The effects are:
- if the key is mutated, then the key may not be retrievable or removable
- if the value is mutated, then all threads in the JVM can potentially observe those mutations, subject to the normal Java Memory Model rules.
When a cache is storeByValue, any mutation to the key or value does not affect the key of value stored in the cache.
The default value is
true.- Specified by:
isStoreByValuein interfaceConfiguration<K,V> - Returns:
- true if the cache is store by value
-
setStoreByValue
Set if a configured cache should use store-by-value or store-by-reference semantics.- Parameters:
isStoreByValue-trueif store-by-value is required,falsefor store-by-reference- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
isStatisticsEnabled
public boolean isStatisticsEnabled()Checks whether statistics collection is enabled in this cache.The default value is
false.- Specified by:
isStatisticsEnabledin interfaceCompleteConfiguration<K,V> - Returns:
- true if statistics collection is enabled
-
setStatisticsEnabled
Sets whether statistics gathering is enabled on a cache.Statistics may be enabled or disabled at runtime via
CacheManager.enableStatistics(String, boolean).- Parameters:
enabled- true to enable statistics, false to disable.- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
isManagementEnabled
public boolean isManagementEnabled()Checks whether management is enabled on this cache.The default value is
false.- Specified by:
isManagementEnabledin interfaceCompleteConfiguration<K,V> - Returns:
- true if management is enabled
-
setManagementEnabled
Sets whether management is enabled on a cache.Management may be enabled or disabled at runtime via
CacheManager.enableManagement(String, boolean).- Parameters:
enabled- true to enable statistics, false to disable.- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
hashCode
-
equals
-