Author: galder.zamarreno(a)jboss.com
Date: 2009-08-13 04:49:58 -0400 (Thu, 13 Aug 2009)
New Revision: 17297
Added:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanConfiguration.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TimestampTypeOverrides.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TypeOverrides.java
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml
Removed:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java
Modified:
core/branches/INFINISPAN/cache-infinispan/
core/branches/INFINISPAN/cache-infinispan/pom.xml
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java
Log:
[ISPN-6] Infinispan overrides via hibernate properties defined and tested.
Property changes on: core/branches/INFINISPAN/cache-infinispan
___________________________________________________________________
Name: svn:ignore
- target
.classpath
.project
+ target
.classpath
.project
.settings
Modified: core/branches/INFINISPAN/cache-infinispan/pom.xml
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/pom.xml 2009-08-13 04:15:37 UTC (rev 17296)
+++ core/branches/INFINISPAN/cache-infinispan/pom.xml 2009-08-13 08:49:58 UTC (rev 17297)
@@ -16,6 +16,21 @@
<name>Hibernate Infinispan Integration</name>
<description>Integration of Hibernate with Infinispan</description>
+ <properties>
+ <version.infinispan>4.0.0-SNAPSHOT</version.infinispan>
+ <version.hsqldb>1.8.0.2</version.hsqldb>
+ <version.cglib>2.2</version.cglib>
+ <version.javassist>3.4.GA</version.javassist>
+ <skipUnitTests>true</skipUnitTests>
+ <!--
+ Following is the default jgroups mcast address. If you find the testsuite runs
very slowly, there
+ may be problems with multicast on the interface JGroups uses by default on your
machine. You can
+ try to resolve setting 'jgroups.bind_addr' as a system-property to the
jvm launching maven and
+ setting the value to an interface where you know multicast works
+ -->
+ <jgroups.bind_addr>127.0.0.1</jgroups.bind_addr>
+ </properties>
+
<dependencies>
<dependency>
<groupId>${groupId}</groupId>
@@ -25,7 +40,7 @@
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
- <version>4.0.0.ALPHA5</version>
+ <version>${version.infinispan}</version>
</dependency>
<!-- test dependencies -->
@@ -38,20 +53,20 @@
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
- <version>1.8.0.2</version>
+ <version>${version.hsqldb}</version>
<scope>test</scope>
</dependency>
<!-- this is optional on core :( and needed for testing -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
- <version>2.2</version>
+ <version>${version.cglib}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
- <version>3.4.GA</version>
+ <version>${version.javassist}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -124,17 +139,6 @@
</plugins>
</build>
- <properties>
- <skipUnitTests>true</skipUnitTests>
- <!--
- Following is the default jgroups mcast address. If you find the testsuite
runs very slowly, there
- may be problems with multicast on the interface JGroups uses by default on
your machine. You can
- try to resolve setting 'jgroups.bind_addr' as a system-property to
the jvm launching maven and
- setting the value to an interface where you know multicast works
- -->
- <jgroups.bind_addr>127.0.0.1</jgroups.bind_addr>
- </properties>
-
<profiles>
<profile>
<id>test</id>
Deleted:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -1,112 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.cache.infinispan;
-
-import java.util.Locale;
-
-import org.infinispan.eviction.EvictionStrategy;
-
-/**
- * This class represents parameters that can be configured for general
- * entity/collection/query/timestamp data type caches and overrides for
- * individual entity or collection caches.
- *
- * @author Galder Zamarreño
- */
-public class DataTypeConfig {
-
- private String cache;
-
- private EvictionStrategy strategy;
-
- private long wakeUpInterval;
-
- private int maxEntries;
-
- private long lifespan;
-
- private long maxIdle;
-
- public String getCache() {
- return cache;
- }
-
- public void setCache(String cache) {
- this.cache = cache;
- }
-
- public EvictionStrategy getStrategy() {
- return strategy;
- }
-
- public void setStrategy(String strategy) {
- this.strategy = EvictionStrategy.valueOf(uc(strategy));
- }
-
- public long getWakeUpInterval() {
- return wakeUpInterval;
- }
-
- public void setWakeUpInterval(long wakeUpInterval) {
- this.wakeUpInterval = wakeUpInterval;
- }
-
- public int getMaxEntries() {
- return maxEntries;
- }
-
- public void setMaxEntries(int maxEntries) {
- this.maxEntries = maxEntries;
- }
-
- public long getLifespan() {
- return lifespan;
- }
-
- public void setLifespan(long lifespan) {
- this.lifespan = lifespan;
- }
-
- public long getMaxIdle() {
- return maxIdle;
- }
-
- public void setMaxIdle(long maxIdle) {
- this.maxIdle = maxIdle;
- }
-
- @Override
- public String toString() {
- return new StringBuilder().append(getClass().getSimpleName()).append('{')
- .append("cache=").append(cache)
- .append(", strategy=").append(strategy)
- .append(", wakeUpInterval=").append(wakeUpInterval)
- .append(", maxEntries=").append(maxEntries)
- .append(", lifespan=").append(lifespan)
- .append(", maxIdle=").append(maxIdle)
- .append('}').toString();
- }
-
- private String uc(String s) {
- return s == null ? null : s.toUpperCase(Locale.ENGLISH);
- }
-}
Added:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanConfiguration.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanConfiguration.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanConfiguration.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.cache.infinispan;
+
+import org.infinispan.config.Configuration;
+
+/**
+ * InfinispanConfiguration.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class InfinispanConfiguration {
+
+ private final Configuration configuration;
+
+ public InfinispanConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+}
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -3,8 +3,10 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import org.hibernate.cache.CacheDataDescription;
import org.hibernate.cache.CacheException;
@@ -19,6 +21,9 @@
import org.hibernate.cache.infinispan.timestamp.InfinispanTimestampsRegion;
import org.hibernate.cfg.Settings;
import org.hibernate.util.PropertiesHelper;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.manager.CacheManager;
import org.infinispan.manager.DefaultCacheManager;
import org.slf4j.Logger;
@@ -117,7 +122,9 @@
private CacheManager manager;
- private final Map<String, DataTypeConfig> configs = new HashMap<String,
DataTypeConfig>();
+ private final Map<String, TypeOverrides> typeOverrides = new HashMap<String,
TypeOverrides>();
+
+ private final Set<String> definedConfigurations = new HashSet<String>();
/**
* Create a new instance using the default configuration.
@@ -134,23 +141,47 @@
public InfinispanRegionFactory(Properties props) {
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public CollectionRegion buildCollectionRegion(String regionName, Properties
properties,
CacheDataDescription metadata) throws CacheException {
log.debug("Building collection cache region [" + regionName +
"]");
- return new InfinispanCollectionRegion(manager.getCache(regionName), regionName,
metadata);
+ Cache cache = getCache(regionName, COLLECTION_KEY);
+ return new InfinispanCollectionRegion(cache, regionName, metadata);
}
- /**
- * {@inheritDoc}
- */
- public EntityRegion buildEntityRegion(String regionName, Properties properties,
- CacheDataDescription metadata) throws CacheException {
- log.debug("Building entity cache region [" + regionName +
"]");
- // TODO: check the configs map for this region and do the corresponding work
- return new InfinispanEntityRegion(manager.getCache(regionName), regionName,
metadata);
+ /** {@inheritDoc} */
+ public EntityRegion buildEntityRegion(String regionName, Properties properties,
CacheDataDescription metadata) throws CacheException {
+ if (log.isDebugEnabled()) log.debug("Building entity cache region [" +
regionName + "]");
+ Cache cache = getCache(regionName, ENTITY_KEY);
+ return new InfinispanEntityRegion(cache, regionName, metadata);
+// TypeOverrides regionOverride = typeOverrides.get(regionName);
+// if (regionOverride != null) {
+// if (log.isDebugEnabled()) log.debug("Entity cache region specific
configuration exists: " + regionOverride);
+// String cacheName = regionOverride.getCacheName();
+// String templateCacheName = null;
+// if (cacheName != null) {
+// // If override has been converted to cache configuration, it means that the
cache configuration has
+// // already been defined and hence we only need to get the cache instance
corresponding to that cache name
+// if (!regionOverride.isConvertedToInfinispanConfiguration()) {
+// templateCacheName = cacheName;
+// Configuration regionCacheCfg =
regionOverride.createInfinispanConfiguration();
+// manager.defineConfiguration(cacheName, templateCacheName,
regionCacheCfg);
+// }
+// cache = manager.getCache(cacheName);
+// } else {
+// // If cache name is null, the base configuration is the generic entity data
type one
+// // and the cache name is the name of the region.
+// if (!regionOverride.isConvertedToInfinispanConfiguration()) {
+// templateCacheName = typeOverrides.get(ENTITY_KEY).getCacheName();
+// Configuration regionCacheCfg =
regionOverride.createInfinispanConfiguration();
+// manager.defineConfiguration(regionName, templateCacheName,
regionCacheCfg);
+// }
+// cache = manager.getCache(regionName);
+// }
+// } else {
+// // No region specific overrides, get a cache instance for the generic entity
data type region
+// cache = manager.getCache(typeOverrides.get(ENTITY_KEY).getCacheName());
+// }
}
/**
@@ -201,61 +232,60 @@
try {
String configLoc = PropertiesHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP,
properties, DEF_INFINISPAN_CONFIG_RESOURCE);
manager = new DefaultCacheManager(configLoc);
- initDefaultCacheNames();
-
+ initGenericDataTypeOverrides();
Enumeration keys = properties.propertyNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
int prefixLoc = -1;
if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
- DataTypeConfig cfgOverride = null;
- int suffixLoc = -1;
- if ((suffixLoc = key.indexOf(CONFIG_SUFFIX)) != -1) {
- cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
- cfgOverride.setCache(PropertiesHelper.extractPropertyValue(key,
properties));
-// String name = key.substring(prefixLoc + PREFIX.length(), suffixLoc);
-// cfgOverride = configs.get(name);
-// if (cfgOverride == null) {
-// cfgOverride = new DataTypeConfig();
-// configs.put(name, cfgOverride);
-// }
-// String cache = null;
-// if (name.equals(ENTITY_CACHE_RESOURCE_PROP)) {
-// cache = PropertiesHelper.getString(ENTITY_CACHE_RESOURCE_PROP,
properties, DEF_ENTITY_RESOURCE);
-// } else if (name.equals(COLLECTION_CACHE_RESOURCE_PROP)) {
-// cache = PropertiesHelper.getString(COLLECTION_CACHE_RESOURCE_PROP,
properties, DEF_ENTITY_RESOURCE);
-// } else if (name.equals(TIMESTAMP_CACHE_RESOURCE_PROP)) {
-// cache = PropertiesHelper.getString(TIMESTAMP_CACHE_RESOURCE_PROP,
properties, DEF_TIMESTAMP_RESOURCE);
-// } else if (name.equals(QUERY_CACHE_RESOURCE_PROP)) {
-// cache = PropertiesHelper.getString(QUERY_CACHE_RESOURCE_PROP,
properties, DEF_QUERY_RESOURCE);
-// } else {
-// cache = PropertiesHelper.extractPropertyValue(key, properties);
-// }
-// cfgOverride.setCache(cache);
- } else if ((suffixLoc = key.indexOf(STRATEGY_SUFFIX)) != -1) {
- cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
- cfgOverride.setStrategy(PropertiesHelper.extractPropertyValue(key,
properties));
- } else if ((suffixLoc = key.indexOf(WAKE_UP_INTERVAL_SUFFIX)) != -1) {
- cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
-
cfgOverride.setWakeUpInterval(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
- } else if ((suffixLoc = key.indexOf(MAX_ENTRIES_SUFFIX)) != -1) {
- cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
- cfgOverride.setMaxEntries(PropertiesHelper.getInt(key, properties,
-1));
- } else if ((suffixLoc = key.indexOf(LIFESPAN_SUFFIX)) != -1) {
- cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
-
cfgOverride.setLifespan(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
- } else if ((suffixLoc = key.indexOf(MAX_IDLE_SUFFIX)) != -1) {
- cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
-
cfgOverride.setMaxIdle(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
- }
+ dissectProperty(prefixLoc, key, properties);
}
-
}
+ defineGenericDataTypeCacheConfigurations();
} catch (CacheException ce) {
throw ce;
} catch (Throwable t) {
throw new CacheException("Unable to start region factory", t);
}
+
+// if ((suffixLoc = key.indexOf(CONFIG_SUFFIX)) != -1) {
+// cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+// cfgOverride.setCache(PropertiesHelper.extractPropertyValue(key,
properties));
+//// String name = key.substring(prefixLoc + PREFIX.length(),
suffixLoc);
+//// cfgOverride = configs.get(name);
+//// if (cfgOverride == null) {
+//// cfgOverride = new DataTypeConfig();
+//// configs.put(name, cfgOverride);
+//// }
+//// String cache = null;
+//// if (name.equals(ENTITY_CACHE_RESOURCE_PROP)) {
+//// cache = PropertiesHelper.getString(ENTITY_CACHE_RESOURCE_PROP,
properties, DEF_ENTITY_RESOURCE);
+//// } else if (name.equals(COLLECTION_CACHE_RESOURCE_PROP)) {
+//// cache =
PropertiesHelper.getString(COLLECTION_CACHE_RESOURCE_PROP, properties,
DEF_ENTITY_RESOURCE);
+//// } else if (name.equals(TIMESTAMP_CACHE_RESOURCE_PROP)) {
+//// cache =
PropertiesHelper.getString(TIMESTAMP_CACHE_RESOURCE_PROP, properties,
DEF_TIMESTAMP_RESOURCE);
+//// } else if (name.equals(QUERY_CACHE_RESOURCE_PROP)) {
+//// cache = PropertiesHelper.getString(QUERY_CACHE_RESOURCE_PROP,
properties, DEF_QUERY_RESOURCE);
+//// } else {
+//// cache = PropertiesHelper.extractPropertyValue(key, properties);
+//// }
+//// cfgOverride.setCache(cache);
+// } else if ((suffixLoc = key.indexOf(STRATEGY_SUFFIX)) != -1) {
+// cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+// cfgOverride.setStrategy(PropertiesHelper.extractPropertyValue(key,
properties));
+// } else if ((suffixLoc = key.indexOf(WAKE_UP_INTERVAL_SUFFIX)) != -1) {
+// cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+//
cfgOverride.setWakeUpInterval(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
+// } else if ((suffixLoc = key.indexOf(MAX_ENTRIES_SUFFIX)) != -1) {
+// cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+// cfgOverride.setMaxEntries(PropertiesHelper.getInt(key, properties,
-1));
+// } else if ((suffixLoc = key.indexOf(LIFESPAN_SUFFIX)) != -1) {
+// cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+//
cfgOverride.setLifespan(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
+// } else if ((suffixLoc = key.indexOf(MAX_IDLE_SUFFIX)) != -1) {
+// cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+//
cfgOverride.setMaxIdle(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
+// }
}
/**
@@ -272,35 +302,158 @@
*
* @return an unmodifiable map.
*/
- public Map<String, DataTypeConfig> getConfigs() {
- return Collections.unmodifiableMap(configs);
+ public Map<String, TypeOverrides> getTypeOverrides() {
+ return Collections.unmodifiableMap(typeOverrides);
}
- private void initDefaultCacheNames() {
- DataTypeConfig entity = new DataTypeConfig();
- entity.setCache(DEF_ENTITY_RESOURCE);
- configs.put(ENTITY_KEY, entity);
+ public Set<String> getDefinedConfigurations() {
+ return Collections.unmodifiableSet(definedConfigurations);
+ }
+
+// private Configuration createCacheConfig(TypeOverrides config) {
+// Configuration cacheCfg = new Configuration();
+// return overrideCacheConfig(config, cacheCfg);
+// }
- DataTypeConfig collection = new DataTypeConfig();
- collection.setCache(DEF_ENTITY_RESOURCE);
- configs.put(COLLECTION_KEY, collection);
+ private Map<String, TypeOverrides> initGenericDataTypeOverrides() {
+ TypeOverrides entityOverrides = new TypeOverrides();
+ entityOverrides.setCacheName(DEF_ENTITY_RESOURCE);
+ typeOverrides.put(ENTITY_KEY, entityOverrides);
+ TypeOverrides collectionOverrides = new TypeOverrides();
+ collectionOverrides.setCacheName(DEF_ENTITY_RESOURCE);
+ typeOverrides.put(COLLECTION_KEY, collectionOverrides);
+ TypeOverrides timestampOverrides = new TimestampTypeOverrides();
+ timestampOverrides.setCacheName(DEF_TIMESTAMP_RESOURCE);
+ typeOverrides.put(TIMESTAMP_KEY, timestampOverrides);
+ TypeOverrides queryOverrides = new TypeOverrides();
+ queryOverrides.setCacheName(DEF_QUERY_RESOURCE);
+ typeOverrides.put(QUERY_KEY, queryOverrides);
+ return typeOverrides;
+ }
- DataTypeConfig timestamp = new DataTypeConfig();
- timestamp.setCache(DEF_TIMESTAMP_RESOURCE);
- configs.put(TIMESTAMP_KEY, timestamp);
-
- DataTypeConfig query = new DataTypeConfig();
- query.setCache(DEF_QUERY_RESOURCE);
- configs.put(QUERY_KEY, query);
+// private boolean isGenericDataTypeProperty(String property) {
+// return property.startsWith(PREFIX + ENTITY_KEY) || property.startsWith(PREFIX +
COLLECTION_KEY)
+// || property.startsWith(PREFIX + QUERY_KEY) || property.startsWith(PREFIX +
TIMESTAMP_KEY);
+// }
+
+ private void dissectProperty(int prefixLoc, String key, Properties properties) {
+ TypeOverrides cfgOverride = null;
+ int suffixLoc = -1;
+ if (!key.equals(INFINISPAN_CONFIG_RESOURCE_PROP) && (suffixLoc =
key.indexOf(CONFIG_SUFFIX)) != -1) {
+ cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
+ cfgOverride.setCacheName(PropertiesHelper.extractPropertyValue(key,
properties));
+ } else if ((suffixLoc = key.indexOf(STRATEGY_SUFFIX)) != -1) {
+ cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
+ cfgOverride.setEvictionStrategy(PropertiesHelper.extractPropertyValue(key,
properties));
+ } else if ((suffixLoc = key.indexOf(WAKE_UP_INTERVAL_SUFFIX)) != -1) {
+ cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
+
cfgOverride.setEvictionWakeUpInterval(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
+ } else if ((suffixLoc = key.indexOf(MAX_ENTRIES_SUFFIX)) != -1) {
+ cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
+ cfgOverride.setEvictionMaxEntries(PropertiesHelper.getInt(key, properties,
-1));
+ } else if ((suffixLoc = key.indexOf(LIFESPAN_SUFFIX)) != -1) {
+ cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
+
cfgOverride.setExpirationLifespan(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
+ } else if ((suffixLoc = key.indexOf(MAX_IDLE_SUFFIX)) != -1) {
+ cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
+
cfgOverride.setExpirationMaxIdle(Long.parseLong(PropertiesHelper.extractPropertyValue(key,
properties)));
+ }
}
- private DataTypeConfig getOrCreateConfig(String key, int prefixLoc, int suffixLoc) {
+// private Configuration overrideCacheConfig(TypeOverrides config, Configuration
baseCacheCfg) {
+// // If eviction strategy is different from null, an override has been defined
+// EvictionStrategy strategy = config.getEvictionStrategy();
+// if (strategy != null) baseCacheCfg.setEvictionStrategy(strategy);
+// // If eviction wake up interval is different from min value, an override has been
defined
+// // Checking for -1 might not be enough because user might have defined -1 in the
config.
+// // Same applies to other configuration options.
+// long wakeUpInterval = config.getEvictionWakeUpInterval();
+// if (wakeUpInterval != Long.MIN_VALUE)
baseCacheCfg.setEvictionWakeUpInterval(wakeUpInterval);
+// int maxEntries = config.getEvictionMaxEntries();
+// if (maxEntries != Integer.MIN_VALUE)
baseCacheCfg.setEvictionMaxEntries(maxEntries);
+// long lifespan = config.getExpirationLifespan();
+// if (lifespan != Long.MIN_VALUE) baseCacheCfg.setExpirationLifespan(lifespan);
+// long maxIdle = config.getExpirationMaxIdle();
+// if (maxIdle != Long.MIN_VALUE) baseCacheCfg.setExpirationMaxIdle(maxIdle);
+// return baseCacheCfg;
+// }
+
+ private TypeOverrides getOrCreateConfig(int prefixLoc, String key, int suffixLoc) {
String name = key.substring(prefixLoc + PREFIX.length(), suffixLoc);
- DataTypeConfig cfgOverride = configs.get(name);
+ TypeOverrides cfgOverride = typeOverrides.get(name);
if (cfgOverride == null) {
- cfgOverride = new DataTypeConfig();
- configs.put(name, cfgOverride);
+ cfgOverride = new TypeOverrides();
+ typeOverrides.put(name, cfgOverride);
}
return cfgOverride;
}
+
+ private void defineGenericDataTypeCacheConfigurations() throws CacheException {
+ String[] defaultGenericDataTypes = new String[]{ENTITY_KEY, COLLECTION_KEY,
TIMESTAMP_KEY, QUERY_KEY};
+ for (String type : defaultGenericDataTypes) {
+ TypeOverrides override = typeOverrides.get(type);
+ String cacheName = override.getCacheName();
+ Configuration newCacheCfg = override.createInfinispanConfiguration();
+ Configuration cacheConfig = manager.defineConfiguration(cacheName, cacheName,
newCacheCfg);
+ definedConfigurations.add(cacheName);
+ override.validateInfinispanConfiguration(cacheConfig);
+ }
+ }
+
+ private Cache getCache(String regionName, String typeKey) {
+ TypeOverrides regionOverride = typeOverrides.get(regionName);
+ if (!definedConfigurations.contains(regionName)) {
+ String templateCacheName = null;
+ Configuration regionCacheCfg = null;
+ if (regionOverride != null) {
+ if (log.isDebugEnabled()) log.debug("Entity cache region specific
configuration exists: " + regionOverride);
+ regionCacheCfg = regionOverride.createInfinispanConfiguration();
+ String cacheName = regionOverride.getCacheName();
+ if (cacheName != null) // Region specific override with a given cache name
+ templateCacheName = cacheName;
+ else // Region specific override without cache name, so template cache name
is generic for data type.
+ templateCacheName = typeOverrides.get(typeKey).getCacheName();
+ } else {
+ // No region specific overrides, template cache name is generic for data
type.
+ templateCacheName = typeOverrides.get(typeKey).getCacheName();
+ regionCacheCfg = typeOverrides.get(typeKey).createInfinispanConfiguration();
+ }
+ manager.defineConfiguration(regionName, templateCacheName, regionCacheCfg);
+ definedConfigurations.add(regionName);
+ }
+ return manager.getCache(regionName);
+
+// if (regionOverride != null) {
+// if (log.isDebugEnabled()) log.debug("Entity cache region specific
configuration exists: " + regionOverride);
+// String cacheName = regionOverride.getCacheName();
+// if (cacheName != null) {
+// // Region specific override with a given cache name
+// if (!definedConfigurations.contains(regionName)) {
+// templateCacheName = cacheName;
+// regionCacheCfg = regionOverride.createInfinispanConfiguration();
+// manager.defineConfiguration(regionName, templateCacheName,
regionCacheCfg);
+// definedConfigurations.add(regionName);
+// }
+// return manager.getCache(regionName);
+// } else {
+// // Region specific override without cache name, so template cache name is
generic for data type.
+// if (!definedConfigurations.contains(regionName)) {
+// templateCacheName = typeOverrides.get(typeKey).getCacheName();
+// regionCacheCfg = regionOverride.createInfinispanConfiguration();
+// manager.defineConfiguration(regionName, templateCacheName,
regionCacheCfg);
+// definedConfigurations.add(regionName);
+// }
+// return manager.getCache(regionName);
+// }
+// }
+//
+// if (!definedConfigurations.contains(regionName)) {
+// templateCacheName = typeOverrides.get(typeKey).getCacheName();
+// regionCacheCfg = typeOverrides.get(typeKey).createInfinispanConfiguration();
+// manager.defineConfiguration(regionName, templateCacheName, regionCacheCfg);
+// definedConfigurations.add(regionName);
+// }
+// // No region specific overrides, get a cache instance for the generic entity data
type region
+// return manager.getCache(regionName);
+ }
}
\ No newline at end of file
Added:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TimestampTypeOverrides.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TimestampTypeOverrides.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TimestampTypeOverrides.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.cache.infinispan;
+
+import org.hibernate.cache.CacheException;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
+
+/**
+ * TimestampTypeOverrides.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class TimestampTypeOverrides extends TypeOverrides {
+ @Override
+ public void validateInfinispanConfiguration(Configuration configuration) throws
CacheException {
+ CacheMode cacheMode = configuration.getCacheMode();
+ if (cacheMode.equals(CacheMode.INVALIDATION_ASYNC) ||
cacheMode.equals(CacheMode.INVALIDATION_SYNC)) {
+ throw new CacheException("Timestamp cache cannot be configured with
invalidation");
+ }
+ }
+}
Copied:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TypeOverrides.java
(from rev 17244,
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java)
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TypeOverrides.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/TypeOverrides.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.cache.infinispan;
+
+import java.util.Locale;
+
+import org.hibernate.cache.CacheException;
+import org.infinispan.config.Configuration;
+import org.infinispan.eviction.EvictionStrategy;
+
+/**
+ * This class represents Infinispan cache parameters that can be configured via hibernate
configuration properties
+ * for either general entity/collection/query/timestamp data type caches and overrides
for individual entity or
+ * collection caches. Configuration these properties override previously defined
properties in XML file.
+ *
+ * @author Galder Zamarreño
+ */
+public class TypeOverrides {
+
+ private String cacheName;
+
+ private EvictionStrategy evictionStrategy;
+
+ private long evictionWakeUpInterval = Long.MIN_VALUE;
+
+ private int evictionMaxEntries = Integer.MIN_VALUE;
+
+ private long expirationLifespan = Long.MIN_VALUE;
+
+ private long expirationMaxIdle = Long.MIN_VALUE;
+
+ public String getCacheName() {
+ return cacheName;
+ }
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ public EvictionStrategy getEvictionStrategy() {
+ return evictionStrategy;
+ }
+
+ public void setEvictionStrategy(String evictionStrategy) {
+ this.evictionStrategy = EvictionStrategy.valueOf(uc(evictionStrategy));
+ }
+
+ public long getEvictionWakeUpInterval() {
+ return evictionWakeUpInterval;
+ }
+
+ public void setEvictionWakeUpInterval(long evictionWakeUpInterval) {
+ this.evictionWakeUpInterval = evictionWakeUpInterval;
+ }
+
+ public int getEvictionMaxEntries() {
+ return evictionMaxEntries;
+ }
+
+ public void setEvictionMaxEntries(int evictionMaxEntries) {
+ this.evictionMaxEntries = evictionMaxEntries;
+ }
+
+ public long getExpirationLifespan() {
+ return expirationLifespan;
+ }
+
+ public void setExpirationLifespan(long expirationLifespan) {
+ this.expirationLifespan = expirationLifespan;
+ }
+
+ public long getExpirationMaxIdle() {
+ return expirationMaxIdle;
+ }
+
+ public void setExpirationMaxIdle(long expirationMaxIdle) {
+ this.expirationMaxIdle = expirationMaxIdle;
+ }
+
+// public boolean isConvertedToInfinispanConfiguration() {
+// return convertedToInfinispanConfiguration;
+// }
+
+ public Configuration createInfinispanConfiguration() {
+ Configuration cacheCfg = new Configuration();
+ // If eviction strategy is different from null, an override has been defined
+ if (evictionStrategy != null) cacheCfg.setEvictionStrategy(evictionStrategy);
+ // If eviction wake up interval is different from min value, an override has been
defined
+ // Checking for -1 might not be enough because user might have defined -1 in the
config.
+ // Same applies to other configuration options.
+ if (evictionWakeUpInterval != Long.MIN_VALUE)
cacheCfg.setEvictionWakeUpInterval(evictionWakeUpInterval);
+ if (evictionMaxEntries != Integer.MIN_VALUE)
cacheCfg.setEvictionMaxEntries(evictionMaxEntries);
+ if (expirationLifespan != Long.MIN_VALUE)
cacheCfg.setExpirationLifespan(expirationLifespan);
+ if (expirationMaxIdle != Long.MIN_VALUE)
cacheCfg.setExpirationMaxIdle(expirationMaxIdle);
+// convertedToInfinispanConfiguration = true;
+ return cacheCfg;
+ }
+
+ public void validateInfinispanConfiguration(Configuration configuration) throws
CacheException {
+ // no-op
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder().append(getClass().getSimpleName()).append('{')
+ .append("cache=").append(cacheName)
+ .append(", strategy=").append(evictionStrategy)
+ .append(", wakeUpInterval=").append(evictionWakeUpInterval)
+ .append(", maxEntries=").append(evictionMaxEntries)
+ .append(", lifespan=").append(expirationLifespan)
+ .append(", maxIdle=").append(expirationMaxIdle)
+ .append('}').toString();
+ }
+
+ private String uc(String s) {
+ return s == null ? null : s.toUpperCase(Locale.ENGLISH);
+ }
+}
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -10,19 +10,17 @@
public class InfinispanCollectionRegion extends BaseTransactionalDataRegion implements
CollectionRegion {
- public InfinispanCollectionRegion( Cache<Object, Object> cache, String name,
CacheDataDescription metadata ) {
- super( cache, name, metadata );
- }
+ public InfinispanCollectionRegion(Cache<Object, Object> cache, String name,
CacheDataDescription metadata) {
+ super(cache, name, metadata);
+ }
- public CollectionRegionAccessStrategy buildAccessStrategy( AccessType accessType )
- throws CacheException {
- if (AccessType.READ_ONLY.equals( accessType )) {
- return new ReadOnlyAccess(this);
- } else if (AccessType.TRANSACTIONAL.equals( accessType )) {
- return new TransactionalAccess(this);
- }
-
- throw new CacheException("unsupported access type [" +
accessType.getName() + "]");
- }
+ public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType)
throws CacheException {
+ if (AccessType.READ_ONLY.equals(accessType)) {
+ return new ReadOnlyAccess(this);
+ } else if (AccessType.TRANSACTIONAL.equals(accessType)) {
+ return new TransactionalAccess(this);
+ }
+ throw new CacheException("unsupported access type [" +
accessType.getName() + "]");
+ }
}
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -9,21 +9,18 @@
import org.infinispan.Cache;
public class InfinispanEntityRegion extends BaseTransactionalDataRegion implements
EntityRegion {
-
- public InfinispanEntityRegion( Cache<Object, Object> cache, String name,
CacheDataDescription metadata ) {
- super( cache, name, metadata );
- }
- public EntityRegionAccessStrategy buildAccessStrategy( AccessType accessType )
- throws CacheException {
- if (AccessType.READ_ONLY.equals( accessType )) {
- return new ReadOnlyAccess(this);
- } else if (AccessType.TRANSACTIONAL.equals( accessType )) {
- return new TransactionalAccess(this);
- }
-
- throw new CacheException("unsupported access type [" +
accessType.getName() + "]");
+ public InfinispanEntityRegion(Cache<Object, Object> cache, String name,
CacheDataDescription metadata) {
+ super(cache, name, metadata);
+ }
- }
+ public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws
CacheException {
+ if (AccessType.READ_ONLY.equals(accessType)) {
+ return new ReadOnlyAccess(this);
+ } else if (AccessType.TRANSACTIONAL.equals(accessType)) {
+ return new TransactionalAccess(this);
+ }
+ throw new CacheException("unsupported access type [" +
accessType.getName() + "]");
+ }
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -15,15 +15,15 @@
* @author Galder Zamarreño
*/
abstract class BaseRegion implements Region {
- private final Cache<Object, Object> cache;
+ private final Cache cache;
private final String name;
- public BaseRegion(Cache<Object, Object> cache, String name) {
+ public BaseRegion(Cache cache, String name) {
this.cache = cache;
this.name = name;
}
- public Cache<Object, Object> getCache() {
+ public Cache getCache() {
return cache;
}
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -10,19 +10,20 @@
* @author Chris Bredesen
*/
public abstract class BaseTransactionalDataRegion extends BaseRegion implements
TransactionalDataRegion {
- private final CacheDataDescription metadata;
-
- public BaseTransactionalDataRegion( Cache<Object, Object> cache, String name,
CacheDataDescription metadata ) {
- super( cache, name );
- this.metadata = metadata;
- }
- public CacheDataDescription getCacheDataDescription() {
- return metadata;
- }
+ private final CacheDataDescription metadata;
- public boolean isTransactionAware() {
- return true;
- }
+ public BaseTransactionalDataRegion(Cache<Object, Object> cache, String name,
CacheDataDescription metadata) {
+ super(cache, name);
+ this.metadata = metadata;
+ }
+ public CacheDataDescription getCacheDataDescription() {
+ return metadata;
+ }
+
+ public boolean isTransactionAware() {
+ return true;
+ }
+
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml 2009-08-13
08:49:58 UTC (rev 17297)
@@ -4,8 +4,10 @@
<transport transportClass =
"org.infinispan.remoting.transport.jgroups.JGroupsTransport"
clusterName="infinispan-hibernate-cluster"
distributedSyncTimeout="50000">
<!-- Note that the JGroups transport uses sensible defaults if no
configuration property is defined. -->
- <!-- TODO: Change to udp.xml once streaming transfer requirement has been
removed. -->
- <property name="configurationFile"
value="flush-udp.xml"/>
+ <properties>
+ <!-- TODO: Change to udp.xml once streaming transfer requirement has been
removed. -->
+ <property name="configurationFile"
value="flush-udp.xml"/>
+ </properties>
<!-- See the JGroupsTransport javadocs for more flags -->
</transport>
<serialization
marshallerClass="org.infinispan.marshall.VersionAwareMarshaller"
version="4.0"/>
@@ -13,12 +15,12 @@
<default>
<!-- Used to register JMX statistics in any available MBean server -->
- <jmxStatistics enabled="false"/>
+ <jmxStatistics enabled="false"/>
</default>
<!-- Default configuration is appropriate for entity/collection caching. -->
<namedCache name="entity">
- <clustering mode="invalidation">
+ <clustering mode="INVALIDATION_SYNC">
<stateRetrieval fetchInMemoryState="false"
timeout="20000"/>
<sync replTimeout="20000"/>
</clustering>
@@ -35,7 +37,7 @@
-->
<eviction wakeUpInterval="5000" maxEntries="10000"
strategy="FIFO"/>
<expiration maxIdle="100000"/>
- <lazyDeserialization enabled="true"/>
+ <lazyDeserialization enabled="true"/>
</namedCache>
<!-- A config appropriate for query caching. Does not replicate
@@ -56,14 +58,14 @@
itself is configured with CacheMode=LOCAL.
-->
<namedCache name="timestamp">
- <clustering mode="REPL">
+ <clustering mode="REPL_ASYNC">
<stateRetrieval fetchInMemoryState="true"
timeout="20000"/>
<async/>
</clustering>
<locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
<lazyDeserialization enabled="true"/>
<!-- Don't ever evict modification timestamps -->
- <eviction strategy="NONE"/>
+ <eviction wakeUpInterval="0" strategy="NONE"/>
</namedCache>
</infinispan>
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -23,7 +23,12 @@
import java.util.Properties;
+import org.hibernate.cache.CacheException;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
+import org.hibernate.cache.infinispan.collection.InfinispanCollectionRegion;
+import org.hibernate.cache.infinispan.entity.InfinispanEntityRegion;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
import org.infinispan.eviction.EvictionStrategy;
import junit.framework.TestCase;
@@ -52,32 +57,232 @@
p.setProperty("hibernate.cache.infinispan.query.eviction.strategy",
"FIFO");
p.setProperty("hibernate.cache.infinispan.query.eviction.wake_up_interval",
"3000");
p.setProperty("hibernate.cache.infinispan.query.eviction.max_entries",
"10000");
-
+
InfinispanRegionFactory factory = new InfinispanRegionFactory();
factory.start(null, p);
- assertEquals("entity",
factory.getConfigs().get("entity").getCache());
- assertEquals("entity",
factory.getConfigs().get("collection").getCache());
- assertEquals("timestamp",
factory.getConfigs().get("timestamp").getCache());
-
- assertEquals("person-cache",
factory.getConfigs().get(person).getCache());
- assertEquals(EvictionStrategy.LRU,
factory.getConfigs().get(person).getStrategy());
- assertEquals(2000, factory.getConfigs().get(person).getWakeUpInterval());
- assertEquals(5000, factory.getConfigs().get(person).getMaxEntries());
- assertEquals(60000, factory.getConfigs().get(person).getLifespan());
- assertEquals(30000, factory.getConfigs().get(person).getMaxIdle());
+ assertEquals("entity",
factory.getTypeOverrides().get("entity").getCacheName());
+ assertEquals("entity",
factory.getTypeOverrides().get("collection").getCacheName());
+ assertEquals("timestamp",
factory.getTypeOverrides().get("timestamp").getCacheName());
- assertEquals("person-addresses-cache",
factory.getConfigs().get(addresses).getCache());
- assertEquals(120000, factory.getConfigs().get(addresses).getLifespan());
- assertEquals(60000, factory.getConfigs().get(addresses).getMaxIdle());
-
- assertEquals("my-query-cache",
factory.getConfigs().get("query").getCache());
- assertEquals(EvictionStrategy.FIFO,
factory.getConfigs().get("query").getStrategy());
- assertEquals(3000,
factory.getConfigs().get("query").getWakeUpInterval());
- assertEquals(10000, factory.getConfigs().get("query").getMaxEntries());
+ assertEquals("person-cache",
factory.getTypeOverrides().get(person).getCacheName());
+ assertEquals(EvictionStrategy.LRU,
factory.getTypeOverrides().get(person).getEvictionStrategy());
+ assertEquals(2000,
factory.getTypeOverrides().get(person).getEvictionWakeUpInterval());
+ assertEquals(5000,
factory.getTypeOverrides().get(person).getEvictionMaxEntries());
+ assertEquals(60000,
factory.getTypeOverrides().get(person).getExpirationLifespan());
+ assertEquals(30000,
factory.getTypeOverrides().get(person).getExpirationMaxIdle());
+
+ assertEquals("person-addresses-cache",
factory.getTypeOverrides().get(addresses).getCacheName());
+ assertEquals(120000,
factory.getTypeOverrides().get(addresses).getExpirationLifespan());
+ assertEquals(60000,
factory.getTypeOverrides().get(addresses).getExpirationMaxIdle());
+
+ assertEquals("my-query-cache",
factory.getTypeOverrides().get("query").getCacheName());
+ assertEquals(EvictionStrategy.FIFO,
factory.getTypeOverrides().get("query").getEvictionStrategy());
+ assertEquals(3000,
factory.getTypeOverrides().get("query").getEvictionWakeUpInterval());
+ assertEquals(10000,
factory.getTypeOverrides().get("query").getEvictionMaxEntries());
}
+ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides() {
+ final String person = "com.acme.Person";
+ final String address = "com.acme.Address";
+ final String car = "com.acme.Car";
+ final String addresses = "com.acme.Person.addresses";
+ final String parts = "com.acme.Car.parts";
+ Properties p = new Properties();
+ // First option, cache defined for entity and overrides for generic entity data
type and entity itself.
+ p.setProperty("hibernate.cache.infinispan.com.acme.Person.cfg",
"person-cache");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy",
"LRU");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.wake_up_interval",
"2000");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.max_entries",
"5000 ");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.lifespan",
"60000");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.max_idle",
"30000");
+ p.setProperty("hibernate.cache.infinispan.entity.cfg",
"myentity-cache");
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy",
"FIFO");
+
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval",
"3000");
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries",
"20000");
+ p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.cfg",
"addresses-cache");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.strategy",
"FIFO");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.wake_up_interval",
"2500");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.max_entries",
"5500 ");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.lifespan",
"65000");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.max_idle",
"35000");
+ p.setProperty("hibernate.cache.infinispan.collection.cfg",
"mycollection-cache");
+ p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy",
"LRU");
+
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval",
"3500");
+
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries",
"25000");
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ factory.start(null, p);
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertFalse(factory.getDefinedConfigurations().contains(person));
+ assertNotNull(factory.getTypeOverrides().get(addresses));
+ assertFalse(factory.getDefinedConfigurations().contains(addresses));
+ Cache cache = null;
+ try {
+ InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(person, p, null);
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertTrue(factory.getDefinedConfigurations().contains(person));
+ assertNull(factory.getTypeOverrides().get(address));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
+ assertEquals(2000, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(5000, cacheCfg.getEvictionMaxEntries());
+ assertEquals(60000, cacheCfg.getExpirationLifespan());
+ assertEquals(30000, cacheCfg.getExpirationMaxIdle());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+
+ try {
+ InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(address, p, null);
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertTrue(factory.getDefinedConfigurations().contains(person));
+ assertNull(factory.getTypeOverrides().get(address));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
+ assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(20000, cacheCfg.getEvictionMaxEntries());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+
+ try {
+ InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(car, p, null);
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertTrue(factory.getDefinedConfigurations().contains(person));
+ assertNull(factory.getTypeOverrides().get(address));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
+ assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(20000, cacheCfg.getEvictionMaxEntries());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+
+ try {
+ InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion(addresses, p, null);
+ assertNotNull(factory.getTypeOverrides().get(addresses));
+ assertTrue(factory.getDefinedConfigurations().contains(person));
+ assertNull(factory.getTypeOverrides().get(parts));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
+ assertEquals(2500, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(5500, cacheCfg.getEvictionMaxEntries());
+ assertEquals(65000, cacheCfg.getExpirationLifespan());
+ assertEquals(35000, cacheCfg.getExpirationMaxIdle());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+
+ try {
+ InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion(parts, p, null);
+ assertNotNull(factory.getTypeOverrides().get(addresses));
+ assertTrue(factory.getDefinedConfigurations().contains(addresses));
+ assertNull(factory.getTypeOverrides().get(parts));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
+ assertEquals(3500, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(25000, cacheCfg.getEvictionMaxEntries());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+
+ try {
+ InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion(parts, p, null);
+ assertNotNull(factory.getTypeOverrides().get(addresses));
+ assertTrue(factory.getDefinedConfigurations().contains(addresses));
+ assertNull(factory.getTypeOverrides().get(parts));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
+ assertEquals(3500, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(25000, cacheCfg.getEvictionMaxEntries());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+ }
+
+ public void testBuildEntityCollectionRegionOverridesOnly() {
+ Cache cache = null;
+ Properties p = new Properties();
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy",
"FIFO");
+
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval",
"3000");
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries",
"30000");
+ p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy",
"LRU");
+
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval",
"3500");
+
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries",
"35000");
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ factory.start(null, p);
+ try {
+ InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion("com.acme.Address", p, null);
+ assertNull(factory.getTypeOverrides().get("com.acme.Address"));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
+ assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(30000, cacheCfg.getEvictionMaxEntries());
+ assertEquals(100000, cacheCfg.getExpirationMaxIdle());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+ try {
+ InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion("com.acme.Person.addresses", p, null);
+
assertNull(factory.getTypeOverrides().get("com.acme.Person.addresses"));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
+ assertEquals(3500, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(35000, cacheCfg.getEvictionMaxEntries());
+ assertEquals(100000, cacheCfg.getExpirationMaxIdle());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+ }
+
+ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
+ final String person = "com.acme.Person";
+ Properties p = new Properties();
+ // Third option, no cache defined for entity and overrides for generic entity data
type and entity itself.
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy",
"LRU");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.lifespan",
"60000");
+
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.max_idle",
"30000");
+ p.setProperty("hibernate.cache.infinispan.entity.cfg",
"myentity-cache");
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy",
"FIFO");
+
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval",
"3000");
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries",
"10000");
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ factory.start(null, p);
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertFalse(factory.getDefinedConfigurations().contains(person));
+ Cache cache = null;
+ try {
+ InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(person, p, null);
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertTrue(factory.getDefinedConfigurations().contains(person));
+ cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
+ assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(10000, cacheCfg.getEvictionMaxEntries());
+ assertEquals(60000, cacheCfg.getExpirationLifespan());
+ assertEquals(30000, cacheCfg.getExpirationMaxIdle());
+ } finally {
+ if (cache != null) cache.stop();
+ }
+ }
+
public void testTimestampNoEvictionValidation() {
- // Timestamp cache cannot have evictions configured, so add corresponding test.
+ Properties p = new Properties();
+ p.setProperty("hibernate.cache.infinispan.cfg",
"invalid-infinispan-configs.xml");
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ try {
+ factory.start(null, p);
+ fail("Should have failed saying that invalidation is not allowed for
timestamp caches.");
+ } catch(CacheException ce) {
+ }
}
}
Modified:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java 2009-08-13
04:15:37 UTC (rev 17296)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java 2009-08-13
08:49:58 UTC (rev 17297)
@@ -64,8 +64,7 @@
// Bind a listener to the "local" cache
// Our region factory makes its CacheManager available to us
- CacheManager localManager = ClusterAwareRegionFactory
- .getCacheManager(AbstractDualNodeTestCase.LOCAL);
+ CacheManager localManager =
ClusterAwareRegionFactory.getCacheManager(AbstractDualNodeTestCase.LOCAL);
// Cache localCache = localManager.getCache("entity");
Cache localCustomerCache = localManager.getCache(Customer.class.getName());
Cache localContactCache = localManager.getCache(Contact.class.getName());
@@ -74,7 +73,6 @@
localCustomerCache.addListener(localListener);
localContactCache.addListener(localListener);
localCollectionCache.addListener(localListener);
-
TransactionManager localTM =
DualNodeJtaTransactionManagerImpl.getInstance(AbstractDualNodeTestCase.LOCAL);
// Bind a listener to the "remote" cache
@@ -86,10 +84,8 @@
remoteCustomerCache.addListener(remoteListener);
remoteContactCache.addListener(remoteListener);
remoteCollectionCache.addListener(remoteListener);
+ TransactionManager remoteTM =
DualNodeJtaTransactionManagerImpl.getInstance(AbstractDualNodeTestCase.REMOTE);
- TransactionManager remoteTM = DualNodeJtaTransactionManagerImpl
- .getInstance(AbstractDualNodeTestCase.REMOTE);
-
SessionFactory localFactory = getEnvironment().getSessionFactory();
SessionFactory remoteFactory = getSecondNodeEnvironment().getSessionFactory();
@@ -345,7 +341,7 @@
key = key.substring(index);
log.debug("MyListener[" + name +"] - recording visit to
" + key);
visited.add(key);
- }
+ }
}
}
}
Added:
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml 2009-08-13
08:49:58 UTC (rev 17297)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:infinispan:config:4.0">
+ <global>
+ <transport transportClass =
"org.infinispan.remoting.transport.jgroups.JGroupsTransport"
+ clusterName="infinispan-hibernate-cluster"
distributedSyncTimeout="50000">
+ <!-- Note that the JGroups transport uses sensible defaults if no
configuration property is defined. -->
+ <properties>
+ <!-- TODO: Change to udp.xml once streaming transfer requirement has been
removed. -->
+ <property name="configurationFile"
value="flush-udp.xml"/>
+ </properties>
+ <!-- See the JGroupsTransport javadocs for more flags -->
+ </transport>
+ <serialization
marshallerClass="org.infinispan.marshall.VersionAwareMarshaller"
version="4.0"/>
+ </global>
+
+ <default>
+ <!-- Used to register JMX statistics in any available MBean server -->
+ <jmxStatistics enabled="false"/>
+ </default>
+
+ <!-- Invalid timestamp configuration, cannot be used
+ Optimized for timestamp caching. A clustered timestamp cache
+ is required if query caching is used, even if the query cache
+ itself is configured with CacheMode=LOCAL.
+ -->
+ <namedCache name="timestamp">
+ <clustering mode="INVALIDATION_ASYNC">
+ <stateRetrieval fetchInMemoryState="true"
timeout="20000"/>
+ <async/>
+ </clustering>
+ <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
+ <lazyDeserialization enabled="true"/>
+ <!-- Don't ever evict modification timestamps -->
+ <eviction wakeUpInterval="0" strategy="NONE"/>
+ </namedCache>
+
+</infinispan>
\ No newline at end of file