james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject cvs commit: jakarta-james/src/java/org/apache/james/mailrepository AvalonMailRepository.java AvalonSpoolRepository.java JDBCMailRepository.java JDBCSpoolRepository.java
Date Mon, 06 Aug 2001 04:14:13 GMT
serge       01/08/05 21:14:13

  Modified:    src/java/org/apache/james/mailrepository
                        AvalonMailRepository.java
                        AvalonSpoolRepository.java JDBCMailRepository.java
                        JDBCSpoolRepository.java
  Log:
  Fixed locking code... lock/unlock now return boolean, and lock object is private so the
repository's lock/unlock methods should be called instead.
  
  Revision  Changes    Path
  1.5       +15 -14    jakarta-james/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
  
  Index: AvalonMailRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/AvalonMailRepository.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AvalonMailRepository.java	2001/08/06 03:42:18	1.4
  +++ AvalonMailRepository.java	2001/08/06 04:14:13	1.5
  @@ -46,7 +46,7 @@
       extends AbstractLoggable
       implements MailRepository, Component, Configurable, Composable {
   
  -    protected Lock lock;
  +    private Lock lock;
       protected static boolean DEEP_DEBUG = false;
       private static final String TYPE = "MAIL";
       private Store store;
  @@ -93,7 +93,7 @@
               sr = (StreamRepository) store.select(streamConfiguration);
               or = (ObjectRepository) store.select(objectConfiguration);
               lock = new Lock();
  -	    getLogger().debug(this.getClass().getName() + " created in " + destination);
  +	        getLogger().debug(this.getClass().getName() + " created in " + destination);
           } catch (Exception e) {
               final String message = "Failed to retrieve Store component:" + e.getMessage();
               getLogger().error( message, e );
  @@ -101,21 +101,21 @@
           }
       }
   
  -    public synchronized void unlock(Object key) {
  -
  +    public synchronized boolean unlock(String key) {
           if (lock.unlock(key)) {
               notifyAll();
  +            return true;
           } else {
  -            throw new LockException("Your thread do not own the lock of record " + key);
  +            return false;
           }
       }
  -
  -    public synchronized void lock(Object key) {
   
  +    public synchronized boolean lock(String key) {
           if (lock.lock(key)) {
               notifyAll();
  +            return true;
           } else {
  -            throw new LockException("Record " + key + " already locked by another thread");
  +            return false;
           }
       }
   
  @@ -157,12 +157,13 @@
       }
   
       public void remove(String key) {
  -        try {
  -            lock( key);
  -            sr.remove(key);
  -            or.remove(key);
  -        } finally {
  -            unlock(key);
  +        if (lock(key)) {
  +            try {
  +                sr.remove(key);
  +                or.remove(key);
  +            } finally {
  +                unlock(key);
  +            }
           }
       }
   
  
  
  
  1.2       +24 -16    jakarta-james/src/java/org/apache/james/mailrepository/AvalonSpoolRepository.java
  
  Index: AvalonSpoolRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/AvalonSpoolRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AvalonSpoolRepository.java	2001/05/11 09:25:59	1.1
  +++ AvalonSpoolRepository.java	2001/08/06 04:14:13	1.2
  @@ -23,32 +23,34 @@
    *              type="MAIL"
    *              model="SYNCHRONOUS"/>
    * Requires a logger called MailRepository.
  - * 
  + *
    * @version 1.0.0, 24/04/1999
    * @author  Federico Barbieri <scoobie@pop.systemy.it>
    * @author Charles Benett <charles@benett1.demon.co.uk>
    */
  -public class AvalonSpoolRepository 
  -    extends AvalonMailRepository 
  +public class AvalonSpoolRepository
  +    extends AvalonMailRepository
       implements SpoolRepository {
   
       public synchronized String accept() {
  -	if (DEEP_DEBUG) getLogger().debug("Method accept() called");
  +    	if (DEEP_DEBUG) {
  +            getLogger().debug("Method accept() called");
  +        }
           while (true) {
               for(Iterator it = list(); it.hasNext(); ) {
  -                
  +
                   String s = it.next().toString();
  -		if (DEEP_DEBUG) getLogger().debug("Found item " + s
  +        		if (DEEP_DEBUG) {
  +                    getLogger().debug("Found item " + s
                                                     + " in spool.");
  -                if (lock.lock(s)) {
  -		    if (DEEP_DEBUG) getLogger().debug("accept() has locked: "
  +                }
  +                if (lock(s)) {
  +		            if (DEEP_DEBUG) {
  +                        getLogger().debug("accept() has locked: "
                                                         + s);
  +                    }
                       return s;
                   }
  -                //  Object o = it.next();
  -                //if (lock.lock(o)) {
  -                //  return o.toString();
  -                //}
               }
               try {
                   wait();
  @@ -58,16 +60,22 @@
       }
   
       public synchronized String accept(long delay) {
  -	if (DEEP_DEBUG) getLogger().debug("Method accept(delay) called");
  +	    if (DEEP_DEBUG) {
  +            getLogger().debug("Method accept(delay) called");
  +        }
           while (true) {
               long youngest = 0;
               for (Iterator it = list(); it.hasNext(); ) {
                   String s = it.next().toString();
  -		if (DEEP_DEBUG) getLogger().debug("Found item " + s
  +		        if (DEEP_DEBUG) {
  +                    getLogger().debug("Found item " + s
                                                     + " in spool.");
  -                if (lock.lock(s)) {
  -		    if (DEEP_DEBUG) getLogger().debug("accept(delay) has"
  +                }
  +                if (lock(s)) {
  +		            if (DEEP_DEBUG) {
  +                        getLogger().debug("accept(delay) has"
                                                         + " locked: "  + s);
  +                    }
                       //We have a lock on this object... let's grab the message
                       //  and see if it's a valid time.
                       MailImpl mail = retrieve(s);
  
  
  
  1.2       +23 -21    jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
  
  Index: JDBCMailRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCMailRepository.java	2001/08/06 03:42:18	1.1
  +++ JDBCMailRepository.java	2001/08/06 04:14:13	1.2
  @@ -69,7 +69,7 @@
       extends AbstractLoggable
       implements MailRepository, Component, Configurable, Composable {
   
  -    protected Lock lock;
  +    private Lock lock;
       protected String destination;
       protected String tableName;
       protected String repositoryName;
  @@ -151,19 +151,21 @@
           }
       }
   
  -    public synchronized void unlock(Object key) {
  +    public synchronized boolean unlock(String key) {
           if (lock.unlock(key)) {
               notifyAll();
  +            return true;
           } else {
  -            throw new LockException("Your thread does not own the lock of record " + key);
  +            return false;
           }
       }
   
  -    public synchronized void lock(Object key) {
  +    public synchronized boolean lock(String key) {
           if (lock.lock(key)) {
               notifyAll();
  +            return true;
           } else {
  -            throw new LockException("Record " + key + " already locked by another thread");
  +            return false;
           }
       }
   
  @@ -351,24 +353,24 @@
   
       public void remove(String key) {
           //System.err.println("removing " + key);
  -        try {
  -            lock(key);
  -
  -            Connection conn = getConnection();
  -            PreparedStatement removeMessage = conn.prepareStatement(sqlQueries.getProperty("removeMessageSQL"));
  -            removeMessage.setString(1, key);
  -            removeMessage.setString(2, repositoryName);
  -            removeMessage.execute();
  -            removeMessage.close();
  -            conn.close();
  +        if (lock(key)) {
  +            try {
  +                Connection conn = getConnection();
  +                PreparedStatement removeMessage = conn.prepareStatement(sqlQueries.getProperty("removeMessageSQL"));
  +                removeMessage.setString(1, key);
  +                removeMessage.setString(2, repositoryName);
  +                removeMessage.execute();
  +                removeMessage.close();
  +                conn.close();
   
  -            if (sr != null) {
  -                sr.remove(key);
  +                if (sr != null) {
  +                    sr.remove(key);
  +                }
  +            } catch (Exception me) {
  +                throw new RuntimeException("Exception while removing mail: " + me.getMessage());
  +            } finally {
  +                unlock(key);
               }
  -        } catch (Exception me) {
  -            throw new RuntimeException("Exception while removing mail: " + me.getMessage());
  -        } finally {
  -            unlock(key);
           }
       }
   
  
  
  
  1.2       +2 -2      jakarta-james/src/java/org/apache/james/mailrepository/JDBCSpoolRepository.java
  
  Index: JDBCSpoolRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/JDBCSpoolRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCSpoolRepository.java	2001/08/06 03:42:18	1.1
  +++ JDBCSpoolRepository.java	2001/08/06 04:14:13	1.2
  @@ -74,7 +74,7 @@
                   while (rsListMessages.next()) {
                       String message = rsListMessages.getString(1);
   
  -                    if (lock.lock(message)) {
  +                    if (lock(message)) {
                           rsListMessages.close();
                           listMessages.close();
                           conn.close();
  @@ -123,7 +123,7 @@
                           process = true;
                       }
   
  -                    if (process && lock.lock(message)) {
  +                    if (process && lock(message)) {
                           rsListMessages.close();
                           listMessages.close();
                           conn.close();
  
  
  

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


Mime
View raw message