org.infinispan.loader.bucket
Class BucketBasedCacheStore

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

public abstract class BucketBasedCacheStore
extends LockSupportCacheStore

Base class for cache store that want to use the 'buckets approach' for 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 buckets for keys, means that we can use any serializable object we like as keys and not just Strings or objects that translate to something meaningful for a store(e.g. file system).

Since:
4.0
Author:
Mircea.Markus@jboss.com

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)
           
protected abstract  Bucket loadBucket(String keyHashCode)
          Loads the bucket from the store, base on the hashcode.
protected  InternalCacheEntry loadLockSafe(Object key, String lockingKey)
          Loads the bucket coresponding to the given key, and lookups the key within it.
protected  boolean removeLockSafe(Object key, String keyHashCodeStr)
          Lookups a bucket where the given key is stored.
protected abstract  void saveBucket(Bucket bucket)
          This method assumes that the bucket is already persisted in the database.
protected  void storeLockSafe(InternalCacheEntry ed, String lockingKey)
          Tries to find a bucket corresponding to storedEntry's key, and updates it with the storedEntry.
 
Methods inherited from class org.infinispan.loader.LockSupportCacheStore
acquireGlobalLock, clear, clearLockSafe, fromStream, fromStreamLockSafe, getTotalLockCount, immediateLockForWritting, init, load, loadAll, loadAllLockSafe, lockForReading, lockForWritting, releaseGlobalLock, remove, start, store, toStream, toStreamLockSafe, unlock
 
Methods inherited from class org.infinispan.loader.AbstractCacheStore
applyModifications, commit, getMarshaller, prepare, purgeExpired, purgeInternal, removeAll, rollback, safeClose, safeClose, stop
 
Methods inherited from class org.infinispan.loader.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.loader.CacheLoader
containsKey, getConfigurationClass
 

Constructor Detail

BucketBasedCacheStore

public BucketBasedCacheStore()
Method Detail

loadLockSafe

protected InternalCacheEntry loadLockSafe(Object key,
                                          String lockingKey)
                                   throws CacheLoaderException
Loads the bucket coresponding to the given key, and lookups the key within it. if the bucket is found and the key is expired, then it won't be returned.

Specified by:
loadLockSafe in class LockSupportCacheStore
Parameters:
key - the passed in key, from super#load(Object)
lockingKey - the hash of the key, as returned by super#getLockFromKey(Object). This is present here in order to avoid hash recomputation.
Throws:
CacheLoaderException

storeLockSafe

protected void storeLockSafe(InternalCacheEntry ed,
                             String lockingKey)
                      throws CacheLoaderException
Tries to find a bucket corresponding to storedEntry's key, and updates it with the storedEntry. If no bucket is found, a new one is created.

Specified by:
storeLockSafe in class LockSupportCacheStore
Parameters:
lockingKey - the hash of the key, as returned by super#getLockFromKey(Object). This is present here in order to avoid hash recomputation.
Throws:
CacheLoaderException

removeLockSafe

protected boolean removeLockSafe(Object key,
                                 String keyHashCodeStr)
                          throws CacheLoaderException
Lookups a bucket where the given key is stored. Then removes the StoredEntry having with gven key from there (if such a bucket exists).

Specified by:
removeLockSafe in class LockSupportCacheStore
Parameters:
lockingKey - the hash of the key, as returned by super#getLockFromKey(Object). This is present here in order to avoid hash recomputation.
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 hashCode of the key, as all keys having same hascode will be mapped to same bucket.

Specified by:
getLockFromKey in class LockSupportCacheStore

insertBucket

protected abstract void insertBucket(Bucket bucket)
                              throws CacheLoaderException
Throws:
CacheLoaderException

saveBucket

protected abstract void saveBucket(Bucket bucket)
                            throws CacheLoaderException
This method assumes that the bucket is already persisted in the database.

Throws:
CacheLoaderException - if the bucket is not already present, or something happens while persisting.

loadBucket

protected abstract Bucket loadBucket(String keyHashCode)
                              throws CacheLoaderException
Loads the bucket from the store, base on the hashcode.

Throws:
CacheLoaderException


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