[jboss-cvs] JBossAS SVN: r80855 - projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 12 12:46:02 EST 2008
Author: galder.zamarreno at jboss.com
Date: 2008-11-12 12:46:02 -0500 (Wed, 12 Nov 2008)
New Revision: 80855
Modified:
projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/TreeCacheProvider.java
Log:
[JBCLUSTER-217] Changed default to treecache.xml while maintaining legacy default treeecache-optimistic.xml in case the current default is not available.
Modified: projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/TreeCacheProvider.java
===================================================================
--- projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/TreeCacheProvider.java 2008-11-12 17:34:28 UTC (rev 80854)
+++ projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/TreeCacheProvider.java 2008-11-12 17:46:02 UTC (rev 80855)
@@ -22,6 +22,9 @@
package org.jboss.hibernate.jbc.cacheprovider;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
import java.util.Properties;
import javax.transaction.TransactionManager;
@@ -48,12 +51,20 @@
* @deprecated use {@link org.hibernate.cfg.Environment#CACHE_PROVIDER_CONFIG}
*/
public static final String CONFIG_RESOURCE = "hibernate.cache.tree_cache.config";
- public static final String DEFAULT_CONFIG = "treecache-optimistic.xml";
- private static final Logger log = Logger.getLogger( TreeCacheProvider.class );
+ public static final String DEFAULT_CONFIG = "treecache.xml";
+ /**
+ * @deprecated deprecared default configuration, use {@link DEFAULT_CONFIG} instead.
+ */
+ public static final String LEGACY_DEFAULT_CONFIG = "treecache-optimistic.xml";
+
+ private static final Logger log = Logger.getLogger(TreeCacheProvider.class);
+
private org.jboss.cache.TreeCache cache;
+
private TransactionManager transactionManager;
+
private boolean optimistic;
/**
@@ -64,10 +75,10 @@
* @return The Cache representation of the named cache region.
* @throws CacheException Indicates an error building the cache region.
*/
- public Cache buildCache(String regionName, Properties properties) throws CacheException
+ public Cache buildCache(String regionName, Properties properties) throws CacheException
{
CacheProperties cacheProperties = new CacheProperties(properties);
-
+
if (optimistic)
{
return new OptimisticJBCCache(getUnderlyingCache(), regionName, cacheProperties);
@@ -79,10 +90,11 @@
}
}
- public long nextTimestamp() {
- return System.currentTimeMillis() / 100;
+ public long nextTimestamp()
+ {
+ return System.currentTimeMillis() / 100;
}
-
+
public boolean isOptimistic()
{
return optimistic;
@@ -95,78 +107,110 @@
*
* @throws CacheException Indicates a problem preparing cache for use.
*/
- public void start(Properties properties) {
- String resource = properties.getProperty( Environment.CACHE_PROVIDER_CONFIG );
+ public void start(Properties properties)
+ {
+ 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)
- {
- cache.setTransactionManagerLookup( new TransactionManagerLookupAdaptor(transactionManagerLookup, properties) );
- transactionManager = transactionManagerLookup.getTransactionManager(properties);
- }
- cache.startService();
-
- 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);
- }
+ if (resource == null)
+ {
+ resource = properties.getProperty(CONFIG_RESOURCE);
+ }
+ if (resource == null)
+ {
+ resource = configFileExists(DEFAULT_CONFIG) ? DEFAULT_CONFIG : null;
+ }
+ if (resource == null)
+ {
+ /* If new default does not exists, try to lookup legacy default config file.
+ * If found, then use legacy default config file, if not, revert back
+ * to default config, which will fail but at least will show current default. */
+ resource = configFileExists(LEGACY_DEFAULT_CONFIG) ? LEGACY_DEFAULT_CONFIG : 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)
+ {
+ cache.setTransactionManagerLookup(new TransactionManagerLookupAdaptor(transactionManagerLookup, properties));
+ transactionManager = transactionManagerLookup.getTransactionManager(properties);
+ }
+ cache.startService();
+
+ 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 void stop()
+ public void stop()
{
- if (cache!=null)
- {
- cache.stopService();
- cache=null;
- }
+ if (cache != null)
+ {
+ cache.stopService();
+ cache = null;
+ }
}
-
- public boolean isMinimalPutsEnabledByDefault()
+
+ public boolean isMinimalPutsEnabledByDefault()
{
- return true;
+ return true;
}
- public org.jboss.cache.TreeCache getUnderlyingCache()
+ public org.jboss.cache.TreeCache getUnderlyingCache()
{
- return cache;
+ return cache;
}
- static final class TransactionManagerLookupAdaptor implements org.jboss.cache.TransactionManagerLookup
+ protected boolean configFileExists(String configFile)
{
- private final TransactionManagerLookup tml;
- private final Properties props;
-
- TransactionManagerLookupAdaptor(TransactionManagerLookup tml, Properties props)
- {
- this.tml=tml;
- this.props=props;
- }
-
- public TransactionManager getTransactionManager() throws Exception
- {
- return tml.getTransactionManager(props);
- }
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ InputStream is = cl.getResourceAsStream(configFile);
+ if (is == null)
+ {
+ try
+ {
+ is = new FileInputStream(configFile);
+ }
+ catch (FileNotFoundException e)
+ {
+ log.debug("Config file not found: " + configFile);
+ }
+ }
+ if (is == null)
+ {
+ return false;
+ }
+
+ log.debug("Using configuration file: " + configFile);
+ return true;
}
+ static final class TransactionManagerLookupAdaptor implements org.jboss.cache.TransactionManagerLookup
+ {
+ private final TransactionManagerLookup tml;
+
+ private final Properties props;
+
+ TransactionManagerLookupAdaptor(TransactionManagerLookup tml, Properties props)
+ {
+ this.tml = tml;
+ this.props = props;
+ }
+
+ public TransactionManager getTransactionManager() throws Exception
+ {
+ return tml.getTransactionManager(props);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list