jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r803509 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock: AbstractLockInfo.java LockInfo.java LockManagerImpl.java XAEnvironment.java XALockManager.java
Date Wed, 12 Aug 2009 13:50:07 GMT
Author: jukka
Date: Wed Aug 12 13:50:07 2009
New Revision: 803509

URL: http://svn.apache.org/viewvc?rev=803509&view=rev
Log:
JCR-1590: JSR 283: Locking

Another code cleanup step: Merge AbstractLockInfo to LockInfo.

Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java?rev=803509&r1=803508&r2=803509&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockInfo.java
Wed Aug 12 13:50:07 2009
@@ -22,78 +22,170 @@
 import javax.jcr.Session;
 
 /**
- * Lock information interface.
+ * Internal lock information.
  */
-public interface LockInfo {
+public abstract class LockInfo {
+
+    /**
+     * Constant for the undefined or infinite timeout.
+     */
+    static final long TIMEOUT_INFINITE = Long.MAX_VALUE;
+
+    /**
+     * Constant for the expired timeout.
+     */
+    static final long TIMEOUT_EXPIRED = -1;
+
+    /**
+     * Lock token
+     */
+    protected final LockToken lockToken;
+
+    /**
+     * Flag indicating whether lock is session scoped
+     */
+    protected final boolean sessionScoped;
+
+    /**
+     * Flag indicating whether lock is deep
+     */
+    protected final boolean deep;
+
+    /**
+     * Lock owner, determined on creation time
+     */
+    protected final String lockOwner;
+
+    /**
+     * Flag indicating whether this lock is live
+     */
+    private boolean live;
+
+    /**
+     * Session currently holding lock
+     */
+    private SessionImpl lockHolder;
+
+    /**
+     * Create a new instance of this class.
+     *
+     * @param lockToken     lock token
+     * @param sessionScoped whether lock token is session scoped
+     * @param deep          whether lock is deep
+     * @param lockOwner     owner of lock
+     */
+    protected LockInfo(LockToken lockToken, boolean sessionScoped, boolean deep,
+                    String lockOwner) {
+        this(lockToken, sessionScoped, deep, lockOwner, TIMEOUT_INFINITE);
+    }
+
+    /**
+     * Create a new instance of this class.
+     *
+     * @param lockToken     lock token
+     * @param sessionScoped whether lock token is session scoped
+     * @param deep          whether lock is deep
+     * @param lockOwner     owner of lock
+     * @param timeoutHint   the timeoutHint
+     */
+    protected LockInfo(LockToken lockToken, boolean sessionScoped, boolean deep,
+                            String lockOwner, long timeoutHint) {
+        this.lockToken = lockToken;
+        this.sessionScoped = sessionScoped;
+        this.deep = deep;
+        this.lockOwner = lockOwner;
+        // TODO: TOBEFIXED for 2.0 respect and deal with timeout hint.
+    }
+
+    /**
+     * Return the lock token associated with this lock.
+     *
+     * @return lock token
+     */
+    public LockToken getLockToken() {
+        return lockToken;
+    }
 
     /**
      * Return the ID of the lock holding node
      * @return the id
      */
-    public NodeId getId();
-    
+    public NodeId getId() {
+        return lockToken.getId();
+    }
+
     /**
      * Return the lock owner.
      * 
      * @return lock owner
      */
-    public String getLockOwner();
-    
+    public String getLockOwner() {
+        return lockOwner;
+    }
+
     /**
      * Return a flag indicating whether the lock is deep.
      * 
      * @return <code>true</code> if the lock is deep;
      *         <code>false</code> otherwise
      */
-    public boolean isDeep();
-    
+    public boolean isDeep() {
+        return deep;
+    }
+
     /**
      * Return a flag indicating whether the session given is lock holder. 
      *
      * @param session session to compare with
      */
-    public boolean isLockHolder(Session session);
+    public boolean isLockHolder(Session session) {
+        return lockHolder == session;
+    }
 
     /**
      * Return the session currently holding the lock
      *
      * @return session currently holding the lock
      */
-    SessionImpl getLockHolder();
+    public SessionImpl getLockHolder() {
+        return lockHolder;
+    }
 
     /**
      * Set the session currently holding the lock
      *
      * @param lockHolder session currently holding the lock
      */
-    void setLockHolder(SessionImpl lockHolder);
-
-    /**
-     * Return the lock token associated with this lock.
-     *
-     * @return lock token
-     */
-    LockToken getLockToken();
+    public void setLockHolder(SessionImpl lockHolder) {
+        this.lockHolder = lockHolder;
+    }
 
     /**
      * Return a flag indicating whether the lock is live
      *
      * @return <code>true</code> if the lock is live; otherwise <code>false</code>
      */
-    public boolean isLive();
+    public boolean isLive() {
+        return live;
+    }
 
     /**
      * Set the live flag
+     *
      * @param live live flag
      */
-    void setLive(boolean live);
+    public void setLive(boolean live) {
+        this.live = live;
+    }
 
     /**
      * Return a flag indicating whether the lock information may still change.
      *
      * @return <code>true</code> if the lock is still alive.
      */
-    boolean mayChange();
+    public boolean mayChange() {
+        return live;
+    }
 
     /**
      * Return a flag indicating whether the lock is session-scoped
@@ -101,13 +193,42 @@
      * @return <code>true</code> if the lock is session-scoped;
      *         otherwise <code>false</code>
      */
-    public boolean isSessionScoped();
+    public boolean isSessionScoped() {
+        return sessionScoped;
+    }
 
     /**
      * Return the number of seconds remaining until the lock expires.
      *
      * @return number of seconds remaining until the lock expires.
      */
-    public long getSecondsRemaining();
+    public long getSecondsRemaining() {
+        // TODO: TOBEFIXED for 2.0
+        // TODO  - add support for timeout specified by the API user -> LockManager#lock
+        return isLive() ? TIMEOUT_INFINITE : TIMEOUT_EXPIRED;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append('(');
+        if (deep) {
+            buffer.append("deep ");
+        }
+        if (sessionScoped) {
+            buffer.append("session ");
+        }
+        buffer.append("holder:");
+        if (lockHolder != null) {
+            buffer.append(lockHolder.getUserID());
+        } else {
+            buffer.append("none");
+        }
+        buffer.append("owner:").append(lockOwner);
+        buffer.append(')');
+        return buffer.toString();
+    }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?rev=803509&r1=803508&r2=803509&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
Wed Aug 12 13:50:07 2009
@@ -293,9 +293,9 @@
      * @throws LockException       if the node is already locked
      * @throws RepositoryException if another error occurs
      */
-    AbstractLockInfo internalLock(NodeImpl node, boolean isDeep,
-                                  boolean isSessionScoped, long timeoutHint,
-                                  String ownerInfo)
+    LockInfo internalLock(
+            NodeImpl node, boolean isDeep, boolean isSessionScoped,
+            long timeoutHint, String ownerInfo)
             throws LockException, RepositoryException {
 
         SessionImpl session = (SessionImpl) node.getSession();
@@ -424,7 +424,7 @@
                 }
             }
         }, false);
-        return infos.toArray(new AbstractLockInfo[infos.size()]);
+        return infos.toArray(new LockInfo[infos.size()]);
     }
 
     /**
@@ -464,12 +464,12 @@
      */
     public Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped)
             throws LockException, RepositoryException {
-        return lock(node, isDeep, isSessionScoped, AbstractLockInfo.TIMEOUT_INFINITE, null);
+        return lock(node, isDeep, isSessionScoped, LockInfo.TIMEOUT_INFINITE, null);
     }
 
     public Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timoutHint,
String ownerInfo)
             throws LockException, RepositoryException {
-        AbstractLockInfo info = internalLock(node, isDeep, isSessionScoped, timoutHint, ownerInfo);
+        LockInfo info = internalLock(node, isDeep, isSessionScoped, timoutHint, ownerInfo);
         writeLockProperties(node, info.lockOwner, info.deep);
 
         return new LockImpl(info, node);
@@ -1164,7 +1164,7 @@
      * Contains information about a lock and gets placed inside the child
      * information of a {@link org.apache.jackrabbit.spi.commons.name.PathMap}.
      */
-    class InternalLockInfo extends AbstractLockInfo implements SessionListener {
+    class InternalLockInfo extends LockInfo implements SessionListener {
 
         /**
          * Create a new instance of this class.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java?rev=803509&r1=803508&r2=803509&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
Wed Aug 12 13:50:07 2009
@@ -110,7 +110,7 @@
      */
     public LockInfo lock(NodeImpl node, boolean isDeep, boolean isSessionScoped)
             throws LockException, RepositoryException {
-        return lock(node, isDeep, isSessionScoped, AbstractLockInfo.TIMEOUT_INFINITE, null);
+        return lock(node, isDeep, isSessionScoped, LockInfo.TIMEOUT_INFINITE, null);
     }
 
     /**
@@ -423,7 +423,7 @@
     /**
      * Information about a lock used inside transactions.
      */
-    class XALockInfo extends AbstractLockInfo {
+    class XALockInfo extends LockInfo {
 
         /**
          * Node being locked/unlocked.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java?rev=803509&r1=803508&r2=803509&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
Wed Aug 12 13:50:07 2009
@@ -65,7 +65,7 @@
      */
     public Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped)
             throws LockException, RepositoryException {
-        return lock(node, isDeep, isSessionScoped, AbstractLockInfo.TIMEOUT_INFINITE, null);
+        return lock(node, isDeep, isSessionScoped, LockInfo.TIMEOUT_INFINITE, null);
     }
 
     /**



Mime
View raw message