Class MutableConfiguration<K,V>
- java.lang.Object
-
- javax.cache.configuration.MutableConfiguration<K,V>
-
- Type Parameters:
K- the type of keys maintained the cacheV- the type of cached values
- All Implemented Interfaces:
java.io.Serializable,CompleteConfiguration<K,V>,Configuration<K,V>
public class MutableConfiguration<K,V> extends java.lang.Object implements CompleteConfiguration<K,V>
A simple mutable implementation of aConfiguration.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Factory<CacheLoader<K,V>>cacheLoaderFactoryTheFactoryfor theCacheLoader.protected Factory<CacheWriter<? super K,? super V>>cacheWriterFactoryTheFactoryfor theCacheWriter.protected Factory<ExpiryPolicy>expiryPolicyFactoryTheFactoryfor theExpiryPolicy.protected booleanisManagementEnabledWhether management is enabledprotected booleanisReadThroughA flag indicating if "read-through" mode is required.protected booleanisStatisticsEnabledA flag indicating if statistics gathering is enabled.protected booleanisStoreByValueA flag indicating if the cache will be store-by-value or store-by-reference.protected booleanisWriteThroughA flag indicating if "write-through" mode is required.protected java.lang.Class<K>keyTypeThe type of keys forCaches configured with thisConfiguration.protected java.util.HashSet<CacheEntryListenerConfiguration<K,V>>listenerConfigurationsTheCacheEntryListenerConfigurations for theConfiguration.static longserialVersionUIDThe serialVersionUID required forSerializable.protected java.lang.Class<V>valueTypeThe type of values forCaches configured with thisConfiguration.
-
Constructor Summary
Constructors Constructor Description MutableConfiguration()Default JavaBean constructor.MutableConfiguration(CompleteConfiguration<K,V> configuration)Constructs aMutableConfigurationbased on anotherCompleteConfiguration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MutableConfiguration<K,V>addCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)Add a configuration for aCacheEntryListener.booleanequals(java.lang.Object object)java.lang.Iterable<CacheEntryListenerConfiguration<K,V>>getCacheEntryListenerConfigurations()Factory<CacheLoader<K,V>>getCacheLoaderFactory()Gets theFactoryfor theCacheLoader, if any.Factory<CacheWriter<? super K,? super V>>getCacheWriterFactory()Gets theFactoryfor theCacheWriter, if any.Factory<ExpiryPolicy>getExpiryPolicyFactory()Gets theFactoryfor theExpiryPolicyto be used for caches.java.lang.Class<K>getKeyType()Determines the required type of keys forCaches configured with thisConfiguration.java.lang.Class<V>getValueType()Determines the required type of values forCaches configured with thisConfiguration.inthashCode()booleanisManagementEnabled()Checks whether management is enabled on this cache.booleanisReadThrough()Determines if aCacheshould operate in read-through mode.booleanisStatisticsEnabled()Checks whether statistics collection is enabled in this cache.booleanisStoreByValue()Whether storeByValue (true) or storeByReference (false).booleanisWriteThrough()Determines if aCacheshould operate in write-through mode.MutableConfiguration<K,V>removeCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)Remove a configuration for aCacheEntryListener.MutableConfiguration<K,V>setCacheLoaderFactory(Factory<? extends CacheLoader<K,V>> factory)Set theCacheLoaderfactory.MutableConfiguration<K,V>setCacheWriterFactory(Factory<? extends CacheWriter<? super K,? super V>> factory)Set theCacheWriterfactory.MutableConfiguration<K,V>setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory)Set theFactoryfor theExpiryPolicy.MutableConfiguration<K,V>setManagementEnabled(boolean enabled)Sets whether management is enabled on a cache.MutableConfiguration<K,V>setReadThrough(boolean isReadThrough)Set if read-through caching should be used.MutableConfiguration<K,V>setStatisticsEnabled(boolean enabled)Sets whether statistics gathering is enabled on a cache.MutableConfiguration<K,V>setStoreByValue(boolean isStoreByValue)Set if a configured cache should use store-by-value or store-by-reference semantics.MutableConfiguration<K,V>setTypes(java.lang.Class<K> keyType, java.lang.Class<V> valueType)Sets the expected type of keys and values for aCacheconfigured with thisConfiguration.MutableConfiguration<K,V>setWriteThrough(boolean isWriteThrough)Set if write-through caching should be used.
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
The serialVersionUID required forSerializable.- See Also:
- Constant Field Values
-
keyType
protected java.lang.Class<K> keyType
The type of keys forCaches configured with thisConfiguration.
-
valueType
protected java.lang.Class<V> valueType
The type of values forCaches configured with thisConfiguration.
-
listenerConfigurations
protected java.util.HashSet<CacheEntryListenerConfiguration<K,V>> listenerConfigurations
TheCacheEntryListenerConfigurations for theConfiguration.
-
cacheLoaderFactory
protected Factory<CacheLoader<K,V>> cacheLoaderFactory
TheFactoryfor theCacheLoader.
-
cacheWriterFactory
protected Factory<CacheWriter<? super K,? super V>> cacheWriterFactory
TheFactoryfor theCacheWriter.
-
expiryPolicyFactory
protected Factory<ExpiryPolicy> expiryPolicyFactory
TheFactoryfor theExpiryPolicy.
-
isReadThrough
protected boolean isReadThrough
A flag indicating if "read-through" mode is required.
-
isWriteThrough
protected boolean isWriteThrough
A flag indicating if "write-through" mode is required.
-
isStatisticsEnabled
protected boolean isStatisticsEnabled
A flag indicating if statistics gathering is enabled.
-
isStoreByValue
protected boolean isStoreByValue
A flag indicating if the cache will be store-by-value or store-by-reference.
-
isManagementEnabled
protected boolean isManagementEnabled
Whether management is enabled
-
-
Constructor Detail
-
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(java.lang.Class<K>, java.lang.Class<V>)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:
setTypes(Class, Class)
-
MutableConfiguration
public MutableConfiguration(CompleteConfiguration<K,V> configuration)
Constructs aMutableConfigurationbased on anotherCompleteConfiguration.- Parameters:
configuration- theCompleteConfiguration
-
-
Method Detail
-
getKeyType
public java.lang.Class<K> 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
public java.lang.Class<V> 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
public MutableConfiguration<K,V> setTypes(java.lang.Class<K> keyType, java.lang.Class<V> valueType)
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:
java.lang.NullPointerException- should the key or value type be null- See Also:
CacheManager.getCache(String, Class, Class)
-
getCacheEntryListenerConfigurations
public java.lang.Iterable<CacheEntryListenerConfiguration<K,V>> 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:
java.lang.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
public Factory<CacheLoader<K,V>> 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
public MutableConfiguration<K,V> setCacheLoaderFactory(Factory<? extends CacheLoader<K,V>> factory)
Set theCacheLoaderfactory.- Parameters:
factory- theCacheLoaderFactory- Returns:
- the
MutableConfigurationto permit fluent-style method calls
-
getCacheWriterFactory
public Factory<CacheWriter<? super K,? super V>> 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
public Factory<ExpiryPolicy> 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
public MutableConfiguration<K,V> setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory)
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:
CompleteConfiguration.getCacheLoaderFactory()
-
setReadThrough
public MutableConfiguration<K,V> setReadThrough(boolean isReadThrough)
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:
CompleteConfiguration.getCacheWriterFactory()
-
setWriteThrough
public MutableConfiguration<K,V> setWriteThrough(boolean isWriteThrough)
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
public MutableConfiguration<K,V> setStoreByValue(boolean isStoreByValue)
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
public MutableConfiguration<K,V> setStatisticsEnabled(boolean enabled)
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
public MutableConfiguration<K,V> setManagementEnabled(boolean enabled)
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
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
-