Class PartitionedDataCache

All Implemented Interfaces:
Serializable, DataCache, RemoteCommitListener, Configurable, Clearable, Closeable, EventManager

public class PartitionedDataCache extends ConcurrentDataCache
A partitioned data cache maintains a set of partitions that are DataCache themselves. Each of the partitioned DataCaches can be individually configured. However, all partitions must be of the same type. By default, this cache uses ConcurrentDataCache as its partitions.
This cache can be configured as a plug-in as follows:
<property name='openjpa.DataCache" value="partitioned(name=X, PartitionType=concurrent,Partitions='(name=a,cacheSize=100), (name=b,cacheSize=200)')
Notice that the individual partition properties are enclosed parentheses, separated by comma and finally the whole property string is enclosed in single quote. Each partition must have a non-empty name that are unique among the partitions. The policy can return the name of a partition to distribute the managed instances to be cached in respective partition. The above configuration will configure a partitioned cache named X with two partitions named a and b with cache size 100 and 200 respectively. Besides the two partitions, this cache instance itself can store data and referred by its own name (X in the above example).
Since:
2.0.0
Author:
Pinaki Poddar
See Also:
  • Constructor Details

    • PartitionedDataCache

      public PartitionedDataCache()
  • Method Details

    • initialize

      public void initialize(DataCacheManager mgr)
      Description copied from interface: DataCache
      Initialize any resources associated with the given DataCacheManager.
      Specified by:
      initialize in interface DataCache
      Overrides:
      initialize in class ConcurrentDataCache
    • setPartitionType

      public void setPartitionType(String type) throws Exception
      Sets the type of the partitions. Each partition is a DataCache itself.
      Parameters:
      type - the name of the type that implements DataCache interface. Aliases such as "concurrent" is also recognized.
      Throws:
      Exception - if the given type is not resolvable to a loadable type.
    • setPartitions

      public void setPartitions(String parts)
      Set partitions from a String configuration.
      Parameters:
      parts - a String of the form (p1, p2, p3) where p1, p2 etc. itself are plug-in strings for individual Data Cache configuration.
    • getPartitions

      public List<String> getPartitions()
      Returns the individual partition configuration properties.
    • getPartition

      public DataCache getPartition(String name, boolean create)
      Description copied from interface: DataCache
      Gets the named partition. Note that a partition itself is another cache.
      Specified by:
      getPartition in interface DataCache
      Overrides:
      getPartition in class AbstractDataCache
      Parameters:
      name - name of the given partition.
      create - if true optionally create a new partition.
      Returns:
      a partition of the given name. Or null, if either no such partition exists or can not be created.
    • getPartitionNames

      public Set<String> getPartitionNames()
      Gets the name of the configured partitions.
      Specified by:
      getPartitionNames in interface DataCache
      Overrides:
      getPartitionNames in class AbstractDataCache
      Returns:
      empty set if no partition exists.
    • isPartitioned

      public final boolean isPartitioned()
      Always returns true.
      Specified by:
      isPartitioned in interface DataCache
      Overrides:
      isPartitioned in class AbstractDataCache
    • endConfiguration

      public void endConfiguration()
      Description copied from interface: Configurable
      Invoked upon completion of bean property configuration for this object.
      Specified by:
      endConfiguration in interface Configurable
      Overrides:
      endConfiguration in class AbstractDataCache