Index: C:/Lab/VOID/projects/james-trunk/src/java/org/apache/james/transport/JamesSpoolManager.java =================================================================== --- C:/Lab/VOID/projects/james-trunk/src/java/org/apache/james/transport/JamesSpoolManager.java (revision 168299) +++ C:/Lab/VOID/projects/james-trunk/src/java/org/apache/james/transport/JamesSpoolManager.java (working copy) @@ -17,16 +17,14 @@ package org.apache.james.transport; -import org.apache.avalon.cornerstone.services.threads.ThreadManager; -//import org.apache.excalibur.thread.ThreadPool; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; -import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.Contextualizable; +import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.DefaultServiceManager; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; @@ -34,7 +32,11 @@ import org.apache.james.core.MailImpl; import org.apache.james.services.MailStore; import org.apache.james.services.SpoolRepository; -import org.apache.mailet.*; +import org.apache.mailet.Mail; +import org.apache.mailet.Mailet; +import org.apache.mailet.MailetContext; +import org.apache.mailet.MailetException; +import org.apache.mailet.Matcher; import javax.mail.MessagingException; @@ -189,7 +191,6 @@ try { LinearProcessor processor = new LinearProcessor(); setupLogger(processor, processorName); - processor.setSpool(spool); processor.initialize(); processors.put(processorName, processor); @@ -346,6 +347,7 @@ try { MailImpl mail = (MailImpl)spool.accept(); key = mail.getName(); + String originalState = mail.getState(); if (getLogger().isDebugEnabled()) { StringBuffer debugBuffer = new StringBuffer(64) @@ -370,6 +372,10 @@ getLogger().debug(debugBuffer.toString()); } } + else if (!mail.getState().equals(originalState)) { + spool.store(mail); + spool.unlock(key); + } else { // spool.remove() has a side-effect! It unlocks the // message so that other threads can work on it! If @@ -456,11 +462,16 @@ getLogger().debug(logMessageBuffer.toString()); getLogger().debug("Result was " + mail.getState()); } - return; + // this speed up processing at the cost of less grained updates on + // state change. + // e.g: if the server crashes during the spooling when restarted the + // mail will restart from the first processor and not the processor + // where it were running during the crash. + // return; } catch (Throwable e) { // This is a strange error situation that shouldn't ordinarily // happen - StringBuffer exceptionBuffer = + StringBuffer exceptionBuffer = new StringBuffer(64) .append("Exception in processor <") .append(processorName) @@ -479,17 +490,17 @@ } mail.setErrorMessage(e.getMessage()); } + if (getLogger().isErrorEnabled()) { + StringBuffer logMessageBuffer = + new StringBuffer(128) + .append("An error occurred processing ") + .append(mail.getName()) + .append(" through ") + .append(processorName); + getLogger().error(logMessageBuffer.toString()); + getLogger().error("Result was " + mail.getState()); + } } - if (getLogger().isErrorEnabled()) { - StringBuffer logMessageBuffer = - new StringBuffer(128) - .append("An error occurred processing ") - .append(mail.getName()) - .append(" through ") - .append(processorName); - getLogger().error(logMessageBuffer.toString()); - getLogger().error("Result was " + mail.getState()); - } } }