[exo-jcr-commits] exo-jcr SVN: r4089 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock: infinispan and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Mar 15 07:48:10 EDT 2011


Author: tolusha
Date: 2011-03-15 07:48:09 -0400 (Tue, 15 Mar 2011)
New Revision: 4089

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
Log:
EXOJCR-834: perform lock operation out of transaction

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java	2011-03-15 10:05:20 UTC (rev 4088)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java	2011-03-15 11:48:09 UTC (rev 4089)
@@ -52,6 +52,9 @@
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 import org.exoplatform.services.security.IdentityConstants;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Node;
+import org.jboss.cache.loader.CacheLoader;
 import org.picocontainer.Startable;
 
 import java.io.BufferedOutputStream;
@@ -72,6 +75,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.lock.LockException;
+import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
 /**
@@ -128,8 +132,22 @@
    /**
     * Logger
     */
-   private final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.AbstractCacheableLockManager");
+   protected Log LOG = ExoLogger.getLogger("exo.jcr.component.core.AbstractCacheableLockManager");
 
+   protected LockActionNonTxAware<Integer, Object> getNumLocks;
+
+   protected LockActionNonTxAware<Boolean, Object> hasLocks;
+
+   protected LockActionNonTxAware<Boolean, String> isLockLive;
+
+   protected LockActionNonTxAware<Object, LockData> refresh;
+
+   protected LockActionNonTxAware<Boolean, String> lockExist;
+
+   protected LockActionNonTxAware<LockData, String> getLockDataById;
+
+   protected LockActionNonTxAware<List<LockData>, Object> getLockList;
+
    /**
     * Constructor.
     * 
@@ -170,7 +188,113 @@
       dataManager.addItemPersistenceListener(this);
    }
 
+   /**
+    * Returns the number of active locks.
+    */
    @Managed
+   @ManagedDescription("The number of active locks")
+   public int getNumLocks()
+   {
+      try
+      {
+         return executeLockActionNonTxAware(getNumLocks, null);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return -1;
+   }
+
+   /**
+    * Indicates if some locks have already been created.
+    */
+   protected boolean hasLocks()
+   {
+      try
+      {
+         return executeLockActionNonTxAware(hasLocks, null);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return true;
+   }
+
+   /**
+    * Check is LockManager contains lock. No matter it is in pending or persistent state.
+    */
+   public boolean isLockLive(String nodeId) throws LockException
+   {
+      try
+      {
+         return executeLockActionNonTxAware(isLockLive, nodeId);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return false;
+   }
+
+   /**
+    * Refreshed lock data in cache
+    */
+   public void refreshLockData(LockData newLockData) throws LockException
+   {
+      executeLockActionNonTxAware(refresh, newLockData);
+   }
+
+   /**
+    * Check is LockManager contains lock. 
+    */
+   public boolean lockExist(String nodeId)
+   {
+      try
+      {
+         return executeLockActionNonTxAware(lockExist, nodeId);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return false;
+   }
+
+   /**
+    * Returns lock data by node identifier.
+    */
+   protected LockData getLockDataById(String nodeId)
+   {
+      try
+      {
+         return executeLockActionNonTxAware(getLockDataById, nodeId);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return null;
+   }
+
+   /**
+    * Returns all locks.
+    */
+   protected synchronized List<LockData> getLockList()
+   {
+      try
+      {
+         return executeLockActionNonTxAware(getLockList, null);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return null;
+   }
+
+   @Managed
    @ManagedDescription("Remove the expired locks")
    public void cleanExpiredLocks()
    {
@@ -631,7 +755,58 @@
       sessionLockManagers.remove(sessionID);
    }
 
+   /**
+    * Execute the given action outside a transaction. This is needed since the {@link Cache} used by implementation of {@link CacheableLockManager}
+    * to manage the persistence of its locks thanks to a {@link CacheLoader} and a {@link CacheLoader} lock the cache {@link Node}
+    * even for read operations which cause deadlock issue when a XA {@link Transaction} is already opened
+    * @throws LockException when a exception occurs
+    */
+   private <R, A> R executeLockActionNonTxAware(LockActionNonTxAware<R, A> action, A arg) throws LockException
+   {
+      Transaction tx = null;
+      try
+      {
+         if (tm != null)
+         {
+            try
+            {
+               tx = tm.suspend();
+            }
+            catch (Exception e)
+            {
+               LOG.warn("Cannot suspend the current transaction", e);
+            }
+         }
+         return action.execute(arg);
+      }
+      finally
+      {
+         if (tx != null)
+         {
+            try
+            {
+               tm.resume(tx);
+            }
+            catch (Exception e)
+            {
+               LOG.warn("Cannot resume the current transaction", e);
+            }
+         }
+      }
+   }
 
+   /**
+    * Actions that are not supposed to be called within a transaction
+    * 
+    * Created by The eXo Platform SAS
+    * Author : Nicolas Filotto 
+    *          nicolas.filotto at exoplatform.com
+    * 21 janv. 2010
+    */
+   protected static interface LockActionNonTxAware<R, A>
+   {
+      R execute(A arg) throws LockException;
+   }
 
    /**
     * {@inheritDoc}
@@ -802,43 +977,6 @@
    }
 
    /**
-    * Returns the number of active locks.
-    */
-   @Managed
-   @ManagedDescription("The number of active locks")
-   public abstract int getNumLocks();
-
-   /**
-    * Indicates if some locks have already been created.
-    */
-   protected abstract boolean hasLocks();
-
-   /**
-    * Check is LockManager contains lock. No matter it is in pending or persistent state.
-    */
-   public abstract boolean isLockLive(String nodeId) throws LockException;
-
-   /**
-    * Refreshed lock data in cache
-    */
-   public abstract void refreshLockData(LockData newLockData) throws LockException;
-
-   /**
-    * Check is LockManager contains lock. 
-    */
-   public abstract boolean lockExist(String nodeId);
-
-   /**
-    * Returns lock data by node identifier.
-    */
-   protected abstract LockData getLockDataById(String nodeId);
-
-   /**
-    * Returns all locks.
-    */
-   protected abstract List<LockData> getLockList();
-
-   /**
     * Puts lock data directly into cache.
     * 
     * @param lockData

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java	2011-03-15 10:05:20 UTC (rev 4088)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java	2011-03-15 11:48:09 UTC (rev 4089)
@@ -125,84 +125,78 @@
       {
          throw new RepositoryConfigurationException("Cache configuration not found");
       }
-   }
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public int getNumLocks()
-   {
-      return cache.size();
-   }
+      this.getNumLocks = new LockActionNonTxAware<Integer, Object>()
+      {
+         public Integer execute(Object arg)
+         {
+            return cache.size();
+         }
+      };
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public boolean isLockLive(String nodeId) throws LockException
-   {
-      return cache.containsKey(nodeId);
-   }
+      this.hasLocks = new LockActionNonTxAware<Boolean, Object>()
+      {
+         public Boolean execute(Object arg)
+         {
+            return !cache.isEmpty();
+         }
+      };
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   protected LockData getLockDataById(String nodeId)
-   {
-      return (LockData)cache.get(nodeId);
-   }
+      this.isLockLive = new LockActionNonTxAware<Boolean, String>()
+      {
+         public Boolean execute(String nodeId)
+         {
+            return cache.containsKey(nodeId);
+         }
+      };
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   protected synchronized List<LockData> getLockList()
-   {
-      Collection<Object> datas = cache.values();
+      this.refresh = new LockActionNonTxAware<Object, LockData>()
+      {
+         public Object execute(LockData newLockData) throws LockException
+         {
+            Object oldValue = PrivilegedISPNCacheHelper.put(cache, newLockData.getNodeIdentifier(), newLockData);
+            if (oldValue == null)
+            {
+               throw new LockException("Can't refresh lock for node " + newLockData.getNodeIdentifier()
+                  + " since lock is not exist");
+            }
+            return null;
+         }
+      };
 
-      List<LockData> locksData = new ArrayList<LockData>();
-      for (Object lockData : datas)
+      this.lockExist = new LockActionNonTxAware<Boolean, String>()
       {
-         if (lockData != null)
+         public Boolean execute(String nodeId) throws LockException
          {
-            locksData.add((LockData)lockData);
+            return cache.containsKey(nodeId);
          }
-      }
-      return locksData;
-   }
+      };
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public boolean lockExist(String nodeId)
-   {
-      return cache.containsKey(nodeId);
-   }
+      this.getLockDataById = new LockActionNonTxAware<LockData, String>()
+      {
+         public LockData execute(String nodeId) throws LockException
+         {
+            return (LockData)cache.get(nodeId);
+         }
+      };
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public void refreshLockData(LockData newLockData) throws LockException
-   {
-      Object oldValue = PrivilegedISPNCacheHelper.put(cache, newLockData.getNodeIdentifier(), newLockData);
-      if (oldValue == null)
+      this.getLockList = new LockActionNonTxAware<List<LockData>, Object>()
       {
-         throw new LockException("Can't refresh lock for node " + newLockData.getNodeIdentifier()
-            + " since lock is not exist");
-      }
-   }
+         public List<LockData> execute(Object arg) throws LockException
+         {
+            Collection<Object> datas = cache.values();
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   protected boolean hasLocks()
-   {
-      return !cache.isEmpty();
+            List<LockData> locksData = new ArrayList<LockData>();
+            for (Object lockData : datas)
+            {
+               if (lockData != null)
+               {
+                  locksData.add((LockData)lockData);
+               }
+            }
+            return locksData;
+         }
+      };
    }
 
    /**

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java	2011-03-15 10:05:20 UTC (rev 4088)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java	2011-03-15 11:48:09 UTC (rev 4089)
@@ -25,7 +25,6 @@
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
 import org.exoplatform.services.jcr.impl.core.lock.LockRemoverHolder;
 import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
-import org.exoplatform.services.jcr.impl.core.lock.cacheable.CacheableLockManager;
 import org.exoplatform.services.jcr.impl.core.lock.cacheable.CacheableSessionLockManager;
 import org.exoplatform.services.jcr.impl.core.lock.cacheable.LockData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
@@ -63,7 +62,6 @@
 import javax.jcr.lock.LockException;
 import javax.naming.InitialContext;
 import javax.sql.DataSource;
-import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
 /**
@@ -117,20 +115,6 @@
 
    private final boolean shareable;
 
-   private final LockActionNonTxAware<Integer, Object> getNumLocks;
-
-   private final LockActionNonTxAware<Boolean, Object> hasLocks;
-
-   private final LockActionNonTxAware<Boolean, String> isLockLive;
-
-   private final LockActionNonTxAware<Object, LockData> refresh;
-
-   private final LockActionNonTxAware<Boolean, String> lockExist;
-
-   private final LockActionNonTxAware<LockData, String> getLockDataById;
-
-   private final LockActionNonTxAware<List<LockData>, Object> getLockList;
-
    /**
     * Constructor.
     * 
@@ -297,118 +281,8 @@
       };
    }
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public int getNumLocks()
-   {
-      try
-      {
-         return executeLockActionNonTxAware(getNumLocks, null);
-      }
-      catch (LockException e)
-      {
-         // ignore me will never occur
-      }
-      return -1;
-   }
 
    /**
-    * {@inheritDoc}
-    */
-   @Override
-   protected boolean hasLocks()
-   {
-      try
-      {
-         return executeLockActionNonTxAware(hasLocks, null);
-      }
-      catch (LockException e)
-      {
-         // ignore me will never occur
-      }
-      return true;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public boolean isLockLive(String nodeId) throws LockException
-   {
-      try
-      {
-         return executeLockActionNonTxAware(isLockLive, nodeId);
-      }
-      catch (LockException e)
-      {
-         // ignore me will never occur
-      }
-      return false;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public void refreshLockData(LockData newLockData) throws LockException
-   {
-      executeLockActionNonTxAware(refresh, newLockData);
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public boolean lockExist(String nodeId)
-   {
-      try
-      {
-         return executeLockActionNonTxAware(lockExist, nodeId);
-      }
-      catch (LockException e)
-      {
-         // ignore me will never occur
-      }
-      return false;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   protected LockData getLockDataById(String nodeId)
-   {
-      try
-      {
-         return executeLockActionNonTxAware(getLockDataById, nodeId);
-      }
-      catch (LockException e)
-      {
-         // ignore me will never occur
-      }
-      return null;
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   protected synchronized List<LockData> getLockList()
-   {
-      try
-      {
-         return executeLockActionNonTxAware(getLockList, null);
-      }
-      catch (LockException e)
-      {
-         // ignore me will never occur
-      }
-      return null;
-   }
-
-   /**
     * If JDBC cache loader is used, then fills-in column types. If column type configured from jcr-configuration file,
     * then nothing is overridden. Parameters are injected into the given parameterEntry.
     */
@@ -699,59 +573,6 @@
    }
 
    /**
-    * Execute the given action outside a transaction. This is needed since the {@link Cache} used by implementation of {@link CacheableLockManager}
-    * to manage the persistence of its locks thanks to a {@link CacheLoader} and a {@link CacheLoader} lock the cache {@link Node}
-    * even for read operations which cause deadlock issue when a XA {@link Transaction} is already opened
-    * @throws LockException when a exception occurs
-    */
-   private <R, A> R executeLockActionNonTxAware(LockActionNonTxAware<R, A> action, A arg) throws LockException
-   {
-      Transaction tx = null;
-      try
-      {
-         if (tm != null)
-         {
-            try
-            {
-               tx = tm.suspend();
-            }
-            catch (Exception e)
-            {
-               LOG.warn("Cannot suspend the current transaction", e);
-            }
-         }
-         return action.execute(arg);
-      }
-      finally
-      {
-         if (tx != null)
-         {
-            try
-            {
-               tm.resume(tx);
-            }
-            catch (Exception e)
-            {
-               LOG.warn("Cannot resume the current transaction", e);
-            }
-         }
-      }
-   }
-
-   /**
-    * Actions that are not supposed to be called within a transaction
-    * 
-    * Created by The eXo Platform SAS
-    * Author : Nicolas Filotto 
-    *          nicolas.filotto at exoplatform.com
-    * 21 janv. 2010
-    */
-   protected static interface LockActionNonTxAware<R, A>
-   {
-      R execute(A arg) throws LockException;
-   }
-
-   /**
     * {@inheritDoc}
     */
    @Override



More information about the exo-jcr-commits mailing list