Steve Can I make a suggestion.
Change the existing net.sf.cache.TreeCache constructor to the following.
Code:
public TreeCache(String regionName, org.jboss.cache.TreeCache cache)
throws CacheException {
this.cache = cache;
this.regionName = '/' + regionName.replace('.', '/');
}
Then in the CacheProvider implementation perform all the resolution of the jboss TreeCache object, either by JNDI, or by constructing it manually.
This decouples the construction of the jboss TreeCache keeping it in the factory, leaving the net.sf.hibernate.cache.Cache implementation to just invoke the methods in the cache. eg
Code:
public class TreeCacheProvider implements CacheProvider
{
public Cache buildCache(String regionName, Properties properties) throws CacheException {
return new JBossTreeCache(regionName, getCache());
}
public long nextTimestamp() {
return System.currentTimeMillis() / 100;
}
// reference to the tree cache we discovered
private static TreeCache cache;
// What we lookup in JNDI to discobver the Tree Cache
private static final String TREECACHE_JNDI_REF = "java:/TreeCache";
public static TreeCache getCache() throws CacheException {
if ( cache != null ) return cache;
try {
synchronized (JBossTreeCache.class) {
if (cache==null) {
cache = (TreeCache)new InitialContext().lookup( TREECACHE_JNDI_REF );
if ( cache == null ) throw new CacheException("Failed to lookup TreeCache in JNDI");
}
}
}
catch (Exception e) {
throw new CacheException(e);
}
return cache;
}
}