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:
Serializable
,CompleteConfiguration<K,V>
,Configuration<K,V>
public class MutableConfiguration<K,V> extends Object implements CompleteConfiguration<K,V>
A simple mutable implementation of aConfiguration
.- Since:
- 1.0
- Author:
- Brian Oliver, Greg Luck
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Factory<CacheLoader<K,V>>
cacheLoaderFactory
TheFactory
for theCacheLoader
.protected Factory<CacheWriter<? super K,? super V>>
cacheWriterFactory
TheFactory
for theCacheWriter
.protected Factory<ExpiryPolicy>
expiryPolicyFactory
TheFactory
for theExpiryPolicy
.protected boolean
isManagementEnabled
Whether management is enabledprotected boolean
isReadThrough
A flag indicating if "read-through" mode is required.protected boolean
isStatisticsEnabled
A flag indicating if statistics gathering is enabled.protected boolean
isStoreByValue
A flag indicating if the cache will be store-by-value or store-by-reference.protected boolean
isWriteThrough
A flag indicating if "write-through" mode is required.protected Class<K>
keyType
The type of keys forCache
s configured with thisConfiguration
.protected HashSet<CacheEntryListenerConfiguration<K,V>>
listenerConfigurations
TheCacheEntryListenerConfiguration
s for theConfiguration
.static long
serialVersionUID
The serialVersionUID required forSerializable
.protected Class<V>
valueType
The type of values forCache
s configured with thisConfiguration
.
-
Constructor Summary
Constructors Constructor Description MutableConfiguration()
Default JavaBean constructor.MutableConfiguration(CompleteConfiguration<K,V> configuration)
Constructs aMutableConfiguration
based 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
.boolean
equals(Object object)
Iterable<CacheEntryListenerConfiguration<K,V>>
getCacheEntryListenerConfigurations()
Factory<CacheLoader<K,V>>
getCacheLoaderFactory()
Gets theFactory
for theCacheLoader
, if any.Factory<CacheWriter<? super K,? super V>>
getCacheWriterFactory()
Gets theFactory
for theCacheWriter
, if any.Factory<ExpiryPolicy>
getExpiryPolicyFactory()
Gets theFactory
for theExpiryPolicy
to be used for caches.Class<K>
getKeyType()
Determines the required type of keys forCache
s configured with thisConfiguration
.Class<V>
getValueType()
Determines the required type of values forCache
s configured with thisConfiguration
.int
hashCode()
boolean
isManagementEnabled()
Checks whether management is enabled on this cache.boolean
isReadThrough()
Determines if aCache
should operate in read-through mode.boolean
isStatisticsEnabled()
Checks whether statistics collection is enabled in this cache.boolean
isStoreByValue()
Whether storeByValue (true) or storeByReference (false).boolean
isWriteThrough()
Determines if aCache
should 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 theCacheLoader
factory.MutableConfiguration<K,V>
setCacheWriterFactory(Factory<? extends CacheWriter<? super K,? super V>> factory)
Set theCacheWriter
factory.MutableConfiguration<K,V>
setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory)
Set theFactory
for 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(Class<K> keyType, Class<V> valueType)
Sets the expected type of keys and values for aCache
configured 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 Class<K> keyType
The type of keys forCache
s configured with thisConfiguration
.
-
valueType
protected Class<V> valueType
The type of values forCache
s configured with thisConfiguration
.
-
listenerConfigurations
protected HashSet<CacheEntryListenerConfiguration<K,V>> listenerConfigurations
TheCacheEntryListenerConfiguration
s for theConfiguration
.
-
cacheLoaderFactory
protected Factory<CacheLoader<K,V>> cacheLoaderFactory
TheFactory
for theCacheLoader
.
-
cacheWriterFactory
protected Factory<CacheWriter<? super K,? super V>> cacheWriterFactory
TheFactory
for theCacheWriter
.
-
expiryPolicyFactory
protected Factory<ExpiryPolicy> expiryPolicyFactory
TheFactory
for 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 aMutableConfiguration
based on anotherCompleteConfiguration
.- Parameters:
configuration
- theCompleteConfiguration
-
-
Method Detail
-
getKeyType
public Class<K> getKeyType()
Determines the required type of keys forCache
s configured with thisConfiguration
.- Specified by:
getKeyType
in interfaceConfiguration<K,V>
- Returns:
- the key type or
Object.class
if the type is undefined
-
getValueType
public Class<V> getValueType()
Determines the required type of values forCache
s configured with thisConfiguration
.- Specified by:
getValueType
in interfaceConfiguration<K,V>
- Returns:
- the value type or
Object.class
if the type is undefined
-
setTypes
public MutableConfiguration<K,V> setTypes(Class<K> keyType, Class<V> valueType)
Sets the expected type of keys and values for aCache
configured with thisConfiguration
. Setting both toObject.class
means type-safety checks are not required.This is used by
CacheManager
to ensure that the key and value types are the same as those configured for theCache
prior to returning a requested cache from this method.Implementations may further perform type checking on mutative cache operations and throw a
ClassCastException
if these checks fail.- Parameters:
keyType
- the expected key typevalueType
- the expected value type- Returns:
- the
MutableConfiguration
to permit fluent-style method calls - Throws:
NullPointerException
- should the key or value type be null- See Also:
CacheManager.getCache(String, Class, Class)
-
getCacheEntryListenerConfigurations
public Iterable<CacheEntryListenerConfiguration<K,V>> getCacheEntryListenerConfigurations()
- Specified by:
getCacheEntryListenerConfigurations
in interfaceCompleteConfiguration<K,V>
- Returns:
- an
Iterable
over theCacheEntryListenerConfiguration
s
-
addCacheEntryListenerConfiguration
public MutableConfiguration<K,V> addCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
Add a configuration for aCacheEntryListener
.- Parameters:
cacheEntryListenerConfiguration
- theCacheEntryListenerConfiguration
- Returns:
- the
MutableConfiguration
to 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
- theCacheEntryListenerConfiguration
to remove- Returns:
- the
MutableConfiguration
to permit fluent-style method calls
-
getCacheLoaderFactory
public Factory<CacheLoader<K,V>> getCacheLoaderFactory()
Gets theFactory
for 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:
getCacheLoaderFactory
in interfaceCompleteConfiguration<K,V>
- Returns:
- the
Factory
for theCacheLoader
or null if none has been set.
-
setCacheLoaderFactory
public MutableConfiguration<K,V> setCacheLoaderFactory(Factory<? extends CacheLoader<K,V>> factory)
Set theCacheLoader
factory.- Parameters:
factory
- theCacheLoader
Factory
- Returns:
- the
MutableConfiguration
to permit fluent-style method calls
-
getCacheWriterFactory
public Factory<CacheWriter<? super K,? super V>> getCacheWriterFactory()
- Specified by:
getCacheWriterFactory
in interfaceCompleteConfiguration<K,V>
- Returns:
- the
Factory
for theCacheWriter
or null if none has been set.
-
setCacheWriterFactory
public MutableConfiguration<K,V> setCacheWriterFactory(Factory<? extends CacheWriter<? super K,? super V>> factory)
Set theCacheWriter
factory.- Parameters:
factory
- theCacheWriter
Factory
- Returns:
- the
MutableConfiguration
to permit fluent-style method calls
-
getExpiryPolicyFactory
public Factory<ExpiryPolicy> getExpiryPolicyFactory()
Gets theFactory
for theExpiryPolicy
to be used for caches.The default value is a
Factory
that will produce aEternalExpiryPolicy
instance.- Specified by:
getExpiryPolicyFactory
in interfaceCompleteConfiguration<K,V>
- Returns:
- the
Factory
forExpiryPolicy
(must not benull
)
-
setExpiryPolicyFactory
public MutableConfiguration<K,V> setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory)
Set theFactory
for theExpiryPolicy
. Ifnull
is specified the defaultExpiryPolicy
is 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
- theExpiryPolicy
Factory
- Returns:
- the
MutableConfiguration
to permit fluent-style method calls
-
isReadThrough
public boolean isReadThrough()
Determines if aCache
should 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
CacheLoader
to be invoked.The default value is
false
.- Specified by:
isReadThrough
in interfaceCompleteConfiguration<K,V>
- Returns:
true
when aCache
is 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
CacheLoader
Factory
.- Parameters:
isReadThrough
-true
if read-through is required- Returns:
- the
MutableConfiguration
to permit fluent-style method calls
-
isWriteThrough
public boolean isWriteThrough()
Determines if aCache
should 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 configuredCacheWriter
to be invoked.The default value is
false
.- Specified by:
isWriteThrough
in interfaceCompleteConfiguration<K,V>
- Returns:
true
when aCache
is 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
CacheWriter
Factory
.- Parameters:
isWriteThrough
-true
if write-through is required- Returns:
- the
MutableConfiguration
to 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:
isStoreByValue
in 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
-true
if store-by-value is required,false
for store-by-reference- Returns:
- the
MutableConfiguration
to 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:
isStatisticsEnabled
in 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
MutableConfiguration
to permit fluent-style method calls
-
isManagementEnabled
public boolean isManagementEnabled()
Checks whether management is enabled on this cache.The default value is
false
.- Specified by:
isManagementEnabled
in 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
MutableConfiguration
to permit fluent-style method calls
-
-