org.hibernate.cache.jbc
Class BasicRegionAdapter

java.lang.Object
  extended by org.hibernate.cache.jbc.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.jbc.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)
          Determine whether this region contains data for the given key.
protected abstract  org.jboss.cache.Fqn<String> 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.
 Object getMemberId()
           
 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 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()
          Get the contents of this region as a map.
 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.jbc.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()
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()

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
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()

contains

public boolean contains(Object key)
Description copied from interface: Region
Determine whether this region contains data for the given key.

The semantic here is whether the cache contains data visible for the current call context. This should be viewed as a "best effort", meaning blocking should be avoid if possible.

Specified by:
contains in interface Region
Parameters:
key - The cache key
Returns:
True if the underlying cache contains corresponding data; false otherwise.

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

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 © 2001-2010 Red Hat, Inc. All Rights Reserved.