org.infinispan.loaders.bucket
Class BucketBasedCacheStore

java.lang.Object
  extended by org.infinispan.loaders.AbstractCacheLoader
      extended by org.infinispan.loaders.AbstractCacheStore
          extended by org.infinispan.loaders.LockSupportCacheStore
              extended by org.infinispan.loaders.bucket.BucketBasedCacheStore
All Implemented Interfaces:
CacheLoader, CacheStore
Direct Known Subclasses:
CloudCacheStore, FileCacheStore, JdbcBinaryCacheStore

public abstract class BucketBasedCacheStore
extends LockSupportCacheStore

Base class for CacheStore implementations that combine entries into buckets when storing data.

A hashing algorithm is used to map keys to buckets, and a bucket consists of a collection of key/value pairs.

This approach, while adding an overhead of having to search through the contents of buckets a relevant entry, allows us to use any Serializable object as a key since the bucket is identified by a hash code. This hash code is often easy to represent in a physical store, such as a file system, database, etc.

Since:
4.0
Author:
Mircea.Markus@jboss.com, Manik Surtani

Field Summary
 
Fields inherited from class org.infinispan.loaders.AbstractCacheStore
cache, marshaller, multiThreadedPurge, purgerService
 
Constructor Summary
BucketBasedCacheStore()
           
 
Method Summary
protected  String getLockFromKey(Object key)
          For BucketBasedCacheStores the lock should be acquired at bucket level.
protected abstract  void insertBucket(Bucket bucket)
          Inserts a new Bucket in the storage system.
protected abstract  Bucket loadBucket(String hash)
          Loads a Bucket from the store, based on the hash code of the bucket.
protected  InternalCacheEntry loadLockSafe(Object key, String lockingKey)
          Loads an entry from a Bucket, locating the relevant Bucket using the key's hash code.
protected  boolean removeLockSafe(Object key, String lockingKey)
          Removes an entry from a Bucket, locating the relevant Bucket using the key's hash code.
protected  void storeLockSafe(InternalCacheEntry entry, String lockingKey)
          Stores an entry in an appropriate Bucket, based on the key's hash code.
protected abstract  void updateBucket(Bucket bucket)
          Updates a bucket in the store with the Bucket passed in to the method.
 
Methods inherited from class org.infinispan.loaders.LockSupportCacheStore
acquireGlobalLock, clear, clearLockSafe, fromStream, fromStreamLockSafe, getTotalLockCount, immediateLockForWriting, init, load, loadAll, loadAllLockSafe, lockForReading, lockForWriting, releaseGlobalLock, remove, start, store, toStream, toStreamLockSafe, unlock
 
Methods inherited from class org.infinispan.loaders.AbstractCacheStore
applyModifications, commit, getCacheStoreConfig, getConcurrencyLevel, getMarshaller, prepare, purgeExpired, purgeInternal, removeAll, rollback, safeClose, safeClose, stop, supportsMultiThreadedPurge
 
Methods inherited from class org.infinispan.loaders.AbstractCacheLoader
containsKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.infinispan.loaders.CacheLoader
containsKey, getConfigurationClass
 

Constructor Detail

BucketBasedCacheStore

public BucketBasedCacheStore()
Method Detail

loadLockSafe

protected InternalCacheEntry loadLockSafe(Object key,
                                          String lockingKey)
                                   throws CacheLoaderException
Loads an entry from a Bucket, locating the relevant Bucket using the key's hash code.

Specified by:
loadLockSafe in class LockSupportCacheStore
Parameters:
key - key of the entry to remove.
lockingKey - the hash of the key, as returned by LockSupportCacheStore.getLockFromKey(Object). This is required in order to avoid hash re-computation.
Throws:
CacheLoaderException

storeLockSafe

protected void storeLockSafe(InternalCacheEntry entry,
                             String lockingKey)
                      throws CacheLoaderException
Stores an entry in an appropriate Bucket, based on the key's hash code. If the Bucket does not exist in the underlying store, a new one is created.

Specified by:
storeLockSafe in class LockSupportCacheStore
Parameters:
entry - the entry to store
lockingKey - the hash of the key, as returned by LockSupportCacheStore.getLockFromKey(Object). This is required in order to avoid hash re-computation.
Throws:
CacheLoaderException

removeLockSafe

protected boolean removeLockSafe(Object key,
                                 String lockingKey)
                          throws CacheLoaderException
Removes an entry from a Bucket, locating the relevant Bucket using the key's hash code.

Specified by:
removeLockSafe in class LockSupportCacheStore
Parameters:
key - key of the entry to remove.
lockingKey - the hash of the key, as returned by LockSupportCacheStore.getLockFromKey(Object). This is required in order to avoid hash re-computation.
Throws:
CacheLoaderException

getLockFromKey

protected String getLockFromKey(Object key)
For BucketBasedCacheStores the lock should be acquired at bucket level. So we're locking based on the hash code of the key, as all keys having same hash code will be mapped to same bucket.

Specified by:
getLockFromKey in class LockSupportCacheStore

insertBucket

protected abstract void insertBucket(Bucket bucket)
                              throws CacheLoaderException
Inserts a new Bucket in the storage system. If the bucket already exists, this method should simply update the store with the contents of the bucket - i.e., behave the same as updateBucket(Bucket).

Parameters:
bucket - bucket to insert
Throws:
CacheLoaderException - in case of problems with the store.

updateBucket

protected abstract void updateBucket(Bucket bucket)
                              throws CacheLoaderException
Updates a bucket in the store with the Bucket passed in to the method. This method assumes that the bucket already exists in the store.

Parameters:
bucket - bucket to update.
Throws:
CacheLoaderException - in case of problems with the store.

loadBucket

protected abstract Bucket loadBucket(String hash)
                              throws CacheLoaderException
Loads a Bucket from the store, based on the hash code of the bucket.

Parameters:
hash - String representation of the Bucket's hash
Returns:
a Bucket if one exists, null otherwise.
Throws:
CacheLoaderException - in case of problems with the store.

Google Analytics

Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.