jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r558172 - in /jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: cluster/ lock/
Date Fri, 20 Jul 2007 22:10:20 GMT
Author: jukka
Date: Fri Jul 20 15:10:17 2007
New Revision: 558172

URL: http://svn.apache.org/viewvc?view=rev&rev=558172
Log:
1.3: Merged revision 546038 (JCR-929)

Added:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractClusterOperation.java
      - copied unchanged from r546038, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractClusterOperation.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterOperation.java
      - copied unchanged from r546038, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterOperation.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/LockOperation.java
      - copied unchanged from r546038, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/LockOperation.java
Modified:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/LockEventChannel.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?view=diff&rev=558172&r1=558171&r2=558172
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Fri Jul 20 15:10:17 2007
@@ -677,64 +677,46 @@
         /**
          * {@inheritDoc}
          */
-        public void locked(NodeId nodeId, boolean deep, String owner) {
+        public ClusterOperation create(NodeId nodeId, boolean deep, String owner) {
             if (status != STARTED) {
                 log.info("not started: lock operation ignored.");
-                return;
+                return null;
             }
-            Record record = null;
-            boolean succeeded = false;
-
             try {
-                record = journal.getProducer(PRODUCER_ID).append();
-                record.writeString(workspace);
-                write(record, nodeId, deep, owner);
-                record.writeChar('\0');
-                record.update();
-                setRevision(record.getRevision());
-                succeeded = true;
+                Record record = journal.getProducer(PRODUCER_ID).append();
+                return new LockOperation(ClusterNode.this, workspace, record,
+                        nodeId, deep, owner);
             } catch (JournalException e) {
                 String msg = "Unable to create log entry: " + e.getMessage();
                 log.error(msg);
+                return null;
             } catch (Throwable e) {
                 String msg = "Unexpected error while creating log entry.";
                 log.error(msg, e);
-            } finally {
-                if (!succeeded && record != null) {
-                    record.cancelUpdate();
-                }
+                return null;
             }
         }
 
         /**
          * {@inheritDoc}
          */
-        public void unlocked(NodeId nodeId) {
+        public ClusterOperation create(NodeId nodeId) {
             if (status != STARTED) {
                 log.info("not started: unlock operation ignored.");
-                return;
+                return null;
             }
-            Record record = null;
-            boolean succeeded = false;
-
             try {
-                record = journal.getProducer(PRODUCER_ID).append();
-                record.writeString(workspace);
-                write(record, nodeId);
-                record.writeChar('\0');
-                record.update();
-                setRevision(record.getRevision());
-                succeeded = true;
+                Record record = journal.getProducer(PRODUCER_ID).append();
+                return new LockOperation(ClusterNode.this, workspace, record,
+                        nodeId);
             } catch (JournalException e) {
                 String msg = "Unable to create log entry: " + e.getMessage();
                 log.error(msg);
+                return null;
             } catch (Throwable e) {
                 String msg = "Unexpected error while creating log entry.";
                 log.error(msg, e);
-            } finally {
-                if (!succeeded && record != null) {
-                    record.cancelUpdate();
-                }
+                return null;
             }
         }
 
@@ -1182,18 +1164,6 @@
         record.writeString(uri);
     }
 
-    private static void write(Record record, NodeId nodeId, boolean isDeep, String owner)
-            throws JournalException {
-
-        write(record, nodeId, true, isDeep, owner);
-    }
-
-    private static void write(Record record, NodeId nodeId)
-            throws JournalException {
-
-        write(record, nodeId, false, false, null);
-    }
-
     private static void write(Record record, Collection c, boolean register)
             throws JournalException {
 
@@ -1268,16 +1238,40 @@
         record.writeString(event.getUserId());
     }
 
-    private static void write(Record record, NodeId nodeId, boolean isLock,
-                              boolean isDeep, String owner)
-            throws JournalException {
+    /**
+     * Invoked when a cluster operation has ended. If <code>successful</code>,
+     * attempts to fill the journal record and update it, otherwise cancels
+     * the update.
+     *
+     * @param operation cluster operation
+     * @param successful <code>true</code> if the operation was successful and
+     *                   the journal record should be updated;
+     *                   <code>false</code> to revoke changes
+     */
+    public void ended(AbstractClusterOperation operation, boolean successful) {
+        Record record = operation.getRecord();
+        boolean succeeded = false;
 
-        record.writeChar('L');
-        record.writeNodeId(nodeId);
-        record.writeBoolean(isLock);
-        if (isLock) {
-            record.writeBoolean(isDeep);
-            record.writeString(owner);
+        try {
+            if (successful) {
+                record = operation.getRecord();
+                record.writeString(operation.getWorkspace());
+                operation.write();
+                record.writeChar('\0');
+                record.update();
+                setRevision(record.getRevision());
+                succeeded = true;
+            }
+        } catch (JournalException e) {
+            String msg = "Unable to create log entry: " + e.getMessage();
+            log.error(msg);
+        } catch (Throwable e) {
+            String msg = "Unexpected error while creating log entry.";
+            log.error(msg, e);
+        } finally {
+            if (!succeeded) {
+                record.cancelUpdate();
+            }
         }
     }
 }

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/LockEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/LockEventChannel.java?view=diff&rev=558172&r1=558171&r2=558172
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/LockEventChannel.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/LockEventChannel.java
Fri Jul 20 15:10:17 2007
@@ -24,20 +24,27 @@
 public interface LockEventChannel {
 
     /**
-     * Called when a node has been locked.
+     * Create a new cluster operation that should be used to inform other
+     * instances in the cluster. Called when a node is about to be
+     * locked. 
      *
      * @param nodeId node id
      * @param deep flag indicating whether lock is deep
      * @param owner lock owner
+     * @return cluster operation or <code>null</code> if the cluster node
+     *         is not started or some error occurs
      */
-    public void locked(NodeId nodeId, boolean deep, String owner);
+    public ClusterOperation create(NodeId nodeId, boolean deep, String owner);
 
     /**
-     * Called when a node has been unlocked.
+     * Create a new cluster operation  that should be used to inform other
+     * instances in the cluster. Called when a node has been unlocked.
      *
      * @param nodeId node id
+     * @return cluster operation or <code>null</code> if the cluster node
+     *         is not started or some error occurs
      */
-    public void unlocked(NodeId nodeId);
+    public ClusterOperation create(NodeId nodeId);
 
     /**
      * Set listener that will receive information about incoming, external lock events.

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java?view=diff&rev=558172&r1=558171&r2=558172
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
Fri Jul 20 15:10:17 2007
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.core.cluster;
 
-import org.apache.jackrabbit.core.state.ChangeLog;
-import org.apache.jackrabbit.core.state.SharedItemStateManager;
-import org.apache.jackrabbit.core.observation.EventStateCollection;
-
 /**
  * Event channel used to transmit update operations.
  */

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?view=diff&rev=558172&r1=558171&r2=558172
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
Fri Jul 20 15:10:17 2007
@@ -27,6 +27,7 @@
 import org.apache.jackrabbit.core.util.Dumpable;
 import org.apache.jackrabbit.core.cluster.LockEventChannel;
 import org.apache.jackrabbit.core.cluster.LockEventListener;
+import org.apache.jackrabbit.core.cluster.ClusterOperation;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
@@ -261,6 +262,14 @@
         LockInfo info = new LockInfo(new LockToken(node.getNodeId()),
                 isSessionScoped, isDeep, session.getUserID());
 
+        ClusterOperation operation = null;
+        boolean successful = false;
+
+        // Cluster is only informed about open-scoped locks
+        if (eventChannel != null && !isSessionScoped) {
+            operation = eventChannel.create(node.getNodeId(), isDeep, session.getUserID());
+        }
+
         acquire();
 
         try {
@@ -289,15 +298,16 @@
             lockMap.put(path, info);
 
             if (!info.sessionScoped) {
-                if (eventChannel != null) {
-                    eventChannel.locked(node.getNodeId(), isDeep, session.getUserID());
-                }
                 save();
+                successful = true;
             }
             return info;
 
         } finally {
             release();
+            if (operation != null) {
+                operation.ended(successful);
+            }
         }
     }
 
@@ -310,6 +320,13 @@
     void internalUnlock(NodeImpl node)
             throws LockException, RepositoryException {
 
+        ClusterOperation operation = null;
+        boolean successful = false;
+
+        if (eventChannel != null) {
+            operation = eventChannel.create(node.getNodeId());
+        }
+        
         acquire();
 
         try {
@@ -334,14 +351,15 @@
             info.setLive(false);
 
             if (!info.sessionScoped) {
-                if (eventChannel != null) {
-                    eventChannel.unlocked(node.getNodeId());
-                }
                 save();
+                successful = true;
             }
-
         } finally {
             release();
+
+            if (operation != null) {
+                operation.ended(successful);
+            }
         }
     }
 



Mime
View raw message