⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jamesspoolmanager.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**************************************************************** * Licensed to the Apache Software Foundation (ASF) under one   * * or more contributor license agreements.  See the NOTICE file * * distributed with this work for additional information        * * regarding copyright ownership.  The ASF licenses this file   * * to you under the Apache License, Version 2.0 (the            * * "License"); you may not use this file except in compliance   * * with the License.  You may obtain a copy of the License at   * *                                                              * *   http://www.apache.org/licenses/LICENSE-2.0                 * *                                                              * * Unless required by applicable law or agreed to in writing,   * * software distributed under the License is distributed on an  * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       * * KIND, either express or implied.  See the License for the    * * specific language governing permissions and limitations      * * under the License.                                           * ****************************************************************/package org.apache.james.transport;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.container.ContainerUtil;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;import org.apache.avalon.framework.service.Serviceable;import org.apache.james.services.MailetLoader;import org.apache.james.services.MatcherLoader;import org.apache.james.services.SpoolRepository;import org.apache.mailet.Mail;import org.apache.mailet.Mailet;import org.apache.mailet.MailetException;import org.apache.mailet.Matcher;import javax.mail.MessagingException;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;/** * Manages the mail spool.  This class is responsible for retrieving * messages from the spool, directing messages to the appropriate * processor, and removing them from the spool when processing is * complete. * * @version CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $ */public class JamesSpoolManager    extends AbstractLogEnabled    implements Serviceable, Configurable, Initializable, Runnable, Disposable {    /**     * System component manager     */    private DefaultServiceManager compMgr;    /**     * The configuration object used by this spool manager.     */    private Configuration conf;    /**     * The spool that this manager will process     */    private SpoolRepository spool;    /**     * The map of processor names to processors     */    private HashMap processors;    /**     * The number of threads used to move mail through the spool.     */    private int numThreads;    /**     * The ThreadPool containing worker threads.     *     * This used to be used, but for threads that lived the entire     * lifespan of the application.  Currently commented out.  In     * the future, we could use a thread pool to run short-lived     * workers, so that we have a smaller number of readers that     * accept a message from the spool, and dispatch to a pool of     * worker threads that process the message.     */    // private ThreadPool workerPool;    /**     * The ThreadManager from which the thread pool is obtained.     */    // private ThreadManager threadManager;    /**     * Number of active threads     */    private int numActive;    /**     * Spool threads are active     */    private boolean active;    /**     * Spool threads     */    private Collection spoolThreads;    /**     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)     */    public void service(ServiceManager comp) throws ServiceException {        // threadManager = (ThreadManager) comp.lookup(ThreadManager.ROLE);        compMgr = new DefaultServiceManager(comp);    }    /**     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)     */    public void configure(Configuration conf) throws ConfigurationException {        this.conf = conf;        numThreads = conf.getChild("threads").getValueAsInteger(1);    }    /**     * @see org.apache.avalon.framework.activity.Initializable#initialize()     */    public void initialize() throws Exception {        getLogger().info("JamesSpoolManager init...");        spool = (SpoolRepository) compMgr.lookup(SpoolRepository.ROLE);        MailetLoader mailetLoader        = (MailetLoader) compMgr.lookup(MailetLoader.ROLE);        MatcherLoader matchLoader        = (MatcherLoader) compMgr.lookup(MatcherLoader.ROLE);        //A processor is a Collection of        processors = new HashMap();        final Configuration[] processorConfs = conf.getChildren( "processor" );        for ( int i = 0; i < processorConfs.length; i++ )        {            Configuration processorConf = processorConfs[i];            String processorName = processorConf.getAttribute("name");            try {                LinearProcessor processor = new LinearProcessor();                setupLogger(processor, processorName);                processor.setSpool(spool);                processor.initialize();                processors.put(processorName, processor);                final Configuration[] mailetConfs                    = processorConf.getChildren( "mailet" );                // Loop through the mailet configuration, load                // all of the matcher and mailets, and add                // them to the processor.                for ( int j = 0; j < mailetConfs.length; j++ )                {                    Configuration c = mailetConfs[j];                    String mailetClassName = c.getAttribute("class");                    String matcherName = c.getAttribute("match");                    Mailet mailet = null;                    Matcher matcher = null;                    try {                        matcher = matchLoader.getMatcher(matcherName);                        //The matcher itself should log that it's been inited.                        if (getLogger().isInfoEnabled()) {                            StringBuffer infoBuffer =                                new StringBuffer(64)                                        .append("Matcher ")                                        .append(matcherName)                                        .append(" instantiated.");                            getLogger().info(infoBuffer.toString());                        }                    } catch (MessagingException ex) {                        // **** Do better job printing out exception                        if (getLogger().isErrorEnabled()) {                            StringBuffer errorBuffer =                                new StringBuffer(256)                                        .append("Unable to init matcher ")                                        .append(matcherName)                                        .append(": ")                                        .append(ex.toString());                            getLogger().error( errorBuffer.toString(), ex );                if (ex.getNextException() != null) {                getLogger().error( "Caused by nested exception: ", ex.getNextException());                }                        }                        System.err.println("Unable to init matcher " + matcherName);                        System.err.println("Check spool manager logs for more details.");                        //System.exit(1);                        throw ex;                    }                    try {                        mailet = mailetLoader.getMailet(mailetClassName, c);                        if (getLogger().isInfoEnabled()) {                            StringBuffer infoBuffer =                                new StringBuffer(64)                                        .append("Mailet ")                                        .append(mailetClassName)                                        .append(" instantiated.");                            getLogger().info(infoBuffer.toString());                        }                    } catch (MessagingException ex) {                        // **** Do better job printing out exception                        if (getLogger().isErrorEnabled()) {                            StringBuffer errorBuffer =                                new StringBuffer(256)                                        .append("Unable to init mailet ")                                        .append(mailetClassName)                                        .append(": ")                                        .append(ex.toString());                            getLogger().error( errorBuffer.toString(), ex );                if (ex.getNextException() != null) {                getLogger().error( "Caused by nested exception: ", ex.getNextException());                }                        }                        System.err.println("Unable to init mailet " + mailetClassName);                        System.err.println("Check spool manager logs for more details.");                        //System.exit(1);                        throw ex;                    }                    //Add this pair to the processor                    processor.add(matcher, mailet);                }                // Close the processor matcher/mailet lists.                //                // Please note that this is critical to the proper operation                // of the LinearProcessor code.  The processor will not be                // able to service mails until this call is made.                processor.closeProcessorLists();                if (getLogger().isInfoEnabled()) {                    StringBuffer infoBuffer =                        new StringBuffer(64)                                .append("Processor ")                                .append(processorName)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -