org.hibernate.cache.jbc2
Class BasicRegionAdapter

java.lang.Object
  extended by org.hibernate.cache.jbc2.BasicRegionAdapter
All Implemented Interfaces:
Region
Direct Known Subclasses:
TransactionalDataRegionAdapter

public abstract class BasicRegionAdapter
extends Object
implements Region

General support for writing Region implementations for JBoss Cache 2.x.

Author:
Steve Ebersole

Field Summary
static String ITEM
           
protected  org.jboss.cache.Cache jbcCache
           
protected  org.slf4j.Logger log
           
protected  boolean optimistic
           
protected  org.jboss.cache.Fqn regionFqn
           
protected  String regionName
           
protected  org.jboss.cache.Node regionRoot
           
protected  Object regionRootMutex
           
protected  TransactionManager transactionManager
           
 
Constructor Summary
BasicRegionAdapter(org.jboss.cache.Cache jbcCache, String regionName, String regionPrefix)
           
 
Method Summary
protected  void activateLocalClusterNode()
           
protected abstract   createRegionFqn(String regionName, String regionPrefix)
           
protected  void deactivateLocalNode()
           
 void destroy()
          The "end state" contract of the region's lifecycle.
 void ensureRegionRootExists()
          Checks for the validity of the root cache node for this region, creating a new one if it does not exist or is invalid, and also ensuring that the root node is marked as resident.
static String escapeRegionName(String regionName, String regionPrefix)
           
 org.jboss.cache.Cache getCacheInstance()
           
 long getElementCountInMemory()
          The count of entries currently contained in the regions in-memory store.
 long getElementCountOnDisk()
          The count of entries currently contained in the regions disk store.
 String getName()
          Retrieve the name of this region.
protected  org.jboss.cache.config.Option getNonLockingDataVersionOption(boolean allowNullReturn)
          Get an Option with a data version of NonLockingDataVersion.
 org.jboss.cache.Fqn getRegionFqn()
           
 long getSizeInMemory()
          The number of bytes is this cache region currently consuming in memory.
 int getTimeout()
           
static  getTypeFirstRegionFqn(String regionName, String regionPrefix, String regionType)
           
static  getTypeLastRegionFqn(String regionName, String regionPrefix, String regionType)
           
 long nextTimestamp()
           
protected  void resume(Transaction tx)
          Tell the TransactionManager to resume the given transaction
protected  Transaction suspend()
          Tell the TransactionManager to suspend any ongoing transaction.
protected  Object suspendAndGet(Object key, org.jboss.cache.config.Option opt, boolean suppressTimeout)
          Performs a JBoss Cache get(Fqn, Object) after first suspending any ongoing transaction.
 Map toMap()
          Get the contents of this region as a map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ITEM

public static final String ITEM
See Also:
Constant Field Values

jbcCache

protected final org.jboss.cache.Cache jbcCache

regionName

protected final String regionName

regionFqn

protected final org.jboss.cache.Fqn regionFqn

regionRoot

protected org.jboss.cache.Node regionRoot

optimistic

protected final boolean optimistic

transactionManager

protected final TransactionManager transactionManager

log

protected final org.slf4j.Logger log

regionRootMutex

protected final Object regionRootMutex
Constructor Detail

BasicRegionAdapter

public BasicRegionAdapter(org.jboss.cache.Cache jbcCache,
                          String regionName,
                          String regionPrefix)
Method Detail

createRegionFqn

protected abstract  createRegionFqn(String regionName,
                                         String regionPrefix)

activateLocalClusterNode

protected void activateLocalClusterNode()

getName

public String getName()
Description copied from interface: Region
Retrieve the name of this region.

Specified by:
getName in interface Region
Returns:
The region name

getCacheInstance

public org.jboss.cache.Cache getCacheInstance()

getRegionFqn

public org.jboss.cache.Fqn getRegionFqn()

ensureRegionRootExists

public void ensureRegionRootExists()
Checks for the validity of the root cache node for this region, creating a new one if it does not exist or is invalid, and also ensuring that the root node is marked as resident. Suspends any transaction while doing this to ensure no transactional locks are held on the region root. TODO remove this once JBCACHE-1250 is resolved.


destroy

public void destroy()
             throws CacheException
Description copied from interface: Region
The "end state" contract of the region's lifecycle. Called during SessionFactory.close() to give the region a chance to cleanup.

Specified by:
destroy in interface Region
Throws:
CacheException - Indicates problem shutting down

deactivateLocalNode

protected void deactivateLocalNode()

getSizeInMemory

public long getSizeInMemory()
Description copied from interface: Region
The number of bytes is this cache region currently consuming in memory.

Specified by:
getSizeInMemory in interface Region
Returns:
The number of bytes consumed by this region; -1 if unknown or unsupported.

getElementCountInMemory

public long getElementCountInMemory()
Description copied from interface: Region
The count of entries currently contained in the regions in-memory store.

Specified by:
getElementCountInMemory in interface Region
Returns:
The count of entries in memory; -1 if unknown or unsupported.

getElementCountOnDisk

public long getElementCountOnDisk()
Description copied from interface: Region
The count of entries currently contained in the regions disk store.

Specified by:
getElementCountOnDisk in interface Region
Returns:
The count of entries on disk; -1 if unknown or unsupported.

toMap

public Map toMap()
Description copied from interface: Region
Get the contents of this region as a map.

Implementors which do not support this notion should simply return an empty map.

Specified by:
toMap in interface Region
Returns:
The content map.

nextTimestamp

public long nextTimestamp()
Specified by:
nextTimestamp in interface Region

getTimeout

public int getTimeout()
Specified by:
getTimeout in interface Region

suspendAndGet

protected Object suspendAndGet(Object key,
                               org.jboss.cache.config.Option opt,
                               boolean suppressTimeout)
                        throws CacheException
Performs a JBoss Cache get(Fqn, Object) after first suspending any ongoing transaction. Wraps any exception in a CacheException. Ensures any ongoing transaction is resumed.

Parameters:
key - The key of the item to get
opt - any option to add to the get invocation. May be null
suppressTimeout - should any TimeoutException be suppressed?
Returns:
The retrieved object
Throws:
CacheException - issue managing transaction or talking to cache

suspend

protected Transaction suspend()
Tell the TransactionManager to suspend any ongoing transaction.

Returns:
the transaction that was suspended, or null if there wasn't one

resume

protected void resume(Transaction tx)
Tell the TransactionManager to resume the given transaction

Parameters:
tx - the transaction to suspend. May be null.

getNonLockingDataVersionOption

protected org.jboss.cache.config.Option getNonLockingDataVersionOption(boolean allowNullReturn)
Get an Option with a data version of NonLockingDataVersion. The data version will not be set if the cache is not configured for optimistic locking.

Parameters:
allowNullReturn - If true, return null if the cache is not using optimistic locking. If false, return a default Option.
Returns:
the Option, or null.

getTypeFirstRegionFqn

public static  getTypeFirstRegionFqn(String regionName,
                                          String regionPrefix,
                                          String regionType)

getTypeLastRegionFqn

public static  getTypeLastRegionFqn(String regionName,
                                         String regionPrefix,
                                         String regionType)

escapeRegionName

public static String escapeRegionName(String regionName,
                                      String regionPrefix)


Copyright © 2009 Hibernate.org. All Rights Reserved.