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>> TheFactory
for theCacheLoader
.protected Factory
<CacheWriter<? super K, ? super V>> TheFactory
for theCacheWriter
.protected Factory
<ExpiryPolicy> TheFactory
for theExpiryPolicy
.protected boolean
Whether management is enabledprotected boolean
A flag indicating if "read-through" mode is required.protected boolean
A flag indicating if statistics gathering is enabled.protected boolean
A flag indicating if the cache will be store-by-value or store-by-reference.protected boolean
A flag indicating if "write-through" mode is required.The type of keys forCache
s configured with thisConfiguration
.protected HashSet
<CacheEntryListenerConfiguration<K, V>> TheCacheEntryListenerConfiguration
s for theConfiguration
.static final long
The serialVersionUID required forSerializable
.The type of values forCache
s configured with thisConfiguration
. -
Constructor Summary
ConstructorsConstructorDescriptionDefault JavaBean constructor.MutableConfiguration
(CompleteConfiguration<K, V> configuration) Constructs aMutableConfiguration
based on anotherCompleteConfiguration
. -
Method Summary
Modifier and TypeMethodDescriptionaddCacheEntryListenerConfiguration
(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Add a configuration for aCacheEntryListener
.boolean
Factory
<CacheLoader<K, V>> Gets theFactory
for theCacheLoader
, if any.Factory
<CacheWriter<? super K, ? super V>> Gets theFactory
for theCacheWriter
, if any.Gets theFactory
for theExpiryPolicy
to be used for caches.Determines the required type of keys forCache
s configured with thisConfiguration
.Determines the required type of values forCache
s configured with thisConfiguration
.int
hashCode()
boolean
Checks whether management is enabled on this cache.boolean
Determines if aCache
should operate in read-through mode.boolean
Checks whether statistics collection is enabled in this cache.boolean
Whether storeByValue (true) or storeByReference (false).boolean
Determines if aCache
should operate in write-through mode.removeCacheEntryListenerConfiguration
(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Remove a configuration for aCacheEntryListener
.setCacheLoaderFactory
(Factory<? extends CacheLoader<K, V>> factory) Set theCacheLoader
factory.setCacheWriterFactory
(Factory<? extends CacheWriter<? super K, ? super V>> factory) Set theCacheWriter
factory.setExpiryPolicyFactory
(Factory<? extends ExpiryPolicy> factory) Set theFactory
for 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 aCache
configured with thisConfiguration
.setWriteThrough
(boolean isWriteThrough) Set if write-through caching should be used.
-
Field Details
-
serialVersionUID
public static final long serialVersionUIDThe serialVersionUID required forSerializable
.- See Also:
-
keyType
The type of keys forCache
s configured with thisConfiguration
. -
valueType
The type of values forCache
s configured with thisConfiguration
. -
listenerConfigurations
TheCacheEntryListenerConfiguration
s for theConfiguration
. -
cacheLoaderFactory
TheFactory
for theCacheLoader
. -
cacheWriterFactory
TheFactory
for theCacheWriter
. -
expiryPolicyFactory
TheFactory
for 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(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:
-
MutableConfiguration
Constructs aMutableConfiguration
based on anotherCompleteConfiguration
.- Parameters:
configuration
- theCompleteConfiguration
-
-
Method Details
-
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
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
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:
-
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
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
Set theCacheLoader
factory.- Parameters:
factory
- theCacheLoader
Factory
- Returns:
- the
MutableConfiguration
to permit fluent-style method calls
-
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
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
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:
-
setReadThrough
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:
-
setWriteThrough
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
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
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
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
-
hashCode
public int hashCode() -
equals
-