1 7 package org.jboss.hibernate.cache; 8 9 import java.util.Properties ; 10 11 import javax.management.MBeanServer ; 12 import javax.management.ObjectName ; 13 import javax.transaction.TransactionManager ; 14 15 import org.hibernate.cache.Cache; 16 import org.hibernate.cache.CacheException; 17 import org.hibernate.cache.CacheProvider; 18 import org.jboss.cache.jmx.CacheJmxWrapperMBean; 19 import org.jboss.mx.util.MBeanProxyExt; 20 import org.jboss.mx.util.MBeanServerLocator; 21 import org.jboss.tm.TransactionManagerLocator; 22 23 30 public class DeployedTreeCacheProvider implements CacheProvider 31 { 32 public static final String OBJECT_NAME_PROP = "hibernate.treecache.objectName"; 33 public static final String DEFAULT_OBJECT_NAME = "jboss.cache:service=HibernateTreeCache"; 34 35 private org.jboss.cache.Cache deployedTreeCache; 36 37 public void start(Properties properties) throws CacheException 38 { 39 String configObjectName = properties.getProperty( OBJECT_NAME_PROP, DEFAULT_OBJECT_NAME ); 41 ObjectName objectName; 42 try 43 { 44 objectName = new ObjectName ( configObjectName ); 45 } 46 catch( Throwable t ) 47 { 48 throw new CacheException( "Malformed TreeCache ObjectName"); 49 } 50 51 CacheJmxWrapperMBean mbean; 52 try 53 { 54 MBeanServer server = MBeanServerLocator.locateJBoss(); 55 mbean = (CacheJmxWrapperMBean) MBeanProxyExt.create(CacheJmxWrapperMBean.class, objectName, server); 56 deployedTreeCache = mbean.getCache(); 57 } 58 catch( Throwable t ) 59 { 60 throw new CacheException( "Unable to locate TreeCache MBean under object name [" + configObjectName + "]" ); 61 } 62 } 63 64 public void stop() 65 { 66 deployedTreeCache = null; 67 } 68 69 public boolean isMinimalPutsEnabledByDefault() 70 { 71 return true; 72 } 73 74 82 public Cache buildCache(String name, Properties properties) throws CacheException 83 { 84 TransactionManager tm = TransactionManagerLocator.getInstance().locate(); 85 return new JBCCache( deployedTreeCache, name, tm ); 86 } 87 88 public long nextTimestamp() 89 { 90 return System.currentTimeMillis() / 100; 91 } 92 } 93 | Popular Tags |