[exo-jcr-commits] exo-jcr SVN: r2223 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Apr 8 06:03:01 EDT 2010


Author: areshetnyak
Date: 2010-04-08 06:03:00 -0400 (Thu, 08 Apr 2010)
New Revision: 2223

Added:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java
Removed:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java
Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java
   jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
Log:
EXOJCR-545 : Add implementation use the ExpitationAlgorithm

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java	2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java	2010-04-08 10:03:00 UTC (rev 2223)
@@ -18,6 +18,20 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
 
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.AddToListContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutKeyValueContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutObjectContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveFromListContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveKeyContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveNodeContainer;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 import org.jboss.cache.Cache;
@@ -30,18 +44,9 @@
 import org.jboss.cache.NodeNotExistsException;
 import org.jboss.cache.Region;
 import org.jboss.cache.config.Configuration;
-import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
 import org.jboss.cache.interceptors.base.CommandInterceptor;
 import org.jgroups.Address;
 
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.transaction.TransactionManager;
-
 /**
  * Decorator over the JBossCache that stores changes in buffer, then sorts and applies to JBossCache.
  * 
@@ -52,12 +57,12 @@
 @SuppressWarnings("unchecked")
 public class BufferedJBossCache implements Cache<Serializable, Object>
 {
-   //   private final Log log = ExoLogger.getLogger("exo.jcr.component.core.BufferedJbossCache");
-
    /**
     * Parent cache.
     */
    private final Cache<Serializable, Object> parentCache;
+   
+   private final ChangesContainerFactory changesContatinerFactory;
 
    private final ThreadLocal<CompressedChangesBuffer> changesList = new ThreadLocal<CompressedChangesBuffer>();
 
@@ -66,10 +71,11 @@
    protected static final Log LOG =
       ExoLogger.getLogger("org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache");
 
-   public BufferedJBossCache(Cache<Serializable, Object> parentCache)
+   public BufferedJBossCache(Cache<Serializable, Object> parentCache, ChangesContainerFactory changesContatinerFactory)
    {
       super();
       this.parentCache = parentCache;
+      this.changesContatinerFactory = changesContatinerFactory;
    }
 
    /**
@@ -451,8 +457,8 @@
    public void put(Fqn fqn, Map<? extends Serializable, ? extends Object> data)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new PutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local
-         .get()));
+      changesContainer.add(changesContatinerFactory.createPutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local
+               .get()));
    }
 
    /* (non-Javadoc)
@@ -461,8 +467,8 @@
    public Object put(Fqn fqn, Serializable key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
-         local.get()));
+      changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+               local.get()));
 
       return parentCache.get(fqn, key);
    }
@@ -474,7 +480,7 @@
       // take Object from buffer for first 
       Object prevObject = getObjectFromChangesContainer(changesContainer, fqn, key);
 
-      changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+      changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
          local.get()));
 
       if (prevObject != null)
@@ -496,9 +502,9 @@
          if (change.getChangesType().equals(ChangesType.PUT_KEY) && change.getFqn().equals(fqn))
          {
             PutKeyValueContainer cont = ((PutKeyValueContainer)change);
-            if (cont.key.equals(key))
+            if (cont.getKey().equals(key))
             {
-               object = ((PutKeyValueContainer)change).value;
+               object = ((PutKeyValueContainer)change).getValue();
             }
          }
       }
@@ -537,7 +543,7 @@
    public Object remove(Fqn fqn, Serializable key)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new RemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
+      changesContainer.add(changesContatinerFactory.createRemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
          .get()));
       return parentCache.get(fqn, key);
    }
@@ -580,7 +586,7 @@
    public boolean removeNode(Fqn fqn)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new RemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(changesContatinerFactory.createRemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get()));
       return true;
    }
 
@@ -648,7 +654,7 @@
    public void addToList(Fqn fqn, String key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+      changesContainer.add(changesContatinerFactory.createAddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
          local.get()));
    }
 
@@ -662,266 +668,12 @@
    public void removeFromList(Fqn fqn, String key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(new RemoveFromListContainer(fqn, key, value, parentCache,
+      changesContainer.add(changesContatinerFactory.createRemoveFromListContainer(fqn, key, value, parentCache,
          changesContainer.getHistoryIndex(), local.get()));
    }
 
    public static enum ChangesType {
       REMOVE, REMOVE_KEY, PUT, PUT_KEY, PUT_TO_LIST;
    }
-   
-   protected static void putMap(Fqn fqn, Map<? extends Serializable, ? extends Object> data, Cache<Serializable, Object> cache, boolean localMode) 
-   {
-      cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
-      cache.put(fqn, data);
-   }
-   
-   protected static void putObject(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache, boolean localMode) 
-   {
-      cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
-      cache.put(fqn, key, value);
-   }
 
-   /**
-    * Container for changes
-    */
-   public static abstract class ChangesContainer implements Comparable<ChangesContainer>
-   {
-      protected final Fqn fqn;
-
-      protected final ChangesType changesType;
-
-      protected final Cache<Serializable, Object> cache;
-
-      protected final int historicalIndex;
-
-      protected final boolean localMode;
-
-      public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
-         boolean localMode)
-      {
-         super();
-         this.fqn = fqn;
-         this.changesType = changesType;
-         this.cache = cache;
-         this.historicalIndex = historicalIndex;
-         this.localMode = localMode;
-      }
-
-      /**
-       * @return the fqn
-       */
-      public Fqn getFqn()
-      {
-         return fqn;
-      }
-
-      /**
-       * @return the index of change in original sequence
-       */
-      public int getHistoricalIndex()
-      {
-         return historicalIndex;
-      }
-
-      /**
-       * @return the changesType
-       */
-      public ChangesType getChangesType()
-      {
-         return changesType;
-      }
-
-      /* (non-Javadoc)
-       * @see java.lang.Object#toString()
-       */
-      @Override
-      public String toString()
-      {
-         return fqn + " type=" + changesType + " historyIndex=" + historicalIndex;
-      }
-
-      public int compareTo(ChangesContainer o)
-      {
-         int result = fqn.compareTo(o.getFqn());
-         return result == 0 ? historicalIndex - o.getHistoricalIndex() : result;
-      }
-
-      protected void setCacheLocalMode()
-      {
-         cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
-      }
-
-      public abstract void apply();
-   }
-
-   /**
-    * Put object container;
-    */
-   public static class PutObjectContainer extends ChangesContainer
-   {
-      private final Map<? extends Serializable, ? extends Object> data;
-
-      public PutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
-         Cache<Serializable, Object> cache, int historicalIndex, boolean local)
-      {
-         super(fqn, ChangesType.PUT, cache, historicalIndex, local);
-
-         this.data = data;
-      }
-
-      @Override
-      public void apply()
-      {
-         putMap(fqn, data, cache, localMode);
-      }
-   }
-
-   /**
-    * Put  container.
-    */
-   public static class PutKeyValueContainer extends ChangesContainer
-   {
-      private final Serializable key;
-
-      private final Object value;
-
-      public PutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
-         int historicalIndex, boolean local)
-      {
-         super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
-         this.key = key;
-         this.value = value;
-      }
-
-      @Override
-      public void apply()
-      {
-         putObject(fqn, key, value, cache, localMode);
-      }
-   }
-
-   /**
-    * It tries to get Set by given key. If it is Set then adds new value and puts new set back.
-    * If null found, then new Set created (ordinary cache does).
-    */
-   public static class AddToListContainer extends ChangesContainer
-   {
-      private final Serializable key;
-
-      private final Object value;
-
-      public AddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
-         int historicalIndex, boolean local)
-      {
-         super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
-         this.key = key;
-         this.value = value;
-      }
-
-      @Override
-      public void apply()
-      {
-         // force writeLock on next read
-         cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
-         // object found by FQN and key;
-         Object existingObject = cache.get(getFqn(), key);
-         Set<Object> newSet = new HashSet<Object>();
-         // if set found of null, perform add
-         if (existingObject instanceof Set || existingObject == null)
-         {
-            // set found
-            if (existingObject instanceof Set)
-            {
-               newSet.addAll((Set<Object>)existingObject);
-            }
-            newSet.add(value);
-            
-            putObject(fqn, key, newSet, cache, localMode);
-         }
-         else
-         {
-            LOG.error("Unexpected object found by FQN:" + getFqn() + " and key:" + key + ". Expected Set, but found:"
-               + existingObject.getClass().getName());
-         }
-      }
-   }
-
-   /**
-    * It tries to get set by given key. If it is set then removes value and puts new modified set back.
-    */
-   public static class RemoveFromListContainer extends ChangesContainer
-   {
-      private final Serializable key;
-
-      private final Object value;
-
-      public RemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
-         int historicalIndex, boolean local)
-      {
-         super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
-         this.key = key;
-         this.value = value;
-      }
-
-      @Override
-      public void apply()
-      {
-         // force writeLock on next read
-         cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
-         // object found by FQN and key;
-         setCacheLocalMode();
-         Object existingObject = cache.get(getFqn(), key);
-         // if found value is really set! add to it.
-         if (existingObject instanceof Set)
-         {
-            Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
-            newSet.remove(value);
-            
-            putObject(fqn, key, newSet, cache, localMode);
-         }
-      }
-   }
-
-   /**
-    * Remove container.
-    */
-   public static class RemoveKeyContainer extends ChangesContainer
-   {
-      private final Serializable key;
-
-      public RemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex,
-         boolean local)
-      {
-         super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
-         this.key = key;
-      }
-
-      @Override
-      public void apply()
-      {
-         setCacheLocalMode();
-         cache.remove(fqn, key);
-      }
-
-   }
-
-   /**
-    * Remove container.
-    */
-   public static class RemoveNodeContainer extends ChangesContainer
-   {
-
-      public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
-      {
-         super(fqn, ChangesType.REMOVE, cache, historicalIndex, local);
-      }
-
-      @Override
-      public void apply()
-      {
-         setCacheLocalMode();
-         cache.removeNode(fqn);
-      }
-   }
 }

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java	2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java	2010-04-08 10:03:00 UTC (rev 2223)
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
-
-/**
- * Created by The eXo Platform SAS.
- * 
- * <br/>Date: 2010
- *
- * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
- * @version $Id$
- */
-public class BufferedJBossCacheExp extends BufferedJBossCache
-{
-   /**
-    * The expiration timeout.  
-    */
-   public final static long DEFAULT_EXPIRATION_TIMEOUT = 900000; // 15 minutes. 
-   
-   public final long expirationTimeOut;
-
-   public BufferedJBossCacheExp(Cache<Serializable, Object> parentCache, long expirationTimeOut)
-   {
-      super(parentCache);
-      this.expirationTimeOut = expirationTimeOut;
-   }
-   
-   public BufferedJBossCacheExp(Cache<Serializable, Object> parentCache)
-   {
-      super(parentCache);
-      this.expirationTimeOut = DEFAULT_EXPIRATION_TIMEOUT;
-   }
-   
-   protected static void putMap(Fqn fqn, Map<? extends Serializable, ? extends Object> data, Cache<Serializable, Object> cache, boolean localMode) 
-   {
-      putExpiration(fqn, cache, localMode);
-      
-      cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
-      cache.put(fqn, data);
-      
-      cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
-      cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + DEFAULT_EXPIRATION_TIMEOUT));
-   }
-   
-   protected static void putObject(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache, boolean localMode) 
-   {
-      cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
-      cache.put(fqn, key, value);
-   }
-   
-   public static void putExpiration(Fqn efqn, Cache<Serializable, Object> cache, boolean localMode)
-   {
-      for (int i = 2; i <= efqn.size(); i++)
-      {
-         Fqn pfqn = efqn.getSubFqn(0, i);
-         cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
-         cache.put(pfqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + DEFAULT_EXPIRATION_TIMEOUT));
-      }
-   }
-   
-   
-
-}

Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java	2010-04-08 10:03:00 UTC (rev 2223)
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ *  ChahgesContainerExpirationFactory this special factory to ExpirationAlgorithm  
+ * 
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id$
+ */
+public class ChangesContainerExpirationFactory
+   extends ChangesContainerFactory
+{
+   
+   /**
+   * The expiration timeout.  
+   */
+   public final static long DEFAULT_EXPIRATION_TIMEOUT = 900000; // 15 minutes. 
+
+   public static long expirationTimeOut;
+
+   public ChangesContainerExpirationFactory(long expirationTimeOut)
+   {
+      this.expirationTimeOut = expirationTimeOut;
+   }
+   
+   public ChangesContainerExpirationFactory()
+   {
+      this.expirationTimeOut = DEFAULT_EXPIRATION_TIMEOUT;
+   }
+   
+   /**
+    * Put object container;
+    */
+   public static class PutObjectContainerExpiration extends PutObjectContainer
+   {
+
+      public PutObjectContainerExpiration(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+         Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+      {
+         super(fqn, data, cache, historicalIndex, local);
+      }
+
+      @Override
+      public void apply()
+      {
+         setCacheLocalMode();
+         cache.put(fqn, data);
+
+         setCacheLocalMode();
+         cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+      }
+   }
+
+   /**
+    * Put  container.
+    */
+   public static class PutKeyValueContainerExpiration extends PutKeyValueContainer
+   {
+
+      public PutKeyValueContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local)
+      {
+         super(fqn, key, value, cache, historicalIndex, local);
+      }
+
+      @Override
+      public void apply()
+      {
+         setCacheLocalMode();
+         cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+         
+         setCacheLocalMode();
+         cache.put(fqn, key, value);
+      }
+
+      public Serializable getKey()
+      {
+         return key;
+      }
+
+      public Object getValue()
+      {
+         return value;
+      }
+      
+   }
+
+   /**
+    * It tries to get Set by given key. If it is Set then adds new value and puts new set back.
+    * If null found, then new Set created (ordinary cache does).
+    */
+   public static class AddToListContainerExpiration extends AddToListContainer
+   {
+
+      public AddToListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local)
+      {
+         super(fqn, key, value, cache, historicalIndex, local);
+      }
+
+      @Override
+      public void apply()
+      {
+         // force writeLock on next read
+         cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+         // object found by FQN and key;
+         Object existingObject = cache.get(getFqn(), key);
+         Set<Object> newSet = new HashSet<Object>();
+         // if set found of null, perform add
+         if (existingObject instanceof Set || existingObject == null)
+         {
+            // set found
+            if (existingObject instanceof Set)
+            {
+               newSet.addAll((Set<Object>)existingObject);
+            }
+            newSet.add(value);
+            
+            setCacheLocalMode();
+            cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+            
+            setCacheLocalMode();
+            cache.put(fqn, key, newSet);
+         }
+         else
+         {
+            LOG.error("Unexpected object found by FQN:" + getFqn() + " and key:" + key + ". Expected Set, but found:"
+               + existingObject.getClass().getName());
+         }
+      }
+   }
+
+   /**
+    * It tries to get set by given key. If it is set then removes value and puts new modified set back.
+    */
+   public static class RemoveFromListContainerExpiration extends RemoveFromListContainer
+   {
+
+      public RemoveFromListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local)
+      {
+         super(fqn, key, value, cache, historicalIndex, local);
+      }
+
+      @Override
+      public void apply()
+      {
+         // force writeLock on next read
+         cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+         // object found by FQN and key;
+         setCacheLocalMode();
+         Object existingObject = cache.get(getFqn(), key);
+         // if found value is really set! add to it.
+         if (existingObject instanceof Set)
+         {
+            Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
+            newSet.remove(value);
+            
+            setCacheLocalMode();
+            cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+            
+            setCacheLocalMode();
+            cache.put(fqn, key, newSet);
+         }
+      }
+   }
+   
+   public ChangesContainer createPutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+            Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+   {
+     return new PutObjectContainerExpiration(fqn, data, cache, historicalIndex, local);  
+   }
+   
+   public ChangesContainer createPutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+            int historicalIndex, boolean local)
+   {
+     return new PutKeyValueContainerExpiration(fqn, key, value, cache, historicalIndex, local);  
+   }
+   
+   public ChangesContainer createAddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+            int historicalIndex, boolean local)
+   {
+     return new AddToListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+   }
+   
+   public ChangesContainer createRemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+            int historicalIndex, boolean local)
+   {
+     return new RemoveFromListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+   }
+
+}


Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java	2010-04-08 10:03:00 UTC (rev 2223)
@@ -0,0 +1,335 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesType;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id$
+ */
+public class ChangesContainerFactory
+{
+   protected static final Log LOG =
+      ExoLogger.getLogger("org.exoplatform." +
+      		"services.jcr.impl.dataflow.persistent.jbosscache.ChangesContatinerFactory");
+   
+   /**
+    * Container for changes
+    */
+   public static abstract class ChangesContainer implements Comparable<ChangesContainer>
+   {
+      protected final Fqn fqn;
+
+      protected final ChangesType changesType;
+
+      protected final Cache<Serializable, Object> cache;
+
+      protected final int historicalIndex;
+
+      protected final boolean localMode;
+
+      public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
+         boolean localMode)
+      {
+         super();
+         this.fqn = fqn;
+         this.changesType = changesType;
+         this.cache = cache;
+         this.historicalIndex = historicalIndex;
+         this.localMode = localMode;
+      }
+
+      /**
+       * @return the fqn
+       */
+      public Fqn getFqn()
+      {
+         return fqn;
+      }
+
+      /**
+       * @return the index of change in original sequence
+       */
+      public int getHistoricalIndex()
+      {
+         return historicalIndex;
+      }
+
+      /**
+       * @return the changesType
+       */
+      public ChangesType getChangesType()
+      {
+         return changesType;
+      }
+
+      /* (non-Javadoc)
+       * @see java.lang.Object#toString()
+       */
+      @Override
+      public String toString()
+      {
+         return fqn + " type=" + changesType + " historyIndex=" + historicalIndex;
+      }
+
+      public int compareTo(ChangesContainer o)
+      {
+         int result = fqn.compareTo(o.getFqn());
+         return result == 0 ? historicalIndex - o.getHistoricalIndex() : result;
+      }
+
+      protected void setCacheLocalMode()
+      {
+         cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+      }
+
+      public abstract void apply();
+   }
+
+   /**
+    * Put object container;
+    */
+   public static class PutObjectContainer extends ChangesContainer
+   {
+      protected final Map<? extends Serializable, ? extends Object> data;
+
+      public PutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+         Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+      {
+         super(fqn, ChangesType.PUT, cache, historicalIndex, local);
+
+         this.data = data;
+      }
+
+      @Override
+      public void apply()
+      {
+         setCacheLocalMode();
+         cache.put(fqn, data);
+      }
+   }
+
+   /**
+    * Put  container.
+    */
+   public static class PutKeyValueContainer extends ChangesContainer
+   {
+      protected final Serializable key;
+
+      protected final Object value;
+
+      public PutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local)
+      {
+         super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
+         this.key = key;
+         this.value = value;
+      }
+
+      @Override
+      public void apply()
+      {
+         setCacheLocalMode();
+         cache.put(fqn, key, value);
+      }
+
+      public Serializable getKey()
+      {
+         return key;
+      }
+
+      public Object getValue()
+      {
+         return value;
+      }
+      
+   }
+
+   /**
+    * It tries to get Set by given key. If it is Set then adds new value and puts new set back.
+    * If null found, then new Set created (ordinary cache does).
+    */
+   public static class AddToListContainer extends ChangesContainer
+   {
+      protected final Serializable key;
+
+      protected final Object value;
+
+      public AddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local)
+      {
+         super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
+         this.key = key;
+         this.value = value;
+      }
+
+      @Override
+      public void apply()
+      {
+         // force writeLock on next read
+         cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+         // object found by FQN and key;
+         Object existingObject = cache.get(getFqn(), key);
+         Set<Object> newSet = new HashSet<Object>();
+         // if set found of null, perform add
+         if (existingObject instanceof Set || existingObject == null)
+         {
+            // set found
+            if (existingObject instanceof Set)
+            {
+               newSet.addAll((Set<Object>)existingObject);
+            }
+            newSet.add(value);
+            setCacheLocalMode();
+            cache.put(fqn, key, newSet);
+         }
+         else
+         {
+            LOG.error("Unexpected object found by FQN:" + getFqn() + " and key:" + key + ". Expected Set, but found:"
+               + existingObject.getClass().getName());
+         }
+      }
+   }
+
+   /**
+    * It tries to get set by given key. If it is set then removes value and puts new modified set back.
+    */
+   public static class RemoveFromListContainer extends ChangesContainer
+   {
+      protected final Serializable key;
+
+      protected final Object value;
+
+      public RemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local)
+      {
+         super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
+         this.key = key;
+         this.value = value;
+      }
+
+      @Override
+      public void apply()
+      {
+         // force writeLock on next read
+         cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+         // object found by FQN and key;
+         setCacheLocalMode();
+         Object existingObject = cache.get(getFqn(), key);
+         // if found value is really set! add to it.
+         if (existingObject instanceof Set)
+         {
+            Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
+            newSet.remove(value);
+            setCacheLocalMode();
+            cache.put(fqn, key, newSet);
+         }
+      }
+   }
+
+   /**
+    * Remove container.
+    */
+   public static class RemoveKeyContainer extends ChangesContainer
+   {
+      private final Serializable key;
+
+      public RemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex,
+         boolean local)
+      {
+         super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
+         this.key = key;
+      }
+
+      @Override
+      public void apply()
+      {
+         setCacheLocalMode();
+         cache.remove(fqn, key);
+      }
+
+   }
+
+   /**
+    * Remove container.
+    */
+   public static class RemoveNodeContainer extends ChangesContainer
+   {
+
+      public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+      {
+         super(fqn, ChangesType.REMOVE, cache, historicalIndex, local);
+      }
+
+      @Override
+      public void apply()
+      {
+         setCacheLocalMode();
+         cache.removeNode(fqn);
+      }
+   }
+   
+   public ChangesContainer createPutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+            Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+   {
+     return new PutObjectContainer(fqn, data, cache, historicalIndex, local);  
+   }
+   
+   public ChangesContainer createPutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+            int historicalIndex, boolean local)
+   {
+     return new PutKeyValueContainer(fqn, key, value, cache, historicalIndex, local);  
+   }
+   
+   public ChangesContainer createAddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+            int historicalIndex, boolean local)
+   {
+     return new AddToListContainer(fqn, key, value, cache, historicalIndex, local);
+   }
+   
+   public ChangesContainer createRemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+            int historicalIndex, boolean local)
+   {
+     return new RemoveFromListContainer(fqn, key, value, cache, historicalIndex, local);
+   }
+   
+   public ChangesContainer createRemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex,
+            boolean local)
+   {
+     return new RemoveKeyContainer(fqn, key, cache, historicalIndex, local);
+   }
+   
+   public ChangesContainer createRemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+   {
+     return new RemoveNodeContainer(fqn, cache, historicalIndex, local);
+   }
+   
+}


Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java	2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java	2010-04-08 10:03:00 UTC (rev 2223)
@@ -18,16 +18,16 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
 
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesType;
-import org.jboss.cache.Fqn;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesType;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
+import org.jboss.cache.Fqn;
+
 /**
  * Sorting cache modification "as is" in {@link BufferedJBossCache} may harm data consistency. 
  * Here is a link, showing possible trouble:

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2010-04-08 10:03:00 UTC (rev 2223)
@@ -307,7 +307,7 @@
       }
 
       // TODO: create appropriate cache with useExpiration set or not.
-      this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()));
+      this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()), new ChangesContainerExpirationFactory());
 
       this.itemsRoot = Fqn.fromElements(ITEMS);
       this.childNodes = Fqn.fromElements(CHILD_NODES);

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java	2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java	2010-04-08 10:03:00 UTC (rev 2223)
@@ -18,15 +18,15 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
 
+import java.util.HashMap;
+
 import junit.framework.TestCase;
 
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.PutObjectContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.RemoveNodeContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutObjectContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveNodeContainer;
 import org.jboss.cache.Fqn;
 
-import java.util.HashMap;
-
 /**
  * @author <a href="mailto:foo at bar.org">Foo Bar</a>
  * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z aheritier $

Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml	2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml	2010-04-08 10:03:00 UTC (rev 2223)
@@ -15,7 +15,7 @@
       actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ParentNodeEvictionActionPolicy" 
       eventQueueSize="1000000">
          <property name="maxNodes" value="50000" />
-	 <property name="warnNoExpirationKey" value="true" />
+	 <property name="warnNoExpirationKey" value="false" />
       </default>
    </eviction>
 



More information about the exo-jcr-commits mailing list