[exo-jcr-commits] exo-jcr SVN: r2289 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Apr 20 09:30:11 EDT 2010


Author: nfilotto
Date: 2010-04-20 09:30:10 -0400 (Tue, 20 Apr 2010)
New Revision: 2289

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
Log:
EXOJCR-639: The method HasLocks has been added, The method getNumLocks should be launched as an Action Non Tx Aware and in getExactNodeOrCloseParentLock and getClosedChild, we check if the locks exist only once

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	2010-04-16 14:19:43 UTC (rev 2288)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java	2010-04-20 13:30:10 UTC (rev 2289)
@@ -443,14 +443,54 @@
       return lockTimeOut;
    }
 
+   private final LockActionNonTxAware<Integer, Object> getNumLocks = new LockActionNonTxAware<Integer, Object>()
+   {
+      public Integer execute(Object arg)
+      {
+         return ((CacheSPI<Serializable, Object>)cache).getNumberOfNodes() - 1;
+      }
+   };
+
    @Managed
    @ManagedDescription("The number of active locks")
    public int getNumLocks()
    {
-      return ((CacheSPI<Serializable, Object>)cache).getNumberOfNodes() - 1;
+      try
+      {
+         return executeLockActionNonTxAware(getNumLocks, null);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return -1;
    }
 
+   private final LockActionNonTxAware<Boolean, Object> hasLocks = new LockActionNonTxAware<Boolean, Object>()
+   {
+      public Boolean execute(Object arg)
+      {
+         return ((CacheSPI<Serializable, Object>)cache).getNode(lockRoot).hasChildrenDirect();
+      }
+   };
+
    /**
+    * Indicates if some locks have already been created
+    */
+   private boolean hasLocks()
+   {
+      try
+      {
+         return executeLockActionNonTxAware(hasLocks, null);
+      }
+      catch (LockException e)
+      {
+         // ignore me will never occur
+      }
+      return true;
+   }
+   
+   /**
     * Return new instance of session lock manager.
     */
    public SessionLockManager getSessionLockManager(String sessionId, SessionDataManager transientManager)
@@ -870,8 +910,13 @@
     */
    public LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException
    {
+      return getExactNodeOrCloseParentLock(node, true);
+   }
+   
+   private LockData getExactNodeOrCloseParentLock(NodeData node, boolean checkHasLocks) throws RepositoryException
+   {
 
-      if (node == null || getNumLocks() == 0)
+      if (node == null || (checkHasLocks && !hasLocks()))
       {
          return null;
       }
@@ -882,7 +927,7 @@
          NodeData parentData = (NodeData)dataManager.getItemData(node.getParentIdentifier());
          if (parentData != null)
          {
-            retval = getExactNodeOrCloseParentLock(parentData);
+            retval = getExactNodeOrCloseParentLock(parentData, false);
          }
       }
       return retval;
@@ -893,7 +938,7 @@
     */
    public LockData getExactNodeLock(NodeData node) throws RepositoryException
    {
-      if (node == null || getNumLocks() == 0)
+      if (node == null || !hasLocks())
       {
          return null;
       }
@@ -906,8 +951,13 @@
     */
    public LockData getClosedChild(NodeData node) throws RepositoryException
    {
+      return getClosedChild(node, true);
+   }
+   
+   private LockData getClosedChild(NodeData node, boolean checkHasLocks) throws RepositoryException
+   {
 
-      if (node == null || getNumLocks() == 0)
+      if (node == null || (checkHasLocks && !hasLocks()))
       {
          return null;
       }
@@ -923,7 +973,7 @@
       // child not found try to find dipper
       for (NodeData nodeData : childData)
       {
-         retval = getClosedChild(nodeData);
+         retval = getClosedChild(nodeData, false);
          if (retval != null)
             return retval;
       }



More information about the exo-jcr-commits mailing list