[infinispan-commits] Infinispan SVN: r2574 - in branches/4.2.x/core/src: main/resources/config-samples and 2 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Fri Oct 22 08:52:58 EDT 2010
Author: manik.surtani at jboss.com
Date: 2010-10-22 08:52:58 -0400 (Fri, 22 Oct 2010)
New Revision: 2574
Added:
branches/4.2.x/core/src/main/java/org/infinispan/config/JAXBUnmarshallable.java
Modified:
branches/4.2.x/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java
branches/4.2.x/core/src/main/java/org/infinispan/config/Configuration.java
branches/4.2.x/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java
branches/4.2.x/core/src/main/resources/config-samples/all.xml
branches/4.2.x/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java
branches/4.2.x/core/src/test/resources/configs/named-cache-test.xml
Log:
ISPN-726 - Default cluster mode and transaction mgr lookup should be used if not specified in the <clustering /> and <transaction /> tags
Modified: branches/4.2.x/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java 2010-10-22 11:54:45 UTC (rev 2573)
+++ branches/4.2.x/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java 2010-10-22 12:52:58 UTC (rev 2574)
@@ -44,7 +44,7 @@
* @since 4.0
*/
@Scope(Scopes.NAMED_CACHE)
-public abstract class AbstractConfigurationBean implements CloneableConfigurationComponent {
+public abstract class AbstractConfigurationBean implements CloneableConfigurationComponent, JAXBUnmarshallable {
private static final long serialVersionUID = 4879873994727821938L;
protected static final TypedProperties EMPTY_PROPERTIES = new TypedProperties();
protected transient Log log = LogFactory.getLog(getClass());
@@ -120,4 +120,9 @@
public CloneableConfigurationComponent clone() throws CloneNotSupportedException {
return (AbstractConfigurationBean) super.clone();
}
+
+ @Override
+ public void willUnmarshall() {
+ // default no-op
+ }
}
Modified: branches/4.2.x/core/src/main/java/org/infinispan/config/Configuration.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/config/Configuration.java 2010-10-22 11:54:45 UTC (rev 2573)
+++ branches/4.2.x/core/src/main/java/org/infinispan/config/Configuration.java 2010-10-22 12:52:58 UTC (rev 2574)
@@ -49,6 +49,7 @@
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.infinispan.config.Configuration.CacheMode.*;
/**
* Encapsulates the configuration of a Cache. Configures the default cache which can be retrieved
@@ -105,7 +106,7 @@
private UnsafeType unsafe = new UnsafeType();
@XmlElement
- private ClusteringType clustering = new ClusteringType();
+ private ClusteringType clustering = new ClusteringType(LOCAL);
@XmlElement
private JmxStatistics jmxStatistics = new JmxStatistics();
@@ -418,7 +419,7 @@
clustering.setMode(CacheMode.valueOf(uc(cacheMode)));
if (clustering.mode == null) {
log.warn("Unknown cache mode '" + cacheMode + "', using defaults.");
- clustering.setMode(CacheMode.LOCAL);
+ clustering.setMode(LOCAL);
}
}
@@ -1222,6 +1223,13 @@
result = 31 * result + (useEagerLocking != null ? useEagerLocking.hashCode() : 0);
return result;
}
+
+ @Override
+ public void willUnmarshall() {
+ // set the REAL default now!!
+ // make sure we use the setter so that the change is registered for merging
+ setTransactionManagerLookupClass(GenericTransactionManagerLookup.class.getName());
+ }
}
/**
*
@@ -1337,7 +1345,7 @@
@XmlTransient
@ConfigurationDocRef(bean=Configuration.class,targetElement="setCacheMode")
- protected CacheMode mode = CacheMode.LOCAL;
+ protected CacheMode mode;
@XmlElement
protected SyncType sync = new SyncType();
@@ -1354,6 +1362,14 @@
@XmlElement
protected HashType hash = new HashType();
+ public ClusteringType(CacheMode mode) {
+ this.mode = mode;
+ }
+
+ public ClusteringType() {
+ this.mode = DIST_SYNC;
+ }
+
public void setMode(CacheMode mode) {
testImmutability("mode");
this.mode = mode;
@@ -1412,6 +1428,13 @@
result = 31 * result + (hash != null ? hash.hashCode() : 0);
return result;
}
+
+ @Override
+ public void willUnmarshall() {
+ // set the REAL default now!!
+ // must use the setter to ensure the change is registered on the bean
+ setMode(DIST_SYNC);
+ }
}
public static class ClusteringTypeAdapter extends XmlAdapter<ClusteringType, ClusteringType> {
@@ -1427,19 +1450,19 @@
String mode = ct.stringMode.toLowerCase();
if(mode.startsWith("r")){
if(ct.isSynchronous())
- ct.setMode(CacheMode.REPL_SYNC);
+ ct.setMode(REPL_SYNC);
else
- ct.setMode(CacheMode.REPL_ASYNC);
+ ct.setMode(REPL_ASYNC);
} else if (mode.startsWith("i")){
if(ct.isSynchronous())
- ct.setMode(CacheMode.INVALIDATION_SYNC);
+ ct.setMode(INVALIDATION_SYNC);
else
- ct.setMode(CacheMode.INVALIDATION_ASYNC);
+ ct.setMode(INVALIDATION_ASYNC);
} else if (mode.startsWith("d")){
if(ct.isSynchronous())
- ct.setMode(CacheMode.DIST_SYNC);
+ ct.setMode(DIST_SYNC);
else
- ct.setMode(CacheMode.DIST_ASYNC);
+ ct.setMode(DIST_ASYNC);
}
else {
throw new ConfigurationException("Invalid clustering mode" + ct.stringMode);
Modified: branches/4.2.x/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java 2010-10-22 11:54:45 UTC (rev 2573)
+++ branches/4.2.x/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java 2010-10-22 12:52:58 UTC (rev 2574)
@@ -69,7 +69,7 @@
@XmlRootElement(name = "infinispan")
@XmlAccessorType(XmlAccessType.FIELD)
@ConfigurationDoc(name="infinispan")
-public class InfinispanConfiguration implements XmlConfigurationParser {
+public class InfinispanConfiguration implements XmlConfigurationParser, JAXBUnmarshallable {
private static final Log log = LogFactory.getLog(InfinispanConfiguration.class);
@@ -243,6 +243,16 @@
source = replaceProperties(config, nf);
}
+ u.setListener(new Unmarshaller.Listener() {
+ @Override
+ public void beforeUnmarshal(Object target, Object parent) {
+ if (target instanceof JAXBUnmarshallable) {
+ // notify the bean that it is about to be unmarshalled
+ ((JAXBUnmarshallable) target).willUnmarshall();
+ }
+ }
+ });
+
InfinispanConfiguration ic = (InfinispanConfiguration) u.unmarshal(source);
ic.accept(cbv);
return ic;
@@ -402,4 +412,9 @@
}
return map;
}
+
+ @Override
+ public void willUnmarshall() {
+ // no-op
+ }
}
Added: branches/4.2.x/core/src/main/java/org/infinispan/config/JAXBUnmarshallable.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/config/JAXBUnmarshallable.java (rev 0)
+++ branches/4.2.x/core/src/main/java/org/infinispan/config/JAXBUnmarshallable.java 2010-10-22 12:52:58 UTC (rev 2574)
@@ -0,0 +1,14 @@
+package org.infinispan.config;
+
+/**
+ * A mechanism to notify an XML element that the JAXB parser has willUnmarshall it
+ *
+ * @author Manik Surtani
+ * @version 4.2
+ */
+public interface JAXBUnmarshallable {
+ /**
+ * Indicates that this element is about to be unmarshalled from the XML source that was processed.
+ */
+ public void willUnmarshall();
+}
Modified: branches/4.2.x/core/src/main/resources/config-samples/all.xml
===================================================================
--- branches/4.2.x/core/src/main/resources/config-samples/all.xml 2010-10-22 11:54:45 UTC (rev 2573)
+++ branches/4.2.x/core/src/main/resources/config-samples/all.xml 2010-10-22 12:52:58 UTC (rev 2574)
@@ -189,7 +189,7 @@
</clustering>
</namedCache>
- <namedCache name="withReplicatinQueue">
+ <namedCache name="withReplicationQueue">
<clustering>
<async useReplQueue="true" replQueueInterval="100" replQueueMaxElements="200"/>
</clustering>
Modified: branches/4.2.x/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java
===================================================================
--- branches/4.2.x/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java 2010-10-22 11:54:45 UTC (rev 2573)
+++ branches/4.2.x/core/src/test/java/org/infinispan/config/parsing/XmlFileParsingTest.java 2010-10-22 12:52:58 UTC (rev 2574)
@@ -1,5 +1,6 @@
package org.infinispan.config.parsing;
+import org.infinispan.Cache;
import org.infinispan.Version;
import org.infinispan.config.CacheLoaderManagerConfig;
import org.infinispan.config.Configuration;
@@ -14,6 +15,7 @@
import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
import org.infinispan.test.AbstractInfinispanTest;
import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.util.concurrent.IsolationLevel;
import org.testng.annotations.Test;
@@ -121,7 +123,6 @@
assert def.getIsolationLevel() == IsolationLevel.REPEATABLE_READ;
}
-
private void testNamedCacheFile(XmlConfigurationParser parser) throws IOException {
GlobalConfiguration gc = parser.parseGlobalConfiguration();
@@ -160,11 +161,15 @@
Configuration c = namedCaches.get("transactional");
+ assert !c.getCacheMode().isClustered();
assert c.getTransactionManagerLookupClass().equals("org.infinispan.transaction.lookup.GenericTransactionManagerLookup");
assert c.isUseEagerLocking();
assert c.isEagerLockSingleNode();
assert !c.isSyncRollbackPhase();
+ c = namedCaches.get("transactional2");
+ assert c.getTransactionManagerLookupClass().equals("org.something.Lookup");
+
c = namedCaches.get("syncRepl");
assert c.getCacheMode() == Configuration.CacheMode.REPL_SYNC;
@@ -217,7 +222,7 @@
assert csConf.isPurgeOnStartup();
assert csConf.getLocation().equals("/tmp/FileCacheStore-Location");
assert csConf.getSingletonStoreConfig().getPushStateTimeout() == 20000;
- assert csConf.getSingletonStoreConfig().isPushStateWhenCoordinator() == true;
+ assert csConf.getSingletonStoreConfig().isPushStateWhenCoordinator();
assert csConf.getAsyncStoreConfig().getThreadPoolSize() == 5;
assert csConf.getAsyncStoreConfig().getFlushLockTimeout() == 15000;
assert csConf.getAsyncStoreConfig().isEnabled();
@@ -251,6 +256,7 @@
c = namedCaches.get("withDeadlockDetection");
assert c.isEnableDeadlockDetection();
assert c.getDeadlockDetectionSpinDuration() == 1221;
+ assert c.getCacheMode() == Configuration.CacheMode.DIST_SYNC;
}
private void testConfigurationMerging(XmlConfigurationParser parser) throws IOException {
@@ -329,6 +335,13 @@
assert !c.isExposeJmxStatistics();
c = defaultCfg.clone();
+ c.applyOverrides(namedCaches.get("withReplicationQueue"));
+ assert c.getCacheMode() == Configuration.CacheMode.DIST_SYNC;
+ assert c.isUseReplQueue();
+ assert c.getReplQueueInterval() == 100;
+ assert c.getReplQueueMaxElements() == 200;
+
+ c = defaultCfg.clone();
Configuration configurationWL = namedCaches.get("withLoader");
configurationWL.getCacheLoaderManagerConfig().setShared(true);
FileCacheStoreConfig clc = (FileCacheStoreConfig)configurationWL.getCacheLoaderManagerConfig().getFirstCacheLoaderConfig();
Modified: branches/4.2.x/core/src/test/resources/configs/named-cache-test.xml
===================================================================
--- branches/4.2.x/core/src/test/resources/configs/named-cache-test.xml 2010-10-22 11:54:45 UTC (rev 2573)
+++ branches/4.2.x/core/src/test/resources/configs/named-cache-test.xml 2010-10-22 12:52:58 UTC (rev 2574)
@@ -54,9 +54,14 @@
</default>
<namedCache name="transactional">
- <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" useEagerLocking="true" eagerLockSingleNode="true"/>
+ <transaction useEagerLocking="true" eagerLockSingleNode="true"/>
</namedCache>
+ <namedCache name="transactional2">
+ <transaction transactionManagerLookupClass="org.something.Lookup"/>
+ </namedCache>
+
+
<namedCache name="syncRepl">
<clustering mode="repl">
<stateRetrieval fetchInMemoryState="false"/>
@@ -166,6 +171,11 @@
</loaders>
</namedCache>
+ <namedCache name="withReplicationQueue">
+ <clustering>
+ <async useReplQueue="true" replQueueInterval="100" replQueueMaxElements="200"/>
+ </clustering>
+ </namedCache>
<namedCache name="cacheWithCustomInterceptors">
More information about the infinispan-commits
mailing list