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

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Feb 5 05:28:45 EST 2010


Author: sergiykarpenko
Date: 2010-02-05 05:28:45 -0500 (Fri, 05 Feb 2010)
New Revision: 1693

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/WorkspaceLockManager.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
   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/CacheableSessionLockManager.java
Log:
EXOJCR-472: CacheableLockManager updated

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/WorkspaceLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/WorkspaceLockManager.java	2010-02-05 07:07:32 UTC (rev 1692)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/WorkspaceLockManager.java	2010-02-05 10:28:45 UTC (rev 1693)
@@ -33,13 +33,14 @@
     * Returns session lock manager that interact with this LockManager.
     * 
     * @param sessionId - session ID
-    * @return
+    * @return new SessionLockManager
     */
    SessionLockManager getSessionLockManager(String sessionId);
 
    /**
-    * Release resources associated with previously opened SessionLockManager.
-    * @param sessionId - session ID
+    * Release all resources associated with CacheableSessionLockManager.
+    * 
+    * @param sessionID - session identifier
     */
    void closeSessionLockManager(String sessionId);
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java	2010-02-05 07:07:32 UTC (rev 1692)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java	2010-02-05 10:28:45 UTC (rev 1693)
@@ -32,47 +32,42 @@
 public interface CacheableLockManager extends WorkspaceLockManager
 {
 
+   // Search constants
    /**
-    * Returns new LockData object or throw LockException if can't place lock here.
-    * 
-    * @param node
-    * @param lockToken
-    * @param isDeep
-    * @param isSessionScoped
-    * @param timeOut
-    * @return LockData object 
-    * @throws LockException - if node can not be locked
+    * The exact lock token.
     */
-   LockData createLockData(NodeData node, String lockToken, boolean isDeep, boolean isSessionScoped, String owner,
-      long timeOut) throws LockException;
+   public static final int SEARCH_EXECMATCH = 1;
 
    /**
-    * Is lock assigned exactly for node exist.
-    * 
-    * @param node
-    * @return 
+    * Lock token of closed parent
     */
-   boolean exactLockExist(NodeData node);
+   public static final int SEARCH_CLOSEDPARENT = 2;
 
    /**
-    * Returns lock data that is assigned to this node or its parent.
-    * 
-    * @param node
-    * @return
+    * Lock token of closed child
     */
-   LockData getExactOrCloseParentLock(NodeData node);
+   public static final int SEARCH_CLOSEDCHILD = 4;
 
-   String getHash(String lockToken);
-
    /**
-    * Is lock live
+    * Is lock live for node by nodeIdentifier.
     * 
     * @param nodeIdentifier
-    * @return
+    * 
+    * @return boolean
     */
    boolean isLockLive(String nodeIdentifier);
 
    /**
+    * Search lock in storage. SearchType shows which locks should be returned.
+    * See SEARCH_EXECMATCH, SEARCH_CLOSEDPARENT, SEARCH_CLOSEDCHILD. SearchTypes may be combined.
+    * 
+    * @param node - base node to search locks 
+    * @param searchType - combination of SEARCH_EXECMATCH, SEARCH_CLOSEDPARENT, SEARCH_CLOSEDCHILD search types
+    * @return LockData or null
+    */
+   public LockData getLockData(NodeData node, int searchType);
+
+   /**
     * Replace old lockData with new one. Node ID, token can't be replaced.
     * 
     * @param newLockData
@@ -80,4 +75,18 @@
     */
    void refreshLockData(LockData newLockData) throws LockException;
 
+   /**
+    * Get default lock timeout.
+    * 
+    * @return long value of timeout
+    */
+   long getDefaultLockTimeOut();
+
+   /**
+    * Return hash for lock token.
+    * 
+    * @param lockToken - lock token string 
+    * @return - hash string
+    */
+   String getLockTokenHash(String lockToken);
 }

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-02-05 07:07:32 UTC (rev 1692)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java	2010-02-05 10:28:45 UTC (rev 1693)
@@ -104,23 +104,7 @@
     */
    public static final long DEFAULT_LOCK_TIMEOUT = 1000 * 60 * 30;
 
-   // Search constants
    /**
-    * The exact lock token.
-    */
-   protected static final int SEARCH_EXECMATCH = 1;
-
-   /**
-    * Lock token of closed parent
-    */
-   protected static final int SEARCH_CLOSEDPARENT = 2;
-
-   /**
-    * Lock token of closed child
-    */
-   protected static final int SEARCH_CLOSEDCHILD = 4;
-
-   /**
     * Name of lock root in jboss-cache.
     */
    public static final String LOCKS = "$LOCKS";
@@ -133,7 +117,7 @@
    /**
     * Logger
     */
-   private final Log log = ExoLogger.getLogger("jcr.lock.CacheableLockManager");
+   private final Log log = ExoLogger.getLogger("jcr.lock.CacheableLockManagerImpl");
 
    /**
     * Data manager.
@@ -141,11 +125,6 @@
    private final DataManager dataManager;
 
    /**
-    * Context recall is a workaround of JDBCCacheLoader starting. 
-    */
-   //private final InitialContextInitializer context;
-
-   /**
     * Run time lock time out.
     */
    private long lockTimeOut;
@@ -164,6 +143,9 @@
 
    private final Fqn<String> lockRoot;
 
+   /**
+    * SessionLockManagers that uses this LockManager.
+    */
    private Map<String, CacheableSessionLockManager> sessionLockManagers;
 
    /**
@@ -229,16 +211,13 @@
             lockTimeOut =
                config.getLockManager().getTimeout() > 0 ? config.getLockManager().getTimeout() : DEFAULT_LOCK_TIMEOUT;
          }
-
       }
       else
       {
          lockTimeOut = DEFAULT_LOCK_TIMEOUT;
       }
 
-      //pendingLocks = new HashMap<String, LockData>();
       sessionLockManagers = new HashMap<String, CacheableSessionLockManager>();
-      //this.context = context;
 
       dataManager.addItemPersistenceListener(this);
 
@@ -312,19 +291,8 @@
       if (log.isInfoEnabled())
       {
          log.info("The pre and post cache loaders have been added");
-      }      
+      }
    }
-   
-   /*
-    * (non-Javadoc)
-    * @see
-    * org.exoplatform.services.jcr.impl.core.lock.LockManager#addPendingLock(org.exoplatform.services
-    * .jcr.impl.core.NodeImpl, boolean, boolean, long)
-    */
-   //   public synchronized void addPendingLock(String nodeIdentifier, LockData lData)
-   //   {
-   //      pendingLocks.put(nodeIdentifier, lData);
-   //   }
 
    @Managed
    @ManagedDescription("Remove the expired locks")
@@ -338,24 +306,6 @@
       return lockTimeOut;
    }
 
-   /*
-    * (non-Javadoc)
-    * @see
-    * org.exoplatform.services.jcr.impl.core.lock.LockManager#getLock(org.exoplatform.services.jcr
-    * .impl.core.NodeImpl)
-    */
-   //   public LockData getLockData(NodeImpl node) throws LockException, RepositoryException
-   //   {
-   //
-   //      LockData lData = getLockData((NodeData)node.getData(), SEARCH_EXECMATCH | SEARCH_CLOSEDPARENT);
-   //
-   //      if (lData == null || (!node.getInternalIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
-   //      {
-   //         throw new LockException("Node not locked: " + node.getData().getQPath());
-   //      }
-   //      return lData;
-   //   }
-
    private final LockActionNonTxAware<Integer, Object> getNumLocks = new LockActionNonTxAware<Integer, Object>()
    {
       public Integer execute(Object arg)
@@ -393,7 +343,7 @@
    {
       public Boolean execute(String nodeId)
       {
-         if (/*pendingLocks.containsKey(nodeId) || */cache.get(makeLockFqn(nodeId), LOCK_DATA) != null)
+         if (cache.get(makeLockFqn(nodeId), LOCK_DATA) != null) //pendingLocks.containsKey(nodeId) || 
          {
             return true;
          }
@@ -548,7 +498,7 @@
    }
 
    /**
-    * Class containing operation type (LOCK or UNLOCK) and all the needed information like node uuid and session id 
+    * Class containing operation type (LOCK or UNLOCK) and all the needed information like node uuid and session id.
     */
    private class LockOperationContainer implements Comparable<LockOperationContainer>
    {
@@ -778,7 +728,7 @@
     * @param token
     * @return
     */
-   public String getHash(String token)
+   public String getLockTokenHash(String token)
    {
       String hash = "";
       try
@@ -795,11 +745,7 @@
    }
 
    /**
-    * Search lock in maps.
-    * 
-    * @param data
-    * @param searchType
-    * @return
+    * {@inheritDoc}
     */
    public LockData getLockData(NodeData data, int searchType)
    {
@@ -850,7 +796,8 @@
       }
       catch (RepositoryException e)
       {
-         //TODO
+         //TODO 
+         log.error(e.getMessage(), e);
          return null;
       }
 
@@ -981,9 +928,7 @@
    }
 
    /**
-    * Release all resources associated with CacheableSessionLockManager.
-    * 
-    * @param sessionID - session identifier
+    * {@inheritDoc}
     */
    public void closeSessionLockManager(String sessionID)
    {
@@ -1069,46 +1014,4 @@
       R execute(A arg) throws LockException;
    }
 
-   public LockData createLockData(NodeData node, String lockToken, boolean isDeep, boolean isSessionScoped,
-      String owner, long timeOut) throws LockException
-   {
-
-      LockData lData =
-         getLockData(node, CacheableLockManagerImpl.SEARCH_EXECMATCH | CacheableLockManagerImpl.SEARCH_CLOSEDPARENT);
-      if (lData != null)
-      {
-         if (lData.getNodeIdentifier().equals(node.getIdentifier()))
-         {
-            throw new LockException("Node already locked: " + node.getQPath());
-         }
-         else if (lData.isDeep())
-         {
-            throw new LockException("Parent node has deep lock.");
-         }
-      }
-
-      if (isDeep && getLockData(node, CacheableLockManagerImpl.SEARCH_CLOSEDCHILD) != null)
-      {
-         throw new LockException("Some child node is locked.");
-      }
-
-      String lockTokenHash = getHash(lockToken);
-
-      lData =
-         new LockData(node.getIdentifier(), lockTokenHash, isDeep, isSessionScoped, owner, timeOut > 0 ? timeOut
-            : getDefaultLockTimeOut());
-      return lData;
-   }
-
-   public LockData getExactOrCloseParentLock(NodeData node)
-   {
-      return getLockData(node, CacheableLockManagerImpl.SEARCH_EXECMATCH | CacheableLockManagerImpl.SEARCH_CLOSEDPARENT);
-
-   }
-
-   public boolean exactLockExist(NodeData node)
-   {
-      return getLockData(node, CacheableLockManagerImpl.SEARCH_EXECMATCH) != null;
-   }
-
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java	2010-02-05 07:07:32 UTC (rev 1692)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java	2010-02-05 10:28:45 UTC (rev 1693)
@@ -104,10 +104,34 @@
 
       String lockToken = IdGenerator.generate();
 
+      NodeData data = (NodeData)node.getData();
+
       LockData lData =
-         lockManager.createLockData((NodeData)node.getData(), lockToken, isDeep, isSessionScoped, node.getSession()
-            .getUserID(), timeOut);
+         lockManager
+            .getLockData(data, CacheableLockManager.SEARCH_EXECMATCH | CacheableLockManager.SEARCH_CLOSEDPARENT);
+      if (lData != null)
+      {
+         if (lData.getNodeIdentifier().equals(node.getIdentifier()))
+         {
+            throw new LockException("Node already locked: " + data.getQPath());
+         }
+         else if (lData.isDeep())
+         {
+            throw new LockException("Parent node has deep lock.");
+         }
+      }
 
+      if (isDeep && lockManager.getLockData(data, CacheableLockManager.SEARCH_CLOSEDCHILD) != null)
+      {
+         throw new LockException("Some child node is locked.");
+      }
+
+      String lockTokenHash = lockManager.getLockTokenHash(lockToken);
+
+      lData =
+         new LockData(node.getIdentifier(), lockTokenHash, isDeep, isSessionScoped, node.getSession().getUserID(),
+            timeOut > 0 ? timeOut : lockManager.getDefaultLockTimeOut());
+
       lockedNodes.put(node.getInternalIdentifier(), lData);
       pendingLocks.add(node.getInternalIdentifier());
       tokens.put(lockToken, lData.getTokenHash());
@@ -122,7 +146,7 @@
     */
    public void addLockToken(String lt)
    {
-      tokens.put(lt, lockManager.getHash(lt));
+      tokens.put(lt, lockManager.getLockTokenHash(lt));
    }
 
    /**
@@ -130,7 +154,9 @@
     */
    public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
    {
-      LockData lData = lockManager.getExactOrCloseParentLock((NodeData)node.getData());
+      LockData lData =
+         lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_EXECMATCH
+            | CacheableLockManager.SEARCH_CLOSEDPARENT);
 
       if (lData == null || (!node.getInternalIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
       {
@@ -154,7 +180,7 @@
     */
    public boolean holdsLock(NodeData node) throws RepositoryException
    {
-      return lockManager.exactLockExist(node);
+      return lockManager.getLockData(node, CacheableLockManager.SEARCH_EXECMATCH) != null;
    }
 
    /**
@@ -162,7 +188,9 @@
     */
    public boolean isLocked(NodeData node)
    {
-      LockData lData = lockManager.getExactOrCloseParentLock(node);
+      LockData lData =
+         lockManager
+            .getLockData(node, CacheableLockManager.SEARCH_EXECMATCH | CacheableLockManager.SEARCH_CLOSEDPARENT);
 
       if (lData == null || (!node.getIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
       {
@@ -176,7 +204,9 @@
     */
    public boolean isLockHolder(NodeImpl node) throws RepositoryException
    {
-      LockData lData = lockManager.getExactOrCloseParentLock((NodeData)node.getData());
+      LockData lData =
+         lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_EXECMATCH
+            | CacheableLockManager.SEARCH_CLOSEDPARENT);
 
       return lData != null && isLockHolder(lData);
    }
@@ -255,10 +285,20 @@
    }
 
    /**
-    * Returns real token, if session has it
+    * Is session contains pending lock for node by nodeId.
+    * @param nodeId - node ID string
+    * @return boolean
+    */
+   protected boolean cotainsPendingLock(String nodeId)
+   {
+      return pendingLocks.contains(nodeId);
+   }
+
+   /**
+    * Returns real token, if session has it.
     * 
-    * @param lockData
-    * @return
+    * @param tokenHash - token hash string
+    * @return lock token string
     */
    protected String getLockToken(String tokenHash)
    {
@@ -273,6 +313,24 @@
    }
 
    /**
+    * Return pending lock.
+    * 
+    * @param nodeId - ID of locked node
+    * @return pending lock or null
+    */
+   protected LockData getPendingLock(String nodeId)
+   {
+      if (pendingLocks.contains(nodeId))
+      {
+         return lockedNodes.get(nodeId);
+      }
+      else
+      {
+         return null;
+      }
+   }
+
+   /**
     * Check is lock alive. That means lock must exist in LockManager storage (cache or map, etc). 
     * 
     * @param nodeIdentifier - locked node id
@@ -291,15 +349,9 @@
       }
    }
 
-   /**
-    * Refresh lockData. 
-    * 
-    * @param newLockData
-    * @throws LockException
-    */
-   protected void refresh(LockData newLockData) throws LockException
+   protected void notifyLockPersisted(String nodeIdentifier)
    {
-      lockManager.refreshLockData(newLockData);
+      pendingLocks.remove(nodeIdentifier);
    }
 
    /**
@@ -312,27 +364,15 @@
       lockedNodes.remove(nodeIdentifier);
    }
 
-   protected void notifyLockPersisted(String nodeIdentifier)
+   /**
+    * Refresh lockData. 
+    * 
+    * @param newLockData
+    * @throws LockException
+    */
+   protected void refresh(LockData newLockData) throws LockException
    {
-      pendingLocks.remove(nodeIdentifier);
+      lockManager.refreshLockData(newLockData);
    }
 
-   protected boolean cotainsPendingLock(String nodeId)
-   {
-      return pendingLocks.contains(nodeId);
-   }
-
-   protected LockData getPendingLock(String nodeId)
-   {
-      //TODO check it 
-      if (pendingLocks.contains(nodeId))
-      {
-         return lockedNodes.get(nodeId);
-      }
-      else
-      {
-         return null;
-      }
-   }
-
 }



More information about the exo-jcr-commits mailing list