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
protected  Set<Object> currentView
           
protected  org.jboss.cache.Fqn internalFqn
           
protected  AtomicReference<org.hibernate.cache.jbc2.BasicRegionAdapter.InvalidateState> invalidateState
           
protected  Object invalidationMutex
           
static String ITEM
           
protected  org.jboss.cache.Cache jbcCache
           
protected  org.slf4j.Logger log
           
protected  Object memberId
           
protected  boolean optimistic
           
protected  org.jboss.cache.Fqn regionFqn
           
protected  String regionName
           
protected  org.jboss.cache.Node regionRoot
           
protected  Object regionRootMutex
           
protected  boolean replication
           
protected  TransactionManager transactionManager
           
 
Constructor Summary
BasicRegionAdapter(org.jboss.cache.Cache jbcCache, String regionName, String regionPrefix)
           
 
Method Summary
protected  void activateLocalClusterNode()
           
 boolean checkValid()
           
 boolean contains(Object key)
           
protected abstract  org.jboss.cache.Fqn<String> createRegionFqn(String regionName, String regionPrefix)
           
protected  void deactivateLocalNode()
           
 void destroy()
           
 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()
           
 long getElementCountOnDisk()
           
 Object getMemberId()
           
 String getName()
           
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()
           
 int getTimeout()
           
static org.jboss.cache.Fqn<String> getTypeFirstRegionFqn(String regionName, String regionPrefix, String regionType)
           
static org.jboss.cache.Fqn<String> getTypeLastRegionFqn(String regionName, String regionPrefix, String regionType)
           
protected  boolean handleEvictAllInvalidation(org.jboss.cache.notifications.event.NodeInvalidatedEvent event)
           
protected  boolean handleEvictAllModification(org.jboss.cache.notifications.event.NodeModifiedEvent event)
           
 long nextTimestamp()
           
 void nodeInvalidated(org.jboss.cache.notifications.event.NodeInvalidatedEvent event)
           
 void nodeModified(org.jboss.cache.notifications.event.NodeModifiedEvent event)
           
 void resume(Transaction tx)
          Tell the TransactionManager to resume the given transaction
 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()
           
 void viewChanged(org.jboss.cache.notifications.event.ViewChangedEvent event)
           
 
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

internalFqn

protected final org.jboss.cache.Fqn internalFqn

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

memberId

protected final Object memberId

replication

protected final boolean replication

invalidationMutex

protected final Object invalidationMutex

invalidateState

protected final AtomicReference<org.hibernate.cache.jbc2.BasicRegionAdapter.InvalidateState> invalidateState

currentView

protected final Set<Object> currentView
Constructor Detail

BasicRegionAdapter

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

createRegionFqn

protected abstract org.jboss.cache.Fqn<String> createRegionFqn(String regionName,
                                                               String regionPrefix)

activateLocalClusterNode

protected void activateLocalClusterNode()

getName

public String getName()
Specified by:
getName in interface Region

getCacheInstance

public org.jboss.cache.Cache getCacheInstance()

getRegionFqn

public org.jboss.cache.Fqn getRegionFqn()

getMemberId

public Object getMemberId()

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.


checkValid

public boolean checkValid()

destroy

public void destroy()
             throws CacheException
Specified by:
destroy in interface Region
Throws:
CacheException

deactivateLocalNode

protected void deactivateLocalNode()

contains

public boolean contains(Object key)

getSizeInMemory

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

getElementCountInMemory

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

getElementCountOnDisk

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

toMap

public Map toMap()
Specified by:
toMap in interface Region

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

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

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

resume

public 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 org.jboss.cache.Fqn<String> getTypeFirstRegionFqn(String regionName,
                                                                String regionPrefix,
                                                                String regionType)

getTypeLastRegionFqn

public static org.jboss.cache.Fqn<String> getTypeLastRegionFqn(String regionName,
                                                               String regionPrefix,
                                                               String regionType)

escapeRegionName

public static String escapeRegionName(String regionName,
                                      String regionPrefix)

nodeModified

public void nodeModified(org.jboss.cache.notifications.event.NodeModifiedEvent event)

handleEvictAllModification

protected boolean handleEvictAllModification(org.jboss.cache.notifications.event.NodeModifiedEvent event)

nodeInvalidated

public void nodeInvalidated(org.jboss.cache.notifications.event.NodeInvalidatedEvent event)

handleEvictAllInvalidation

protected boolean handleEvictAllInvalidation(org.jboss.cache.notifications.event.NodeInvalidatedEvent event)

viewChanged

public void viewChanged(org.jboss.cache.notifications.event.ViewChangedEvent event)


Copyright © 2011 Hibernate.org. All Rights Reserved.