org.apache.james.transport
Class LinearProcessor

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.transport.LinearProcessor
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.logger.LogEnabled

public class LinearProcessor
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.activity.Disposable

Implements a processor for mails, directing the mail down the chain of matchers/mailets. SAMPLE CONFIGURATION <processor name="try" onerror="return,log"> <mailet match="RecipientIsLocal" class="LocalDelivery"> </mailet> <mailet match="All" class="RemoteDelivery"> <delayTime>21600000</delayTime> <maxRetries>5</maxRetries> </mailet> </processor> Note that the 'onerror' attribute is not yet supported. As of James v2.2.0a5, 'onerror' functionality is implemented, but it is implemented on the <mailet> tag. The specification is: <mailet match="..." class="..." [onMatchException="{noMatch|matchAll|error|<aProcessorName>}"] [onMailetException="{ignore|error|<aProcessorName>}"]> noMatch: no addresses are considered to match matchAll: all addresses are considered to match error: as before, send the message to the ERROR processor Otherwise, a processor name can be specified, and the message will be sent there.

CVS $Id: LinearProcessor.java 494012 2007-01-08 10:23:58 +0000 (lun, 08 gen 2007) norman $

Version:
2.2.0

Constructor Summary
LinearProcessor()
           
 
Method Summary
 void add(Matcher matcher, Mailet mailet)
          Adds a new Matcher / Mailet pair to the processor.
 void closeProcessorLists()
          Closes the processor matcher/mailet list.
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 void initialize()
           
 void service(Mail mail)
          Processes a single mail message through the chain of matchers and mailets.
 void setSpool(SpoolRepository spool)
          Set the spool to be used by this LinearProcessor.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearProcessor

public LinearProcessor()
Method Detail

setSpool

public void setSpool(SpoolRepository spool)
Set the spool to be used by this LinearProcessor.

Parameters:
spool - the spool to be used by this processor
Throws:
java.lang.IllegalArgumentException - when the spool passed in is null

initialize

public void initialize()
Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
See Also:
Initializable.initialize()

dispose

public void dispose()

The dispose operation is called at the end of a components lifecycle. Instances of this class use this method to release and destroy any resources that they own.

This implementation disposes of all the mailet instances added to the processor

Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable
Throws:
java.lang.Exception - if an error is encountered during shutdown

add

public void add(Matcher matcher,
                Mailet mailet)

Adds a new Matcher / Mailet pair to the processor. Checks to ensure that the matcher and mailet passed in are not null. Synchronized to ensure that the matchers and mailets are kept in sync.

It is an essential part of the contract of the LinearProcessor that a particular matcher/mailet combination be used to terminate the processor chain. This is done by calling the closeProcessorList method.

Once the closeProcessorList has been called any subsequent call to the add method will result in an IllegalStateException.

This method is synchronized to protect against corruption of matcher/mailets lists

Parameters:
matcher - the new matcher being added
mailet - the new mailet being added
Throws:
java.lang.IllegalArgumentException - when the matcher or mailet passed in is null
java.lang.IllegalStateException - when this method is called after the processor lists have been closed

closeProcessorLists

public void closeProcessorLists()

Closes the processor matcher/mailet list.

This method is synchronized to protect against corruption of matcher/mailets lists

Throws:
java.lang.IllegalStateException - when this method is called after the processor lists have been closed

service

public void service(Mail mail)
             throws javax.mail.MessagingException

Processes a single mail message through the chain of matchers and mailets.

Calls to this method before setSpool has been called with a non-null argument will result in an IllegalStateException.

If the matcher/mailet lists have not been closed by a call to the closeProcessorLists method then a call to this method will result in an IllegalStateException. The end of the matcher/mailet chain must be a matcher that matches all mails and a mailet that sets every mail to GHOST status. This is necessary to ensure that mails are removed from the spool in an orderly fashion. The closeProcessorLists method ensures this.

Parameters:
mail - the new mail to be processed
Throws:
java.lang.IllegalStateException - when this method is called before the processor lists have been closed or the spool has been initialized
javax.mail.MessagingException


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.