[jbosscache-commits] JBoss Cache SVN: r5889 - in core/trunk/src/main/java/org/jboss/cache: lock and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue May 27 10:43:21 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-05-27 10:43:21 -0400 (Tue, 27 May 2008)
New Revision: 5889

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
   core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
Log:
Fixed broken behaviour

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java	2008-05-27 13:28:31 UTC (rev 5888)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java	2008-05-27 14:43:21 UTC (rev 5889)
@@ -111,14 +111,14 @@
    @SuppressWarnings("unchecked")
    protected WorkspaceNode lockAndCreateWorkspaceNode(NodeFactory nodeFactory, NodeSPI node, TransactionWorkspace workspace, GlobalTransaction gtx, long timeout)
    {
-      boolean locked = lockManager.lock(node.getFqn(), READ, gtx, timeout);
+      boolean locked = lockManager.lock(node, READ, gtx, timeout);
 
       if (!locked)
          throw new TimeoutException("Unable to lock node " + node.getFqn() + " after timeout " + timeout + " for copying into workspace");
 
       WorkspaceNode wn = nodeFactory.createWorkspaceNode(node, workspace);
 
-      lockManager.unlock(node.getFqn(), gtx);
+      lockManager.unlock(node, gtx);
       return wn;
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java	2008-05-27 13:28:31 UTC (rev 5888)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java	2008-05-27 14:43:21 UTC (rev 5889)
@@ -47,6 +47,17 @@
    boolean lock(Fqn fqn, LockType lockType, Object owner, long timeout);
 
    /**
+    * As {@link #lock(org.jboss.cache.Fqn, LockType, Object, long)} except that a NodeSPI is passed in instead of an Fqn.
+    *
+    * @param node     node to lock
+    * @param lockType type of lock to acquire
+    * @param owner    owner to acquire the lock for
+    * @param timeout  maximum length of time to wait for (in millis)
+    * @return true if the lock was acquired, false otherwise.
+    */
+   boolean lock(NodeSPI node, LockType lockType, Object owner, long timeout);
+
+   /**
     * Acquires a lock of type lockType, on a specific Node in the cache, denoted by fqn.  This
     * method will try for a period of time and give up if it is unable to acquire the required lock.  The period of time
     * is specified in {@link org.jboss.cache.config.Option#getLockAcquisitionTimeout()} and, if this is unset, the default timeout
@@ -88,18 +99,18 @@
    /**
     * Releases the lock passed in, held by the specified owner
     *
-    * @param lock  NodeLock to unlock
+    * @param fqn   Fqn of the node to unlock
     * @param owner lock owner
     */
-   void unlock(NodeLock lock, Object owner);
+   void unlock(Fqn fqn, Object owner);
 
    /**
     * Releases the lock passed in, held by the specified owner
     *
-    * @param fqn   Fqn of the node to unlock
+    * @param node  Node to unlock
     * @param owner lock owner
     */
-   void unlock(Fqn fqn, Object owner);
+   void unlock(NodeSPI node, Object owner);
 
    /**
     * Releases locks present in an invocation context and transaction entry, if one is available.

Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java	2008-05-27 13:28:31 UTC (rev 5888)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java	2008-05-27 14:43:21 UTC (rev 5889)
@@ -60,6 +60,7 @@
 
    private NodeLock acquireLock(NodeSPI node, LockType lockType, Object owner, long timeout)
    {
+      if (node == null) return null;
       NodeLock lock = node.getLock();
       boolean acquired = false;
       try
@@ -92,6 +93,12 @@
       return acquireLock(fqn, lockType, owner, timeout) != null;
    }
 
+   public boolean lock(NodeSPI node, LockType lockType, Object owner, long timeout)
+   {
+      return acquireLock(node, lockType, owner, timeout) != null;
+   }
+
+
    public boolean lockAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx)
    {
       return lockAndRecord(dataContainer.peek(fqn), lockType, ctx);
@@ -121,11 +128,12 @@
    public void unlock(InvocationContext ctx)
    {
       List<NodeLock> locks = ctx.getTransactionEntry() != null ? ctx.getTransactionEntry().getLocks() : ctx.getInvocationLocksAcquired();
+      if (locks == null || locks.isEmpty()) return;
 
       Object owner = getLockOwner(ctx);
       // Copying out to an array is faster than creating an ArrayList and iterating,
       // since list creation will just copy out to an array internally
-      IdentityLock[] lockArray = locks.toArray(new IdentityLock[locks.size()]);
+      NodeLock[] lockArray = locks.toArray(new NodeLock[locks.size()]);
       for (int i = lockArray.length - 1; i >= 0; i--)
       {
          if (trace)
@@ -135,7 +143,7 @@
       locks.clear();
    }
 
-   public void unlock(NodeLock lock, Object owner)
+   private void unlock(NodeLock lock, Object owner)
    {
       if (trace) log.trace("releasing lock for " + lock.getFqn() + " (" + lock + "), owner " + owner);
       lock.release(owner);
@@ -146,6 +154,11 @@
       unlock(dataContainer.peek(fqn).getLock(), owner);
    }
 
+   public void unlock(NodeSPI node, Object owner)
+   {
+      unlock(node.getLock(), owner);
+   }
+
    public boolean lockAll(NodeSPI node, LockType lockType, Object owner)
    {
       return lockAll(node, lockType, owner, lockAcquisitionTimeout, false);
@@ -168,6 +181,7 @@
     */
    private List<NodeLock> lockAllNodes(NodeSPI node, LockType lockType, Object owner, long timeout, boolean excludeInternalFqns)
    {
+      if (node == null) return null;
       List<NodeLock> locks = null;
       try
       {




More information about the jbosscache-commits mailing list