View Javadoc

1   /************************************************************************
2    * Copyright (c) 1999-2006 The Apache Software Foundation.             *
3    * All rights reserved.                                                *
4    * ------------------------------------------------------------------- *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you *
6    * may not use this file except in compliance with the License. You    *
7    * may obtain a copy of the License at:                                *
8    *                                                                     *
9    *     http://www.apache.org/licenses/LICENSE-2.0                      *
10   *                                                                     *
11   * Unless required by applicable law or agreed to in writing, software *
12   * distributed under the License is distributed on an "AS IS" BASIS,   *
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
14   * implied.  See the License for the specific language governing       *
15   * permissions and limitations under the License.                      *
16   ***********************************************************************/
17  
18  package org.apache.mailet;
19  
20  /***
21   * Draft of a Mailet inteface. The <code>service</code> perform all needed work
22   * on the Mail object. Whatever remains at the end of the service is considered
23   * to need futher processing and will go to the next Mailet if there is one
24   * configured or will go to the error processor if not.
25   * Setting a Mail state (setState(String)) to Mail.GHOST or cleaning its recipient
26   * list has the same meaning that s no more processing is needed.
27   * Instead of creating new messages, the mailet can put a message with new recipients
28   * at the top of the mail queue, or insert them immediately after it's execution
29   * through the API are provided by the MailetContext interface.
30   * <p>
31   * This interface defines methods to initialize a mailet, to service messages, and to
32   * remove a mailet from the server. These are known as life-cycle methods and are called
33   * in the following sequence:
34   * <ol>
35   * <li>The mailet is constructed, then initialized with the init method. </li>
36   * <li>Any messages for the service method are handled.</li>
37   * <li>The mailet is taken out of service, then destroyed with the destroy method,
38   *      then garbage collected and finalized.</li>
39   * </ol>
40   * In addition to the life-cycle methods, this interface provides the getMailetConfig
41   * method, which the mailet can use to get any startup information, and the
42   * getMailetInfo method, which allows the mailet to return basic information about itself,
43   * such as author, version, and copyright.
44   *
45   * @version 1.0.0, 24/04/1999
46   */
47  public interface Mailet {
48  
49      /***
50       * Called by the mailet container to indicate to a mailet that the
51       * mailet is being taken out of service. This method is only called once
52       * all threads within the mailet's service method have exited or after a
53       * timeout period has passed. After the mailet container calls this method,
54       * it will not call the service method again on this mailet.
55       * <p>
56       * This method gives the mailet an opportunity to clean up any resources that
57       * are being held (for example, memory, file handles, threads) and make sure
58       * that any persistent state is synchronized with the mailet's current state in memory.
59       */
60      void destroy();
61  
62      /***
63       * Returns information about the mailet, such as author, version, and
64       * copyright.
65       * <p>
66       * The string that this method returns should be plain text and not markup
67       * of any kind (such as HTML, XML, etc.).
68       *
69       * @return a String containing servlet information
70       */
71      String getMailetInfo();
72  
73      /***
74       * Returns a MailetConfig object, which contains initialization and
75       * startup parameters for this mailet.
76       * <p>
77       * Implementations of this interface are responsible for storing the MailetConfig
78       * object so that this method can return it. The GenericMailet class, which implements
79       * this interface, already does this.
80       *
81       * @return the MailetConfig object that initializes this mailet
82       */
83      MailetConfig getMailetConfig();
84  
85      /***
86       * Called by the mailet container to indicate to a mailet that the
87       * mailet is being placed into service.
88       * <p>
89       * The mailet container calls the init method exactly once after
90       * instantiating the mailet. The init method must complete successfully
91       * before the mailet can receive any requests.
92       *
93       * @param config - a MailetConfig object containing the mailet's configuration
94       *          and initialization parameters
95       * @throws javax.mail.MessagingException - if an exception has occurred that interferes with
96       *          the mailet's normal operation
97       */
98      void init(MailetConfig config) throws javax.mail.MessagingException;
99  
100     /***
101      * Called by the mailet container to allow the mailet to process to
102      * a message.
103      * <p>
104      * This method is only called after the mailet's init() method has completed
105      * successfully.
106      * <p>
107      * Mailets typically run inside multithreaded mailet containers that can handle
108      * multiple requests concurrently. Developers must be aware to synchronize access
109      * to any shared resources such as files, network connections, as well as the
110      * mailet's class and instance variables. More information on multithreaded
111      * programming in Java is available in <a href="http://java.sun.com/Series/Tutorial/java/threads/multithreaded.html">the
112      * Java tutorial on multi-threaded programming</a>.
113      *
114      * @param mail - the Mail object that contains the message and routing information
115      * @throws javax.mail.MessagingException - if a message or address parsing exception occurs or
116      *      an exception that interferes with the mailet's normal operation
117      */
118     void service(Mail mail) throws javax.mail.MessagingException;
119 }