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