You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2019/11/13 14:58:09 UTC

[james-project] 08/09: [Refactoring] remove lock usage from JDBC has it uses transactions

This is an automated email from the ASF dual-hosted git repository.

matthieu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e918a1b73193bc4da75957e4c6a9832617bdf0bd
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Nov 12 23:06:25 2019 +0100

    [Refactoring] remove lock usage from JDBC has it uses transactions
---
 .../mailrepository/jdbc/JDBCMailRepository.java    | 52 +++-------------------
 1 file changed, 6 insertions(+), 46 deletions(-)

diff --git a/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java b/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
index b5a8e7b..6c1c06f 100644
--- a/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
+++ b/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
@@ -58,7 +58,6 @@ import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.mailrepository.api.MailKey;
 import org.apache.james.mailrepository.api.MailRepository;
-import org.apache.james.mailrepository.lib.Lock;
 import org.apache.james.repository.api.Initializable;
 import org.apache.james.repository.file.FilePersistentStreamRepository;
 import org.apache.james.server.core.MailImpl;
@@ -106,12 +105,6 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
     private static final boolean DEEP_DEBUG = false;
 
     /**
-     * A lock used to control access to repository elements, locking access
-     * based on the key
-     */
-    private final Lock lock = new Lock();
-
-    /**
      * The table name parsed from the destination URL
      */
     @VisibleForTesting
@@ -226,30 +219,21 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
 
     }
 
+
     /**
-     * Releases a lock on a message identified the key
-     *
-     * @param key
-     *            the key of the message to be unlocked
-     *
-     * @return true if successfully released the lock, false otherwise
+     * JDBC uses transaction, it doesn't need locks
      */
     @Override
     public boolean unlock(MailKey key) {
-        return lock.unlock(key);
+        return false;
     }
 
     /**
-     * Obtains a lock on a message identified by key
-     *
-     * @param key
-     *            the key of the message to be locked
-     *
-     * @return true if successfully obtained the lock, false otherwise
+     * JDBC uses transaction, it doesn't need locks
      */
     @Override
     public boolean lock(MailKey key) {
-        return lock.lock(key);
+        return false;
     }
 
 
@@ -403,16 +387,8 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
 
     @Override
     public MailKey store(Mail mc) throws MessagingException {
-        boolean wasLocked = true;
         MailKey key = MailKey.forMail(mc);
         try {
-            synchronized (this) {
-                wasLocked = lock.isLocked(key);
-                if (!wasLocked) {
-                    // If it wasn't locked, we want a lock during the store
-                    lock(key);
-                }
-            }
             internalStore(mc);
             return key;
         } catch (MessagingException e) {
@@ -421,14 +397,6 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
         } catch (Exception e) {
             LOGGER.error("Exception caught while storing mail {}", key, e);
             throw new MessagingException("Exception caught while storing mail " + key, e);
-        } finally {
-            if (!wasLocked) {
-                // If it wasn't locked, we need to unlock now
-                unlock(key);
-                synchronized (this) {
-                    notify();
-                }
-            }
         }
     }
 
@@ -760,15 +728,7 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
 
     @Override
     public void remove(MailKey key) throws MessagingException {
-        if (lock(key)) {
-            try {
-                internalRemove(key);
-            } finally {
-                unlock(key);
-            }
-        } else {
-            throw new MessagingException("Cannot lock " + key + " to remove it");
-        }
+        internalRemove(key);
     }
 
     private void internalRemove(MailKey key) throws MessagingException {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org