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

📄 mailserver.java

📁 Java Mail Server JAVA编写的邮件服务器
💻 JAVA
字号:
/**************************************************************** * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.     * *                                                              * * Copyright 2008 Jun Li(SiChuan University, the School of      * * Software Engineering). All rights reserved.                  * *                                                              * * Licensed to the JMS under one  or more contributor license   * * agreements.  See the LICENCE file  distributed with this     * * work for additional information regarding copyright          * * ownership.  The JMS licenses this file  you may not use this * * file except in compliance  with the License.                 * *                                                              * * 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.jpxx.mail;import org.apache.log4j.Logger;import org.jpxx.mail.Exception.InvalidServiceException;import org.jpxx.mail.Domain.DomainHandler;/** * <p>This is a core class for JMS. You can start, restart or stop it.</p> * <p>JMS has two services, which are SMTP and POP.</p> *  * @author Jun Li * @version $Revision: 0.0.3 $, $Date: 2008/10/25 $ * @since JMS 0.0.1 *  */public class MailServer {    /**     * The software name     */    public final static String SOFTWARE_NAME = Constants.NAME;    /**     * The software Version     */    public final static String SOFTWARE_VERSION = Constants.VERSION;    /**     * Class factory     */    private Factory factory = Factory.getSingletonInstance();    /**     * Creates an instance of Logger and initializes it.      * It is to write log for <code>MailServer</code>.     */    private Logger log = factory.getLogger(this);    /**     * Singleton instance of MailServer     */    private static MailServer singletonInstance = null;    /**     * Server state. Started or stopped. 1 -started, 0 -stopped     */    private static int state = 0;    /**     * To make sure start one JMS.      * @since JMS 0.0.1     * @return singleton instance of MailServer     */    public static MailServer getSingletonInstance() {        if (singletonInstance == null) {            singletonInstance = new MailServer();        }        return singletonInstance;    }    private MailServer() {        /**         * Start console server.         */        try {            factory.getServer("Console").start();        } catch (InvalidServiceException ise) {            log.error(ise.toString());        }    }    /**     * <p>     * Starts JMS. Before you start server, please adds a domain firstly     * for server. JMS supports two or more domains.     * </p>     *      * <p>     * This method that must not be executed by two threads simultaneously.     * Note the American spelling, <b>synchronized</b>, that all Java terms use.      * A crucial block of code you don’t want two threads accessing      * simultaneously can be designed to allow only one thread through at a time.     * </p>     * @since JMS 0.0.1     */    public synchronized void startServer() {        if (new DomainHandler().getDomains() == null) {            log.error("Starts failed," +                    " no domain for server. Please add a domain firstly.");        } else if (state == 1) {            log.error("Starts failed." +                    " Server is already started.");        } else {            try {                log.info("Start server");                factory.getServer("Smtp").start();                factory.getServer("Pop3").start();                                state = 1;            } catch (InvalidServiceException ise) {                log.error(ise.toString());            }        }    }    /**     * Restart JMS.     *      * <p>     * This method that must not be executed by two threads simultaneously.     * </p>     * @since JMS 0.0.1     */    public synchronized void restartServer() {        if (state == 0) {            log.error("Restart failed." +                    " Can't restart here. Server not started.");        } else {            try {                log.info("Restart server");                factory.getServer("Smtp").restart();                factory.getServer("Pop3").restart();            } catch (InvalidServiceException ise) {                log.error(ise.toString());            }        }    }    /**     * Stop JMS.     *      * <p>     * This method that must not be executed by two threads simultaneously.     * </p>     * @since JMS 0.0.1     */    public synchronized void stopServer() {        if (state == 0) {            log.error("Stop failed." +                    " Server not started at all.");        } else {            try {                log.info("Stop server");                factory.getServer("Smtp").stop();                factory.getServer("Pop3").stop();                state = 0;            } catch (InvalidServiceException ise) {                log.error(ise.toString());            }        }    }    /**     * Returns server current state. 0 -stopped, 1 -started;     * @return server current state. 0 -stopped, 1 -started;     * @since JMS 0.0.3     */    public static int getState() {        return state;    }}

⌨️ 快捷键说明

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