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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Apr 8 08:45:58 EDT 2010


Author: areshetnyak
Date: 2010-04-08 08:45:57 -0400 (Thu, 08 Apr 2010)
New Revision: 2230

Removed:
   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
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
Log:
EXOJCR-545 : The implemetation use ExpirationAlgorithm was changed.

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 12:42:09 UTC (rev 2229)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java	2010-04-08 12:45:57 UTC (rev 2230)
@@ -18,8 +18,14 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
 
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutKeyValueContainer;
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 import org.jboss.cache.Cache;
@@ -32,19 +38,10 @@
 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.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-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.
  * 
@@ -60,34 +57,23 @@
     */
    private final Cache<Serializable, Object> parentCache;
 
-   private final ChangesContainerFactory changesContatinerFactory;
-
    private final ThreadLocal<CompressedChangesBuffer> changesList = new ThreadLocal<CompressedChangesBuffer>();
 
-   /**
-    * This comparator sorts CahangesContainer collection in descending mode.
-    */
-   private final Comparator<ChangesContainer> changesComparator = new Comparator<ChangesContainer>()
-   {
-
-      public int compare(ChangesContainer o1, ChangesContainer o2)
-      {
-         int result = o1.getFqn().compareTo(o2.getFqn());
-         return result == 0 ? o2.getHistoricalIndex() - o1.getHistoricalIndex() : result;
-      }
-
-   };
-
    private ThreadLocal<Boolean> local = new ThreadLocal<Boolean>();
+   
+   private final boolean useExpiration;
+   
+   private final long expirationTimeOut;
 
    protected static final Log LOG =
       ExoLogger.getLogger("org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache");
 
-   public BufferedJBossCache(Cache<Serializable, Object> parentCache, ChangesContainerFactory changesContatinerFactory)
+   public BufferedJBossCache(Cache<Serializable, Object> parentCache, boolean useExpiration, long expirationTimeOut)
    {
       super();
       this.parentCache = parentCache;
-      this.changesContatinerFactory = changesContatinerFactory;
+      this.useExpiration = useExpiration;
+      this.expirationTimeOut = expirationTimeOut;
    }
 
    /**
@@ -469,8 +455,8 @@
    public void put(Fqn fqn, Map<? extends Serializable, ? extends Object> data)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(changesContatinerFactory.createPutObjectContainer(fqn, data, parentCache, changesContainer
-         .getHistoryIndex(), local.get()));
+      changesContainer.add(new PutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local
+         .get(), useExpiration, expirationTimeOut));
    }
 
    /* (non-Javadoc)
@@ -479,8 +465,8 @@
    public Object put(Fqn fqn, Serializable key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache,
-         changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+         local.get(), useExpiration, expirationTimeOut));
 
       return parentCache.get(fqn, key);
    }
@@ -492,8 +478,8 @@
       // take Object from buffer for first 
       Object prevObject = getObjectFromChangesContainer(changesContainer, fqn, key);
 
-      changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache,
-         changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+         local.get(), useExpiration, expirationTimeOut));
 
       if (prevObject != null)
       {
@@ -507,42 +493,9 @@
 
    private Object getObjectFromChangesContainer(CompressedChangesBuffer changesContainer, Fqn fqn, Serializable key)
    {
-      //      List<ChangesContainer> changes = changesContainer.getSortedList();
-      //      Object object = null;
-      //      for (ChangesContainer change : changes)
-      //      {
-      //         if (change.getChangesType().equals(ChangesType.PUT_KEY) && change.getFqn().equals(fqn))
-      //         {
-      //            PutKeyValueContainer cont = ((PutKeyValueContainer)change);
-      //            if (cont.getKey().equals(key))
-      //            {
-      //               object = ((PutKeyValueContainer)change).getValue();
-      //            }
-      //         }
-      //      }
-      //
-      //      return object;
-
-      List<ChangesContainer> changesContainers = new ArrayList<ChangesContainer>();
-      String parentCacheNode = (String)fqn.get(0);
-      if (JBossCacheWorkspaceStorageCache.CHILD_NODES.equals(parentCacheNode) && fqn.size() > 1)
-      {
-         changesContainers.addAll(changesContainer.childNodesMap.get(fqn.get(1)));
-      }
-      else if (JBossCacheWorkspaceStorageCache.CHILD_PROPS.equals(parentCacheNode) && fqn.size() > 1)
-      {
-         changesContainers.addAll(changesContainer.childPropertyMap.get(fqn.get(1)));
-      }
-      else
-      {
-         changesContainers.addAll(changesContainer.changes);
-      }
-
-      // sort changes in descending mode 
-      Collections.sort(changesContainers, changesComparator);
-
+      List<ChangesContainer> changes = changesContainer.getSortedList();
       Object object = null;
-      for (ChangesContainer change : changesContainers)
+      for (ChangesContainer change : changes)
       {
          if (change.getChangesType().equals(ChangesType.PUT_KEY) && change.getFqn().equals(fqn))
          {
@@ -550,7 +503,6 @@
             if (cont.key.equals(key))
             {
                object = ((PutKeyValueContainer)change).value;
-               break;
             }
          }
       }
@@ -589,8 +541,8 @@
    public Object remove(Fqn fqn, Serializable key)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(changesContatinerFactory.createRemoveKeyContainer(fqn, key, parentCache, changesContainer
-         .getHistoryIndex(), local.get()));
+      changesContainer.add(new RemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
+         .get(), useExpiration, expirationTimeOut));
       return parentCache.get(fqn, key);
    }
 
@@ -632,8 +584,8 @@
    public boolean removeNode(Fqn fqn)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(changesContatinerFactory.createRemoveNodeContainer(fqn, parentCache, changesContainer
-         .getHistoryIndex(), local.get()));
+      changesContainer.add(new RemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get(), 
+               useExpiration, expirationTimeOut));
       return true;
    }
 
@@ -701,8 +653,8 @@
    public void addToList(Fqn fqn, String key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(changesContatinerFactory.createAddToListContainer(fqn, key, value, parentCache,
-         changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+         local.get(), useExpiration, expirationTimeOut));
    }
 
    /**
@@ -715,12 +667,291 @@
    public void removeFromList(Fqn fqn, String key, Object value)
    {
       CompressedChangesBuffer changesContainer = getChangesBufferSafe();
-      changesContainer.add(changesContatinerFactory.createRemoveFromListContainer(fqn, key, value, parentCache,
-         changesContainer.getHistoryIndex(), local.get()));
+      changesContainer.add(new RemoveFromListContainer(fqn, key, value, parentCache,
+         changesContainer.getHistoryIndex(), local.get(), useExpiration, expirationTimeOut));
    }
 
    public static enum ChangesType {
       REMOVE, REMOVE_KEY, PUT, PUT_KEY, PUT_TO_LIST;
    }
 
+   /**
+    * 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;
+
+      protected final boolean useExpiration;
+      
+      protected final long timeOut;
+      
+      public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
+         boolean localMode, boolean useExpiration, long timeOut)
+      {
+         super();
+         this.fqn = fqn;
+         this.changesType = changesType;
+         this.cache = cache;
+         this.historicalIndex = historicalIndex;
+         this.localMode = localMode;
+         this.useExpiration = useExpiration;
+         this.timeOut = timeOut;
+      }
+
+      /**
+       * @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 final void putExpiration(Fqn efqn)
+      {
+         setCacheLocalMode();
+         cache.put(efqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + timeOut));
+      }
+
+      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, boolean useExpiration, long timeOut)
+      {
+         super(fqn, ChangesType.PUT, cache, historicalIndex, local, useExpiration, timeOut);
+
+         this.data = data;
+      }
+
+      @Override
+      public void apply()
+      {
+         setCacheLocalMode();
+         cache.put(fqn, data);
+         
+         if (useExpiration)
+         {
+            putExpiration(fqn);
+         }
+      }
+   }
+
+   /**
+    * 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, boolean useExpiration, long timeOut)
+      {
+         super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local, useExpiration, timeOut);
+         this.key = key;
+         this.value = value;
+      }
+
+      @Override
+      public void apply()
+      {
+         if (useExpiration)
+         {
+            putExpiration(fqn);
+         }
+         
+         setCacheLocalMode();
+         cache.put(fqn, key, 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
+   {
+      private final Serializable key;
+
+      private final Object value;
+
+      public AddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local, boolean useExpiration, long timeOut)
+      {
+         super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local, useExpiration, timeOut);
+         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);
+            
+            if (useExpiration)
+            {
+               putExpiration(fqn);
+            }
+            
+            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
+   {
+      private final Serializable key;
+
+      private final Object value;
+
+      public RemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+         int historicalIndex, boolean local, boolean useExpiration, long timeOut)
+      {
+         super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local, useExpiration, timeOut);
+         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);
+            
+            if (useExpiration)
+            {
+               putExpiration(fqn);
+            }
+            
+            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, boolean useExpiration, long timeOut)
+      {
+         super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local, useExpiration, timeOut);
+         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, 
+               boolean useExpiration, long timeOut)
+      {
+         super(fqn, ChangesType.REMOVE, cache, historicalIndex, local, useExpiration, timeOut);
+      }
+
+      @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/ChangesContainerExpirationFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java	2010-04-08 12:42:09 UTC (rev 2229)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java	2010-04-08 12:45:57 UTC (rev 2230)
@@ -1,235 +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 org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
-
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * 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 long expirationTimeOut;
-
-   public ChangesContainerExpirationFactory(long expirationTimeOut)
-   {
-      this.expirationTimeOut = expirationTimeOut;
-   }
-
-   /**
-    * Put object container;
-    */
-   public static class PutObjectContainerExpiration extends PutObjectContainer
-   {
-      private final long timeOut;
-
-      public PutObjectContainerExpiration(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
-         Cache<Serializable, Object> cache, int historicalIndex, boolean local, long timeOut)
-      {
-         super(fqn, data, cache, historicalIndex, local);
-         this.timeOut = timeOut; 
-      }
-
-      @Override
-      public void apply()
-      {
-         setCacheLocalMode();
-         cache.put(fqn, data);
-
-         setCacheLocalMode();
-         cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + timeOut));
-      }
-   }
-
-   /**
-    * Put  container.
-    */
-   public static class PutKeyValueContainerExpiration extends PutKeyValueContainer
-   {
-      private final long timeOut;
-
-      public PutKeyValueContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
-         int historicalIndex, boolean local, long timeOut)
-      {
-         super(fqn, key, value, cache, historicalIndex, local);
-         this.timeOut = timeOut;
-      }
-
-      @Override
-      public void apply()
-      {
-         setCacheLocalMode();
-         cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + timeOut));
-
-         setCacheLocalMode();
-         cache.put(fqn, key, value);
-      }
-
-      @Override
-      public Serializable getKey()
-      {
-         return key;
-      }
-
-      @Override
-      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
-   {
-      private final long timeOut;
-
-      public AddToListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
-         int historicalIndex, boolean local, long timeOut)
-      {
-         super(fqn, key, value, cache, historicalIndex, local);
-         this.timeOut = timeOut;
-      }
-
-      @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() + timeOut));
-
-            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
-   {
-      private final long timeOut;
-
-      public RemoveFromListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
-         int historicalIndex, boolean local, long timeOut)
-      {
-         super(fqn, key, value, cache, historicalIndex, local);
-         this.timeOut = timeOut;
-      }
-
-      @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() + timeOut));
-
-            setCacheLocalMode();
-            cache.put(fqn, key, newSet);
-         }
-      }
-   }
-   
-   /**
-    * {@inheritDoc}
-    */
-   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, expirationTimeOut);  
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   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, expirationTimeOut);  
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   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, expirationTimeOut);
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   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, expirationTimeOut);
-   }
-
-}

Deleted: 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	2010-04-08 12:42:09 UTC (rev 2229)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java	2010-04-08 12:45:57 UTC (rev 2230)
@@ -1,335 +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.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);
-   }
-   
-}

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 12:42:09 UTC (rev 2229)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java	2010-04-08 12:45:57 UTC (rev 2230)
@@ -24,8 +24,8 @@
 import java.util.List;
 import java.util.Map;
 
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesContainer;
 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;
 
 /**

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 12:42:09 UTC (rev 2229)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2010-04-08 12:45:57 UTC (rev 2230)
@@ -306,9 +306,8 @@
 
       // if expiration is used, set appropriate factory with with timeout set via configuration (or default one 15minutes)
       this.cache =
-         new BufferedJBossCache(factory.createCache(wsConfig.getCache()), useExpiration
-            ? new ChangesContainerExpirationFactory(wsConfig.getCache().getParameterInteger(JBOSSCACHE_EXPIRATION,
-               JBOSSCACHE_EXPIRATION_DEFAULT)) : new ChangesContainerFactory());
+         new BufferedJBossCache(factory.createCache(wsConfig.getCache()), useExpiration,
+                  wsConfig.getCache().getParameterInteger(JBOSSCACHE_EXPIRATION, JBOSSCACHE_EXPIRATION_DEFAULT));
 
       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 12:42:09 UTC (rev 2229)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java	2010-04-08 12:45:57 UTC (rev 2230)
@@ -22,9 +22,9 @@
 
 import junit.framework.TestCase;
 
-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.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.jboss.cache.Fqn;
 
 /**
@@ -40,13 +40,13 @@
       CompressedChangesBuffer buffer = new CompressedChangesBuffer();
       ChangesContainer put1 =
          new PutObjectContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES + "/b"),
-            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false);
+            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false, false, 0);
       ChangesContainer put2 =
          new PutObjectContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES + "/b/c"),
-            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false);
+            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false, false, 0);
       ChangesContainer rm1 =
          new RemoveNodeContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES + "/b"), null, buffer
-            .getHistoryIndex(), false);
+            .getHistoryIndex(), false, false, 0);
       buffer.add(put1);
       buffer.add(put2);
       assertTrue("List MUST contain put container", buffer.getSortedList().contains(put1));
@@ -67,17 +67,17 @@
       CompressedChangesBuffer buffer = new CompressedChangesBuffer();
       ChangesContainer put1 =
          new PutObjectContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES + "/b"),
-            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false);
+            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false, false, 0);
 
       ChangesContainer put2 =
          new PutObjectContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES + "/b/c"),
-            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false);
+            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false, false, 0);
       ChangesContainer rm1 =
          new RemoveNodeContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES + "/b/c"), null,
-            buffer.getHistoryIndex(), false);
+            buffer.getHistoryIndex(), false, false, 0);
       ChangesContainer rm2 =
          new RemoveNodeContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES + "/b"), null, buffer
-            .getHistoryIndex(), false);
+            .getHistoryIndex(), false, false, 0);
       buffer.add(put1);
       buffer.add(put2);
       assertTrue("List MUST contain put container", buffer.getSortedList().contains(put1));
@@ -97,11 +97,11 @@
       CompressedChangesBuffer buffer = new CompressedChangesBuffer();
       ChangesContainer put1 =
          new PutObjectContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST + "/b"),
-            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false);
+            new HashMap<String, String>(), null, buffer.getHistoryIndex(), false, false, 0);
 
       ChangesContainer rm1 =
          new RemoveNodeContainer(Fqn.fromString("/" + JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST + "/b"), null,
-            buffer.getHistoryIndex(), false);
+            buffer.getHistoryIndex(), false, false, 0);
       buffer.add(put1);
       assertTrue("List MUST contain put container", buffer.getSortedList().contains(put1));
       buffer.add(rm1);



More information about the exo-jcr-commits mailing list