FileDocCategorySizeDatePackage
TreeCacheProviderHook.javaAPI DocJBoss 4.2.15468Fri Jul 13 20:53:58 BST 2007org.jboss.ejb3.entity

TreeCacheProviderHook

public class TreeCacheProviderHook extends org.hibernate.cache.TreeCacheProvider implements org.hibernate.cache.CacheProvider
Support for integration as a 2nd level cache with an already existing JBoss Cache (TreeCache) instance. The ObjectName of the cache is provided via the hibernate.treecache.mbean.object_name configuration property.

This class supports both optimistic and pessimistic locking, providing instances of org.hibernate.cache.OptimisticCache if the underlying JBoss Cache is configured for optimistic locking.

author
Gavin King
author
Brian Stansberry

Fields Summary
public static final String
HIBERNATE_CACHE_OBJECT_NAME_PROPERTY
Name of the Hibernate configuration property used to provide the ObjectName of the JBoss Cache instance.
public static final String
DEFAULT_MBEAN_OBJECT_NAME
Default ObjectName for the JBoss Cache instance that will be used if {@link HIBERNATE_CACHE_OBJECT_NAME_PROPERTY} is not provided.
protected Logger
log
private org.jboss.cache.TreeCache
cache
private boolean
optimistic
Constructors Summary
Methods Summary
public org.hibernate.cache.CachebuildCache(java.lang.String regionName, java.util.Properties properties)
Construct and configure the Cache representation of a named cache region.

param
regionName the name of the cache region
param
properties configuration settings
return
The Cache representation of the named cache region. If the underlying JBoss Cache is configured for optimistic locking, the returned object will also implement org.hibernate.cache.OptimisticCache.
throws
org.hibernate.cache.CacheException Indicates an error building the cache region.

   
                                                                                           
          
   
      String regionPrefix = properties.getProperty("hibernate.cache.region_prefix");
      
      if (optimistic)
      {
         return new OptimisticJBCCache(cache, regionName, regionPrefix);
      }
      else
      {
         return new JBCCache(cache, regionName, regionPrefix, TxUtil.getTransactionManager());
      }
   
public org.jboss.cache.TreeCachegetUnderlyingCache()

      return cache;
   
public booleanisMinimalPutsEnabledByDefault()

      return true;
   
public booleanisOptimistic()

      return optimistic;
   
public longnextTimestamp()

      return System.currentTimeMillis() / 100;
   
public voidstart(java.util.Properties properties)
Find the underlying JBoss Cache TreeCache instance.

param
properties All current config settings. If {@link #HIBERNATE_CACHE_OBJECT_NAME_PROPERTY} is provided, the value will be the expected name of the cache; otherwise {@link #DEFAULT_MBEAN_OBJECT_NAME} will be used.
throws
org.hibernate.cache.CacheException Indicates a problem preparing cache for use.

      try
      {
         String cacheName = (String) properties.get(HIBERNATE_CACHE_OBJECT_NAME_PROPERTY);
         if (cacheName == null)
         {
            cacheName = DEFAULT_MBEAN_OBJECT_NAME;
         }
         ObjectName mbeanObjectName = new ObjectName(cacheName);
         TreeCacheMBean mbean = (TreeCacheMBean) MBeanProxyExt.create(TreeCacheMBean.class, mbeanObjectName, MBeanServerLocator.locateJBoss());
         cache = mbean.getInstance();
         if ("OPTIMISTIC".equals(cache.getNodeLockingScheme()))
         {
            optimistic = true;
            log.debug("JBoss Cache is configured for optimistic locking; " +
                    "provided Cache implementations will also implement OptimisticCache");
         }
      }
      catch (Exception e)
      {
         throw new CacheException(e);
      }
   
public voidstop()