K
- the type of keys maintained the cacheV
- the type of cached valuesSerializable
, CompleteConfiguration<K,V>
, Configuration<K,V>
public class MutableConfiguration<K,V> extends Object implements CompleteConfiguration<K,V>
Configuration
.Modifier and Type | Field | Description |
---|---|---|
protected Factory<CacheLoader<K,V>> |
cacheLoaderFactory |
The
Factory for the CacheLoader . |
protected Factory<CacheWriter<? super K,? super V>> |
cacheWriterFactory |
The
Factory for the CacheWriter . |
protected Factory<ExpiryPolicy> |
expiryPolicyFactory |
The
Factory for the ExpiryPolicy . |
protected boolean |
isManagementEnabled |
Whether management is enabled
|
protected 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 for
Cache s configured with this
Configuration . |
protected HashSet<CacheEntryListenerConfiguration<K,V>> |
listenerConfigurations |
The
CacheEntryListenerConfiguration s for the Configuration . |
static long |
serialVersionUID |
The serialVersionUID required for
Serializable . |
protected Class<V> |
valueType |
The type of values for
Cache s configured with this
Configuration . |
Constructor | Description |
---|---|
MutableConfiguration() |
Default JavaBean constructor.
|
MutableConfiguration(CompleteConfiguration<K,V> configuration) |
Constructs a
MutableConfiguration based on another
CompleteConfiguration . |
Modifier and Type | Method | Description |
---|---|---|
MutableConfiguration<K,V> |
addCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration) |
Add a configuration for a
CacheEntryListener . |
boolean |
equals(Object object) |
|
Iterable<CacheEntryListenerConfiguration<K,V>> |
getCacheEntryListenerConfigurations() |
|
Factory<CacheLoader<K,V>> |
getCacheLoaderFactory() |
Gets the
Factory for the
CacheLoader , if any. |
Factory<CacheWriter<? super K,? super V>> |
getCacheWriterFactory() |
Gets the
Factory for the
CacheWriter , if any. |
Factory<ExpiryPolicy> |
getExpiryPolicyFactory() |
Gets the
Factory for the
ExpiryPolicy to be used for caches. |
Class<K> |
getKeyType() |
Determines the required type of keys for
Cache s configured
with this Configuration . |
Class<V> |
getValueType() |
Determines the required type of values for
Cache s configured
with this Configuration . |
int |
hashCode() |
|
boolean |
isManagementEnabled() |
Checks whether management is enabled on this cache.
|
boolean |
isReadThrough() |
Determines if a
Cache 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 a
Cache should operate in write-through
mode. |
MutableConfiguration<K,V> |
removeCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration) |
Remove a configuration for a
CacheEntryListener . |
MutableConfiguration<K,V> |
setCacheLoaderFactory(Factory<? extends CacheLoader<K,V>> factory) |
Set the
CacheLoader factory. |
MutableConfiguration<K,V> |
setCacheWriterFactory(Factory<? extends CacheWriter<? super K,? super V>> factory) |
Set the
CacheWriter factory. |
MutableConfiguration<K,V> |
setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory) |
Set the
Factory for the ExpiryPolicy . |
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 a
Cache
configured with this Configuration . |
MutableConfiguration<K,V> |
setWriteThrough(boolean isWriteThrough) |
Set if write-through caching should be used.
|
public static final long serialVersionUID
Serializable
.protected Class<K> keyType
Cache
s configured with this
Configuration
.protected Class<V> valueType
Cache
s configured with this
Configuration
.protected HashSet<CacheEntryListenerConfiguration<K,V>> listenerConfigurations
CacheEntryListenerConfiguration
s for the Configuration
.protected Factory<CacheLoader<K,V>> cacheLoaderFactory
Factory
for the CacheLoader
.protected Factory<CacheWriter<? super K,? super V>> cacheWriterFactory
Factory
for the CacheWriter
.protected Factory<ExpiryPolicy> expiryPolicyFactory
Factory
for the ExpiryPolicy
.protected boolean isReadThrough
protected boolean isWriteThrough
protected boolean isStatisticsEnabled
protected boolean isStoreByValue
protected boolean isManagementEnabled
public MutableConfiguration()
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)
. . .
setTypes(Class, Class)
public MutableConfiguration(CompleteConfiguration<K,V> configuration)
MutableConfiguration
based on another
CompleteConfiguration
.configuration
- the CompleteConfiguration
public Class<K> getKeyType()
Cache
s configured
with this Configuration
.getKeyType
in interface Configuration<K,V>
Object.class
if the type is undefinedpublic Class<V> getValueType()
Cache
s configured
with this Configuration
.getValueType
in interface Configuration<K,V>
Object.class
if the type is undefinedpublic MutableConfiguration<K,V> setTypes(Class<K> keyType, Class<V> valueType)
Cache
configured with this Configuration
. Setting both to
Object.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 the Cache
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.
keyType
- the expected key typevalueType
- the expected value typeMutableConfiguration
to permit fluent-style method callsNullPointerException
- should the key or value type be nullCacheManager.getCache(String, Class, Class)
public Iterable<CacheEntryListenerConfiguration<K,V>> getCacheEntryListenerConfigurations()
getCacheEntryListenerConfigurations
in interface CompleteConfiguration<K,V>
Iterable
over the
CacheEntryListenerConfiguration
spublic MutableConfiguration<K,V> addCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
CacheEntryListener
.cacheEntryListenerConfiguration
- the
CacheEntryListenerConfiguration
MutableConfiguration
to permit fluent-style method callsIllegalArgumentException
- is the same CacheEntryListenerConfiguration
is used more than oncepublic MutableConfiguration<K,V> removeCacheEntryListenerConfiguration(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
CacheEntryListener
.cacheEntryListenerConfiguration
- the
CacheEntryListenerConfiguration
to removeMutableConfiguration
to permit fluent-style method callspublic Factory<CacheLoader<K,V>> getCacheLoaderFactory()
Factory
for the
CacheLoader
, 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/or
Cache.getAll(java.util.Set)
methods.
The default value is null
.
getCacheLoaderFactory
in interface CompleteConfiguration<K,V>
Factory
for the
CacheLoader
or null if none has been set.public MutableConfiguration<K,V> setCacheLoaderFactory(Factory<? extends CacheLoader<K,V>> factory)
CacheLoader
factory.factory
- the CacheLoader
Factory
MutableConfiguration
to permit fluent-style method callspublic Factory<CacheWriter<? super K,? super V>> getCacheWriterFactory()
getCacheWriterFactory
in interface CompleteConfiguration<K,V>
Factory
for the
CacheWriter
or null if none has been set.public MutableConfiguration<K,V> setCacheWriterFactory(Factory<? extends CacheWriter<? super K,? super V>> factory)
CacheWriter
factory.factory
- the CacheWriter
Factory
MutableConfiguration
to permit fluent-style method callspublic Factory<ExpiryPolicy> getExpiryPolicyFactory()
Factory
for the
ExpiryPolicy
to be used for caches.
The default value is a Factory
that will
produce a EternalExpiryPolicy
instance.
getExpiryPolicyFactory
in interface CompleteConfiguration<K,V>
Factory
for
ExpiryPolicy
(must not be null
)public MutableConfiguration<K,V> setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory)
Factory
for the ExpiryPolicy
. If null
is specified the default ExpiryPolicy
is used.
Only one expiry policy can be set for a cache. The last policy applied before cache construction will be the one used.
factory
- the ExpiryPolicy
Factory
MutableConfiguration
to permit fluent-style method callspublic boolean isReadThrough()
Cache
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
.
isReadThrough
in interface CompleteConfiguration<K,V>
true
when a Cache
is in
"read-through" mode.CompleteConfiguration.getCacheLoaderFactory()
public MutableConfiguration<K,V> setReadThrough(boolean isReadThrough)
It is an invalid configuration to set this to true without specifying a
CacheLoader
Factory
.
isReadThrough
- true
if read-through is requiredMutableConfiguration
to permit fluent-style method callspublic boolean isWriteThrough()
Cache
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 configured CacheWriter
to be invoked.
The default value is false
.
isWriteThrough
in interface CompleteConfiguration<K,V>
true
when a Cache
is in
"write-through" mode.CompleteConfiguration.getCacheWriterFactory()
public MutableConfiguration<K,V> setWriteThrough(boolean isWriteThrough)
It is an invalid configuration to set this to true without specifying a
CacheWriter
Factory
.
isWriteThrough
- true
if write-through is requiredMutableConfiguration
to permit fluent-style method callspublic boolean isStoreByValue()
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:
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
.
isStoreByValue
in interface Configuration<K,V>
public MutableConfiguration<K,V> setStoreByValue(boolean isStoreByValue)
isStoreByValue
- true
if store-by-value is required,
false
for store-by-referenceMutableConfiguration
to permit fluent-style method callspublic boolean isStatisticsEnabled()
The default value is false
.
isStatisticsEnabled
in interface CompleteConfiguration<K,V>
public MutableConfiguration<K,V> setStatisticsEnabled(boolean enabled)
Statistics may be enabled or disabled at runtime via
CacheManager.enableStatistics(String, boolean)
.
enabled
- true to enable statistics, false to disable.MutableConfiguration
to permit fluent-style method callspublic boolean isManagementEnabled()
The default value is false
.
isManagementEnabled
in interface CompleteConfiguration<K,V>
public MutableConfiguration<K,V> setManagementEnabled(boolean enabled)
Management may be enabled or disabled at runtime via
CacheManager.enableManagement(String, boolean)
.
enabled
- true to enable statistics, false to disable.MutableConfiguration
to permit fluent-style method callsCopyright © 2017. All rights reserved.