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 ba...@apache.org on 2005/09/07 17:44:00 UTC
svn commit: r279353 - in
/james/server/trunk/src/java/org/apache/james/mailrepository:
AvalonMailRepository.java JDBCMailRepository.java JDBCSpoolRepository.java
Author: bago
Date: Wed Sep 7 08:43:55 2005
New Revision: 279353
URL: http://svn.apache.org/viewcvs?rev=279353&view=rev
Log:
Fix for repository locks/notification/synchronization.
I've done stress-test and test with Thread.sleep() after the notifications to ensure it is working but this is delicate and we should test it more.
Modified:
james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
james/server/trunk/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
james/server/trunk/src/java/org/apache/james/mailrepository/JDBCSpoolRepository.java
Modified: james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java?rev=279353&r1=279352&r2=279353&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java Wed Sep 7 08:43:55 2005
@@ -254,7 +254,7 @@
if (!wasLocked) {
//If it wasn't locked, we want a lock during the store
- lock.lock(key);
+ lock(key);
}
}
try {
@@ -301,8 +301,8 @@
or.put(key, mc);
} finally {
if (!wasLocked) {
- //If it wasn't locked, we need to now unlock
- lock.unlock(key);
+ // If it wasn't locked, we need to unlock now
+ unlock(key);
}
}
@@ -315,10 +315,6 @@
getLogger().debug(logBuffer.toString());
}
- synchronized (this) {
-// notifyAll();
- notify();
- }
} catch (Exception e) {
getLogger().error("Exception storing mail: " + e);
throw new MessagingException("Exception caught while storing Message Container: " + e);
Modified: james/server/trunk/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/mailrepository/JDBCMailRepository.java?rev=279353&r1=279352&r2=279353&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailrepository/JDBCMailRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailrepository/JDBCMailRepository.java Wed Sep 7 08:43:55 2005
@@ -109,13 +109,6 @@
*/
private Lock lock;
- // Configuration elements
-
- /**
- * Destination URL for the repository. See class description for more info
- */
-// protected String destination;
-
/**
* The table name parsed from the destination URL
*/
@@ -127,11 +120,6 @@
protected String repositoryName;
/**
- * The name of the filestore to be used to store mail when configured to use dbfile mode.
- */
-// protected String filestore;
-
- /**
* The name of the SQL configuration file to be used to configure this repository.
*/
private String sqlFileName;
@@ -141,8 +129,6 @@
*/
private StreamRepository sr = null;
- //The data-source for this repository
-
/**
* The selector used to obtain the JDBC datasource
*/
@@ -494,7 +480,7 @@
*
* @return true if successfully released the lock, false otherwise
*/
- public synchronized boolean unlock(String key) {
+ public boolean unlock(String key) {
if (lock.unlock(key)) {
if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
StringBuffer debugBuffer =
@@ -507,7 +493,9 @@
.append(new java.util.Date(System.currentTimeMillis()));
getLogger().debug(debugBuffer.toString());
}
-// notifyAll();
+ synchronized (this) {
+ notify();
+ }
return true;
} else {
return false;
@@ -521,7 +509,7 @@
*
* @return true if successfully obtained the lock, false otherwise
*/
- public synchronized boolean lock(String key) {
+ public boolean lock(String key) {
if (lock.lock(key)) {
if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
StringBuffer debugBuffer =
@@ -546,7 +534,17 @@
*/
public void store(MailImpl mc) throws MessagingException {
Connection conn = null;
+ boolean wasLocked = true;
+ String key = mc.getName();
try {
+ synchronized(this) {
+ wasLocked = lock.isLocked(key);
+
+ if (!wasLocked) {
+ //If it wasn't locked, we want a lock during the store
+ lock(key);
+ }
+ }
conn = datasource.getConnection();
//Need to determine whether need to insert this record, or update it.
@@ -767,14 +765,14 @@
conn.commit();
conn.setAutoCommit(true);
- synchronized (this) {
-// notifyAll();
- notify();
- }
} catch (Exception e) {
throw new MessagingException("Exception caught while storing mail Container: " + e);
} finally {
theJDBCUtil.closeJDBCConnection(conn);
+ if (!wasLocked) {
+ // If it wasn't locked, we need to unlock now
+ unlock(key);
+ }
}
}
Modified: james/server/trunk/src/java/org/apache/james/mailrepository/JDBCSpoolRepository.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/mailrepository/JDBCSpoolRepository.java?rev=279353&r1=279352&r2=279353&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailrepository/JDBCSpoolRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailrepository/JDBCSpoolRepository.java Wed Sep 7 08:43:55 2005
@@ -28,7 +28,6 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
import java.util.LinkedList;
/**
@@ -120,7 +119,7 @@
/**
* Return a message to process. This is a message in the spool that is not locked.
*/
- public Mail accept() throws InterruptedException {
+ public synchronized Mail accept() throws InterruptedException {
return accept(new SpoolRepository.AcceptFilter () {
public boolean accept (String _, String __, long ___, String ____) {
return true;
@@ -164,7 +163,9 @@
public long getWaitTime () {
if (sleepUntil == 0) {
- sleepUntil = System.currentTimeMillis();
+ // in AvalonSpoolRepository we return 0: why do we change sleepUntil?
+ // sleepUntil = System.currentTimeMillis();
+ return 0;
}
long waitTime = sleepUntil - System.currentTimeMillis();
sleepUntil = 0;
@@ -217,9 +218,7 @@
wait_time = WAIT_LIMIT;
}
try {
- synchronized (this) {
- wait (wait_time);
- }
+ wait (wait_time);
} catch (InterruptedException ex) {
throw ex;
}
@@ -244,7 +243,6 @@
* it's been more than 1 second (should be configurable).
*/
private PendingMessage getNextPendingMessage() {
- //System.err.println("Trying to get next message in " + repositoryName);
synchronized (pendingMessages) {
if (pendingMessages.size() == 0 && pendingMessagesLoadTime < System.currentTimeMillis()) {
pendingMessagesLoadTime = LOAD_TIME_MININUM + System.currentTimeMillis();
@@ -254,7 +252,6 @@
if (pendingMessages.size() == 0) {
return null;
} else {
- //System.err.println("Returning a pending message in " + repositoryName);
return (PendingMessage)pendingMessages.removeFirst();
}
}
@@ -265,7 +262,6 @@
*/
private void loadPendingMessages() {
//Loads a vector with PendingMessage objects
- //System.err.println("loading pending messages in " + repositoryName);
synchronized (pendingMessages) {
pendingMessages.clear();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org