View Javadoc
1   /* 
2   Copyright (c) 2010, NHIN Direct Project
3   All rights reserved.
4   
5   Authors:
6      Greg Meyer      gm2552@cerner.com
7    
8   Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9   
10  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
12  in the documentation and/or other materials provided with the distribution.  Neither the name of the The NHIN Direct Project (nhindirect.org). 
13  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
15  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
16  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
17  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
18  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
19  THE POSSIBILITY OF SUCH DAMAGE.
20  */
21  
22  package org.nhindirect.gateway.smtp.james.mailet;
23  
24  import javax.mail.MessagingException;
25  
26  import org.apache.mailet.Mail;
27  import org.apache.mailet.MailetConfig;
28  import org.apache.mailet.base.GenericMailet;
29  
30  /**
31   * Aggregate of the {@link TrackIncomingNotification} and {@link NotificationSuppressor} mailets.  To properly handle notification suppression, notifications cannot
32   * be tracked before determine that suppression state.  However, suppressed messages still should (must for MDN processed) be tracked.  This creates a catch 22 or
33   * chicken and egg condition.  The notification suppressor will eat messages if it is executed first and not allow some notifications to be tracked.  If the tracker is first,
34   * then messages that should not be suppressed may end up being suppressed.
35   * <p>
36   * The class aggregates the two concepts so that they happen pseudo atomically.
37   * @author Greg Meyer
38   * @since 2.0
39   */
40  public class SuppressAndTrackAggregate extends GenericMailet
41  {
42  	protected NotificationSuppressor suppessor;
43  	
44  	protected TrackIncomingNotification tracker;
45  
46  	/**
47  	 * {@inheritDoc}
48  	 */
49  	@Override
50  	public void init(MailetConfig newConfig) throws MessagingException 
51  	{
52  		super.init(newConfig);
53  		
54  		suppessor = new NotificationSuppressor();
55  		tracker = new TrackIncomingNotification();
56  		
57  		suppessor.init(newConfig);
58  		tracker.init(newConfig);
59  	}
60  
61  	/**
62  	 * {@inheritDoc}
63  	 */
64  	@Override
65  	public void service(Mail mail) throws MessagingException 
66  	{
67  		// execute the suppressor first, then track it
68  		suppessor.service(mail);
69  		
70  		tracker.service(mail);
71  		
72  	}
73  }