FileDocCategorySizeDatePackage
OptimisticTreeCacheProvider.javaAPI DocHibernate 3.2.54269Fri May 05 14:27:18 BST 2006org.hibernate.cache

OptimisticTreeCacheProvider

public class OptimisticTreeCacheProvider extends Object implements CacheProvider
Support for a standalone JBossCache TreeCache instance utilizing TreeCache's optimistic locking capabilities. This capability was added in JBossCache version 1.3.0; as such this provider will only work with that version or higher.

The TreeCache instance is configured via a local config resource. The resource to be used for configuration can be controlled by specifying a value for the {@link #CONFIG_RESOURCE} config property.

author
Steve Ebersole

Fields Summary
public static final String
CONFIG_RESOURCE
public static final String
DEFAULT_CONFIG
private static final String
NODE_LOCKING_SCHEME
private static final Log
log
private org.jboss.cache.TreeCache
cache
Constructors Summary
Methods Summary
public 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.
throws
CacheException Indicates an error building the cache region.


	                                                  	 
	        
		return new OptimisticTreeCache( cache, regionName );
	
public org.jboss.cache.TreeCachegetUnderlyingCache()

		return cache;
	
public booleanisMinimalPutsEnabledByDefault()

		return true;
	
public longnextTimestamp()

		return System.currentTimeMillis() / 100;
	
public voidstart(java.util.Properties properties)
Prepare the underlying JBossCache TreeCache instance.

param
properties All current config settings.
throws
CacheException Indicates a problem preparing cache for use.

		String resource = properties.getProperty( Environment.CACHE_PROVIDER_CONFIG );
		if (resource == null) {
			resource = properties.getProperty( CONFIG_RESOURCE );
		}
		if ( resource == null ) {
			resource = DEFAULT_CONFIG;
		}
		log.debug( "Configuring TreeCache from resource [" + resource + "]" );
		try {
			cache = new org.jboss.cache.TreeCache();
			PropertyConfigurator config = new PropertyConfigurator();
			config.configure( cache, resource );
			TransactionManagerLookup transactionManagerLookup =
					TransactionManagerLookupFactory.getTransactionManagerLookup( properties );
			if ( transactionManagerLookup == null ) {
				throw new CacheException(
						"JBossCache only supports optimisitc locking with a configured " +
						"TransactionManagerLookup (" + Environment.TRANSACTION_MANAGER_STRATEGY + ")"
				);
			}
			cache.setTransactionManagerLookup(
					new TransactionManagerLookupAdaptor(
							transactionManagerLookup,
							properties
					)
			);
			if ( ! NODE_LOCKING_SCHEME.equalsIgnoreCase( cache.getNodeLockingScheme() ) ) {
				log.info( "Overriding node-locking-scheme to : " + NODE_LOCKING_SCHEME );
				cache.setNodeLockingScheme( NODE_LOCKING_SCHEME );
			}
			cache.start();
		}
		catch ( Exception e ) {
			throw new CacheException( e );
		}
	
public voidstop()

		if ( cache != null ) {
			cache.stop();
			cache.destroy();
			cache = null;
		}