james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject cvs commit: jakarta-james/src/java/org/apache/james/transport/mailets RemoteDelivery.java
Date Fri, 01 Mar 2002 15:58:40 GMT
danny       02/03/01 07:58:40

  Modified:    src/java/org/apache/james/mailrepository
                        AvalonMailRepository.java
                        AvalonSpoolRepository.java
               src/java/org/apache/james/remotemanager RemoteManager.java
               src/java/org/apache/james/smtpserver SMTPServer.java
               src/java/org/apache/james/transport JamesSpoolManager.java
                        LinearProcessor.java
               src/java/org/apache/james/transport/mailets
                        RemoteDelivery.java
  Log:
  patches suplied by Steve Short [Steve.Short@PostX.com] toAdd mailet shutdown. Prevent tight
loop in RemoteDelivery on unexpected exceptions, removes message from outgoing queue. Prevent
ConcurrentModificationException in AvalonMailRepository by cloning key sey before returning
iterator. Added the dispose method to SMTPServer.java and RemoteManager.java for NT socket
release issue. Changed JamesSpoolManager to throw instead of system.exit for bad init mailet.
Thanks Steve :-)
  
  Revision  Changes    Path
  1.13      +5 -1      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AvalonMailRepository.java	18 Jan 2002 02:48:36 -0000	1.12
  +++ AvalonMailRepository.java	1 Mar 2002 15:58:39 -0000	1.13
  @@ -242,6 +242,10 @@
       }
   
       public Iterator list() {
  -        return keys.iterator();
  +//  Fix ConcurrentModificationException by cloning the keyset before getting an iterator
  +//        return keys.iterator();
  +        final HashSet clone = new HashSet();
  +        clone.addAll( keys );
  +        return clone.iterator();
       }
   }
  
  
  
  1.5       +4 -1      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AvalonSpoolRepository.java	18 Jan 2002 02:48:36 -0000	1.4
  +++ AvalonSpoolRepository.java	1 Mar 2002 15:58:39 -0000	1.5
  @@ -56,6 +56,7 @@
                   wait();
               } catch (InterruptedException ignored) {
               } catch (ConcurrentModificationException ignoredAlso) {
  +               // Should never get here now that list methods clones keyset for iterator
               }
           }
       }
  @@ -107,7 +108,9 @@
                       wait(youngest - System.currentTimeMillis());
                   }
               } catch (InterruptedException ignored) {
  +            } catch (ConcurrentModificationException ignoredAlso) {
  +               // Should never get here now that list methods clones keyset for iterator
               }
  -        }
  +}
       }
   }
  
  
  
  1.4       +12 -1     jakarta-james/src/java/org/apache/james/remotemanager/RemoteManager.java
  
  Index: RemoteManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/remotemanager/RemoteManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RemoteManager.java	27 Feb 2002 05:06:35 -0000	1.3
  +++ RemoteManager.java	1 Mar 2002 15:58:39 -0000	1.4
  @@ -67,5 +67,16 @@
           super.initialize();
           getLogger().info("RemoteManager ...init end");
       }
  -}
   
  +    public void dispose()
  +    {
  +    	getLogger().info( "RemoteManager dispose..." );
  +    	getLogger().info( "RemoteManager dispose..." + m_connectionName);
  +    	super.dispose();
  +       
  +        // This is needed to make sure that sockets are released promptly on Windows 2000
  +	System.gc();
  +	
  +	getLogger().info( "RemoteManager ...dispose end" );
  +    }
  +}
  
  
  
  1.4       +12 -0     jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java
  
  Index: SMTPServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SMTPServer.java	27 Feb 2002 05:06:47 -0000	1.3
  +++ SMTPServer.java	1 Mar 2002 15:58:40 -0000	1.4
  @@ -63,5 +63,17 @@
           getLogger().info("SMTPServer ...init end");
           System.out.println("Started SMTP Server "+m_connectionName);
       }
  +    
  +    public void dispose()
  +    {
  +    	getLogger().info( "SMTPServer dispose..." );
  +    	getLogger().info( "SMTPServer dispose..." + m_connectionName);
  +    	super.dispose();
  +       
  +        // This is needed to make sure sockets are promptly closed on Windows 2000
  +	System.gc();
  +	
  +	getLogger().info( "SMTPServer ...dispose end" );
  +    }
   }
   
  
  
  
  1.9       +21 -9     jakarta-james/src/java/org/apache/james/transport/JamesSpoolManager.java
  
  Index: JamesSpoolManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/JamesSpoolManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JamesSpoolManager.java	18 Jan 2002 02:48:37 -0000	1.8
  +++ JamesSpoolManager.java	1 Mar 2002 15:58:40 -0000	1.9
  @@ -30,13 +30,14 @@
   
   import javax.mail.MessagingException;
   import java.util.HashMap;
  +import java.util.Iterator;
   
   /**
    * @author Serge Knystautas <sergek@lokitech.com>
    * @author Federico Barbieri <scoobie@systemy.it>
    *
  - * This is $Revision: 1.8 $
  - * Committed on $Date: 2002/01/18 02:48:37 $ by: $Author: darrell $
  + * This is $Revision: 1.9 $
  + * Committed on $Date: 2002/03/01 15:58:40 $ by: $Author: danny $
    */
   public class JamesSpoolManager
       extends AbstractLogEnabled
  @@ -142,9 +143,9 @@
                                              + matcherName + ": " + ex.toString(), ex );
                           System.err.println("Unable to init mailet " + matcherName);
                           System.err.println("Check spool manager logs for more details.");
  -                        //ex.printStackTrace();
  -                        System.exit(1);
  -                        //throw ex;
  +                        ex.printStackTrace();
  +                        //System.exit(1);
  +                        throw ex;
                       }
                       try {
                           mailet = mailetLoader.getMailet(mailetClassName,
  @@ -157,9 +158,9 @@
                                             + mailetClassName + ": " + ex.getMessage());
                           System.err.println("Unable to init mailet " + mailetClassName);
                           System.err.println("Check spool manager logs for more details.");
  -                        //ex.printStackTrace();
  -                        System.exit(1);
  -                        //throw ex;
  +                        ex.printStackTrace();
  +                        //System.exit(1);
  +                        throw ex;
                       }
                       //Add this pair to the proces
                       processor.add(matcher, mailet);
  @@ -263,5 +264,16 @@
           }
       }
   
  -    public void dispose() {}
  +    // Shutdown processors
  +    public void dispose() {
  +        getLogger().info("JamesSpoolManager dispose...");
  +        Iterator it = processors.keySet().iterator();
  +        while (it.hasNext()) {
  +            String processorName = (String)it.next();
  +            getLogger().debug("Processor " + processorName);
  +            LinearProcessor processor = (LinearProcessor)processors.get(processorName);
  +            processor.dispose();
  +            processors.remove(processor);
  +        }
  +    }
   }
  
  
  
  1.6       +12 -1     jakarta-james/src/java/org/apache/james/transport/LinearProcessor.java
  
  Index: LinearProcessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/LinearProcessor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LinearProcessor.java	18 Jan 2002 02:48:37 -0000	1.5
  +++ LinearProcessor.java	1 Mar 2002 15:58:40 -0000	1.6
  @@ -8,6 +8,7 @@
   package org.apache.james.transport;
   
   import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.james.core.MailImpl;
  @@ -21,6 +22,7 @@
   import java.util.List;
   import java.util.Random;
   import java.util.Vector;
  +import java.util.Iterator;
   
   /**
    * @author Serge Knystautas <sergek@lokitech.com>
  @@ -40,7 +42,7 @@
    */
   public class LinearProcessor 
       extends AbstractLogEnabled
  -    implements Initializable {
  +    implements Initializable, Disposable {
   
       private List mailets;
       private List matchers;
  @@ -63,6 +65,15 @@
           random = new Random();
       }
   
  +    // Shutdown mailets
  +    public void dispose() {
  +        Iterator it = mailets.iterator();
  +        while (it.hasNext()) {
  +            Mailet mailet = (Mailet)it.next();
  +            getLogger().debug("Shutdown mailet " + mailet.getMailetInfo());
  +            mailet.destroy();
  +        }
  +    }
   
       public void add(Matcher matcher, Mailet mailet) {
           matchers.add(matcher);
  
  
  
  1.14      +24 -14    jakarta-james/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
  
  Index: RemoteDelivery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/mailets/RemoteDelivery.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- RemoteDelivery.java	18 Jan 2002 02:48:38 -0000	1.13
  +++ RemoteDelivery.java	1 Mar 2002 15:58:40 -0000	1.14
  @@ -45,8 +45,8 @@
    * @author Serge Knystautas <sergek@lokitech.com>
    * @author Federico Barbieri <scoobie@pop.systemy.it>
    *
  - * This is $Revision: 1.13 $
  - * Committed on $Date: 2002/01/18 02:48:38 $ by: $Author: darrell $
  + * This is $Revision: 1.14 $
  + * Committed on $Date: 2002/03/01 15:58:40 $ by: $Author: danny $
    */
   public class RemoteDelivery extends GenericMailet implements Runnable {
   
  @@ -306,6 +306,8 @@
               getMailetContext().bounce(mail, sout.toString());
           } catch (MessagingException me) {
               log("encountered unexpected messaging exception while bouncing message: " +
me.getMessage());
  +        } catch (Exception e) {
  +            log("encountered unexpected exception while bouncing message: " + e.getMessage());
           }
       }
   
  @@ -359,7 +361,8 @@
           mail.setState(Mail.GHOST);
       }
   
  -    public void destroy() {
  +    // Need to synchronize to get object monitor for notifyAll()
  +    public synchronized void destroy() {
           //Wake up all threads from waiting for an accept
           notifyAll();
           for (Iterator i = deliveryThreads.iterator(); i.hasNext(); ) {
  @@ -390,17 +393,24 @@
           while (!Thread.currentThread().interrupted()) {
               try {
                   String key = outgoing.accept(delayTime);
  -                log(Thread.currentThread().getName() + " will process mail " + key);
  -                MailImpl mail = outgoing.retrieve(key);
  -                if (deliver(mail, session)) {
  -                    //Message was successfully delivered/fully failed... delete it
  -                    outgoing.remove(key);
  -                } else {
  -                    //Something happened that will delay delivery.  Store any updates
  -                    outgoing.store(mail);
  -                }
  -                //Clear the object handle to make sure it recycles this object.
  -                mail = null;
  +		try {
  +                   log(Thread.currentThread().getName() + " will process mail " + key);
  +                   MailImpl mail = outgoing.retrieve(key);
  +                   if (deliver(mail, session)) {
  +                       //Message was successfully delivered/fully failed... delete it
  +                       outgoing.remove(key);
  +                   } else {
  +                       //Something happened that will delay delivery.  Store any updates
  +                       outgoing.store(mail);
  +                   }
  +                   //Clear the object handle to make sure it recycles this object.
  +                   mail = null;
  +                } catch (Exception e) {
  +                    // Prevent unexpected exceptions from causing looping by removing
  +                    // message from outgoing.
  +		    outgoing.remove(key);
  +		    throw e;
  +		}
               } catch (Exception e) {
                   log("Exception caught in RemoteDelivery.run(): " + e);
               }
  
  
  

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


Mime
View raw message