[infinispan-commits] Infinispan SVN: r667 - in trunk/core/src: test/resources/configs and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Aug 13 07:02:02 EDT 2009


Author: vblagojevic at jboss.com
Date: 2009-08-13 07:02:01 -0400 (Thu, 13 Aug 2009)
New Revision: 667

Modified:
   trunk/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java
   trunk/core/src/main/java/org/infinispan/config/Configuration.java
   trunk/core/src/test/resources/configs/named-cache-test.xml
Log:
remove constraint on cache mode
handle cache mode as it was handled previously

Modified: trunk/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java	2009-08-13 11:00:17 UTC (rev 666)
+++ trunk/core/src/main/java/org/infinispan/config/AbstractConfigurationBean.java	2009-08-13 11:02:01 UTC (rev 667)
@@ -194,9 +194,12 @@
                field.setAccessible(true);
                fieldValueOverrides = (AbstractConfigurationBean) field.get(overrides);
                fieldValueThis = (AbstractConfigurationBean) field.get(this);
-               if(fieldValueOverrides != null && fieldValueThis!=null){
+               if (fieldValueThis == null && fieldValueOverrides != null){
+                  field.set(this, fieldValueOverrides);
+               }
+               else if(fieldValueOverrides != null && fieldValueThis!=null){
                   fieldValueThis.applyOverrides(fieldValueOverrides);
-               }
+               } 
             } catch (Exception e) {
                log.warn("Could not apply override for field " + field + " in class " +overrides,e);
             }

Modified: trunk/core/src/main/java/org/infinispan/config/Configuration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/Configuration.java	2009-08-13 11:00:17 UTC (rev 666)
+++ trunk/core/src/main/java/org/infinispan/config/Configuration.java	2009-08-13 11:02:01 UTC (rev 667)
@@ -36,6 +36,9 @@
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -852,12 +855,16 @@
       }
    } 
    
+   @XmlJavaTypeAdapter(ClusteringTypeAdapter.class)
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(propOrder={})
    private static class ClusteringType extends AbstractNamedCacheConfigurationBean {
       
       /** The serialVersionUID */
       private static final long serialVersionUID = 4048135465543498430L;
+      
+      @XmlAttribute(name="mode")
+      private String stringMode;
 
       @XmlTransient
       private CacheMode mode = CacheMode.LOCAL;
@@ -872,17 +879,21 @@
       private L1Type l1 = new L1Type();
       
       @XmlElement
-      private AsyncType async = new AsyncType();
+      private AsyncType async = new AsyncType(false);
       
       @XmlElement
       private HashType hash = new HashType();
 
-      @XmlAttribute
+      
       public void setMode(CacheMode mode) {
          testImmutability("mode");
          this.mode = mode;
       }
-
+      
+      public boolean isSynchronous() {
+         return !async.readFromXml;
+      }
+      
       @Override
       public ClusteringType clone() throws CloneNotSupportedException {
          ClusteringType dolly = (ClusteringType) super.clone();
@@ -895,9 +906,47 @@
       }
    }
    
+   private static class ClusteringTypeAdapter extends XmlAdapter<ClusteringType, ClusteringType> {
+
+      @Override
+      public ClusteringType marshal(ClusteringType ct) throws Exception {
+         return ct;        
+      }
+
+      @Override
+      public ClusteringType unmarshal(ClusteringType ct) throws Exception {
+         if(ct.stringMode != null){
+            String mode = ct.stringMode.toLowerCase();
+            if(mode.startsWith("r")){
+               if(ct.isSynchronous())
+                  ct.setMode(CacheMode.REPL_SYNC);
+               else 
+                  ct.setMode(CacheMode.REPL_ASYNC);
+            } else if (mode.startsWith("i")){
+               if(ct.isSynchronous())
+                  ct.setMode(CacheMode.INVALIDATION_SYNC);
+               else 
+                  ct.setMode(CacheMode.INVALIDATION_ASYNC);
+            } else if (mode.startsWith("d")){
+               if(ct.isSynchronous())
+                  ct.setMode(CacheMode.DIST_SYNC);
+               else 
+                  ct.setMode(CacheMode.DIST_ASYNC);
+            }
+            else {
+               throw new ConfigurationException("Invalid clustering mode" + ct.stringMode);
+            }
+         }
+         return ct;
+      }
+   }
+   
    @XmlAccessorType(XmlAccessType.PROPERTY)
    private static class AsyncType extends AbstractNamedCacheConfigurationBean {
 
+      @XmlTransient
+      private boolean readFromXml = false;
+      
       /** The serialVersionUID */
       private static final long serialVersionUID = -7726319188826197399L;
 
@@ -909,6 +958,16 @@
       
       private Boolean asyncMarshalling=true;
       
+      
+      private AsyncType(boolean readFromXml) {
+         super();
+         this.readFromXml = readFromXml;
+      }
+      
+      private AsyncType(){
+         this(true);
+      }
+
       @XmlAttribute
       public void setUseReplQueue(Boolean useReplQueue) {
          testImmutability("useReplQueue");

Modified: trunk/core/src/test/resources/configs/named-cache-test.xml
===================================================================
--- trunk/core/src/test/resources/configs/named-cache-test.xml	2009-08-13 11:00:17 UTC (rev 666)
+++ trunk/core/src/test/resources/configs/named-cache-test.xml	2009-08-13 11:02:01 UTC (rev 667)
@@ -55,21 +55,21 @@
    </namedCache>
 
    <namedCache name="syncRepl">
-      <clustering mode="REPL_SYNC">
+      <clustering mode="repl">
          <stateRetrieval fetchInMemoryState="false"/>
          <sync replTimeout="15000"/>
       </clustering>
    </namedCache>
 
    <namedCache name="asyncRepl">
-      <clustering mode="REPL_ASYNC">
+      <clustering mode="repl">
          <stateRetrieval fetchInMemoryState="false"/>
          <async asyncMarshalling="false"/>
       </clustering>
    </namedCache>
 
    <namedCache name="asyncReplQueue">
-      <clustering mode="REPL_ASYNC">
+      <clustering mode="repl">
          <stateRetrieval fetchInMemoryState="false"/>
          <async useReplQueue="true" replQueueInterval="1234" replQueueMaxElements="100"/>
       </clustering>
@@ -77,7 +77,7 @@
 
    <namedCache name="txSyncRepl">
       <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/>
-      <clustering mode="REPL_SYNC">
+      <clustering mode="repl">
          <stateRetrieval fetchInMemoryState="false"/>
          <sync replTimeout="15000"/>
       </clustering>
@@ -112,7 +112,7 @@
    </namedCache>
 
    <namedCache name="dist">
-      <clustering mode="DIST_SYNC">
+      <clustering mode="distribution">
          <sync/>
          <hash numOwners="3" rehashWait="120000"/>
          <l1 enabled="true" lifespan="600000"/>



More information about the infinispan-commits mailing list