public class PartitionedCacheAccess<K,V> extends AbstractPropertyContainer implements ICacheAccess<K,V>
This handles dividing puts and gets.
There are two required properties.
We use a JCS region name for each partition that looks like this: partitionRegionNamePrefix + "_" + partitionNumber. The number is 0 indexed based.
Constructor and Description |
---|
PartitionedCacheAccess()
Sets default properties heading and group.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the elements from a region.
|
void |
dispose()
Dispose this region.
|
protected boolean |
ensureInit()
Initialize if we haven't already.
|
int |
freeMemoryElements(int numberToFree)
Calls free on each partition.
|
V |
get(K key)
Gets the object for the key from the desired partition.
|
ICompositeCacheAttributes |
getCacheAttributes()
Gets the ICompositeCacheAttributes of the cache region
|
ICacheElement<K,V> |
getCacheElement(K key)
Gets the ICacheElement<K, V> (the wrapped object) for the key from the desired partition.
|
Map<K,ICacheElement<K,V>> |
getCacheElements(Set<K> names)
This is a getMultiple.
|
IElementAttributes |
getDefaultElementAttributes()
GetElementAttributes will return an attribute object describing the current attributes
associated with the object name.
|
IElementAttributes |
getElementAttributes(K key)
This is no more efficient than simply getting the cache element.
|
Map<K,V> |
getMatching(String pattern)
This is tricky.
|
Map<K,ICacheElement<K,V>> |
getMatchingCacheElements(String pattern)
This is tricky.
|
protected int |
getNumberOfPartitions() |
long |
getNumericValueForKey(K key)
This can be overridden for special purposes.
|
protected int |
getPartitionNumberForKey(K key)
This expects a numeric key.
|
protected String |
getPartitionRegionNamePrefix() |
protected ICacheAccess<K,V>[] |
getPartitions() |
protected String |
getPropertyForName(String propertyName,
boolean required)
Checks the system properties before the properties.
|
ICacheStats |
getStatistics()
This returns the ICacheStats object with information on this region and its auxiliaries.
|
String |
getStats() |
protected void |
handleProperties()
Loads in the needed configuration settings.
|
protected void |
initialize()
Use the partition prefix and the number of partitions to get JCS regions.
|
void |
put(K key,
V object)
Puts the value into the appropriate cache partition.
|
void |
put(K key,
V object,
IElementAttributes attr)
Puts the value into the appropriate cache partition.
|
void |
putSafe(K key,
V object)
Puts in cache if an item does not exist with the name in that region.
|
void |
remove(K key)
Removes the item from the appropriate partition.
|
void |
resetElementAttributes(K key,
IElementAttributes attributes)
Resets the attributes for this item.
|
void |
setCacheAttributes(ICompositeCacheAttributes cattr)
Sets the attributes on all the partitions.
|
void |
setDefaultElementAttributes(IElementAttributes attr)
This method is does not reset the attributes for items already in the cache.
|
protected void |
setNumberOfPartitions(int numberOfPartitions) |
protected void |
setPartitionRegionNamePrefix(String partitionRegionNamePrefix) |
protected void |
setPartitions(ICacheAccess<K,V>[] partitions) |
ensureProperties, getProperties, getPropertiesFactory, getPropertiesGroup, getPropertiesHeading, initializeProperties, setProperties, setPropertiesFactory, setPropertiesGroup, setPropertiesHeading
public PartitionedCacheAccess()
public void put(K key, V object) throws CacheException
put
in interface ICacheAccess<K,V>
key
- keyobject
- objectCacheException
- on configuration problempublic void putSafe(K key, V object) throws CacheException
putSafe
in interface ICacheAccess<K,V>
key
- object
- CacheException
public void put(K key, V object, IElementAttributes attr) throws CacheException
put
in interface ICacheAccess<K,V>
key
- keyobject
- objectattr
- CacheException
- on configuration problempublic V get(K key)
get
in interface ICacheAccess<K,V>
key
- keypublic ICacheElement<K,V> getCacheElement(K key)
getCacheElement
in interface ICacheAccess<K,V>
key
- keypublic Map<K,ICacheElement<K,V>> getCacheElements(Set<K> names)
getCacheElements
in interface ICacheAccess<K,V>
names
- public Map<K,V> getMatching(String pattern)
If this interface took an object, we could use the hashcode to determine the partition. Then we could use the toString for the pattern.
getMatching
in interface ICacheAccess<K,V>
pattern
- public Map<K,ICacheElement<K,V>> getMatchingCacheElements(String pattern)
getMatchingCacheElements
in interface ICacheAccess<K,V>
pattern
- public void remove(K key) throws CacheException
remove
in interface ICacheAccess<K,V>
key
- CacheException
public int freeMemoryElements(int numberToFree) throws CacheException
freeMemoryElements
in interface ICacheAccessManagement
numberToFree
- CacheException
public ICompositeCacheAttributes getCacheAttributes()
ICacheAccessManagement
getCacheAttributes
in interface ICacheAccessManagement
public IElementAttributes getDefaultElementAttributes() throws CacheException
ICacheAccessManagement
getDefaultElementAttributes
in interface ICacheAccessManagement
CacheException
public IElementAttributes getElementAttributes(K key) throws CacheException
getElementAttributes
in interface ICacheAccess<K,V>
key
- CacheException
public void resetElementAttributes(K key, IElementAttributes attributes) throws CacheException
resetElementAttributes
in interface ICacheAccess<K,V>
key
- attributes
- CacheException
public void setCacheAttributes(ICompositeCacheAttributes cattr)
setCacheAttributes
in interface ICacheAccessManagement
cattr
- public void clear() throws CacheException
clear
in interface ICacheAccessManagement
CacheException
public void setDefaultElementAttributes(IElementAttributes attr) throws CacheException
setDefaultElementAttributes
in interface ICacheAccessManagement
attr
- the default attributes.CacheException
- if something goes wrong.public ICacheStats getStatistics()
This data can be formatted as needed.
getStatistics
in interface ICacheAccessManagement
public String getStats()
getStats
in interface ICacheAccessManagement
public void dispose()
To simply remove all elements from the region use clear().
dispose
in interface ICacheAccessManagement
protected int getPartitionNumberForKey(K key)
We determine the partition by taking the mod of the number of partitions.
key
- keypublic long getNumericValueForKey(K key)
key
- keyprotected boolean ensureInit()
ConfigurationException
- on configuration problemprotected void initialize() throws ConfigurationException
ConfigurationException
- on configuration problemprotected void handleProperties() throws ConfigurationException
Loads the following JCS Cache specific properties:
handleProperties
in class AbstractPropertyContainer
ConfigurationException
- on configuration problemprotected String getPropertyForName(String propertyName, boolean required) throws ConfigurationException
propertyName
- namerequired
- is it required?ConfigurationException
- thrown if it is required and not found.protected void setNumberOfPartitions(int numberOfPartitions)
numberOfPartitions
- The numberOfPartitions to set.protected int getNumberOfPartitions()
protected void setPartitionRegionNamePrefix(String partitionRegionNamePrefix)
partitionRegionNamePrefix
- The partitionRegionNamePrefix to set.protected String getPartitionRegionNamePrefix()
protected void setPartitions(ICacheAccess<K,V>[] partitions)
partitions
- The partitions to set.protected ICacheAccess<K,V>[] getPartitions()
Copyright © 2002–2018 The Apache Software Foundation. All rights reserved.