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

📄 ecappservermain.java

📁 银行项目为后台socket通信写的程序
💻 JAVA
字号:
/****************************************************************************
 * Package		: com.ecSolutions.ecAppServer
 * File			: ecAppServerMain.java
 * Create Date  : 2007-7-19
 * Author		: Steven Chen
 * 
 * Copyright(C) 2006 ecSolutions(shanghai) Co.,Limited.All Rights Reserved.
 *			
 ***************************************************************************/
package com.ecSolutions.ecAppServer;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.ecSolutions.ecAppServer.config.PropertiesConfiguration;
import com.ecSolutions.ecAppServer.management.ServerRoot;
import com.ecSolutions.ecAppServer.server.AppServer;
import com.ecSolutions.ecAppServer.util.FileUtil;
import com.ecSolutions.ecAppServer.util.DbUtil;


public class ecAppServerMain {
	private static Logger log = Logger.getLogger("ecAppServerMain");
	
	
	/**
	 * ecAppServer运行主程序,通过命令行	启动运行此程序
	 * @param args 运行参数,参加usage()
	 */
	public static void main(String[] args) {
		Configuration config = null;
		try {
			config = PropertiesConfiguration.getInstance();
		} catch (ecAppServerConfigException e) {
			log.info("config file reading failure......");
			System.out.println(e.toString());
			System.exit(1);
		}
		
		try {
			DbUtil.setupDataSource(config);
		} catch (ecAppServerConfigException e1) {
			log.error("ecAppServer DataSource setup failure......");
			System.out.println("ecAppServer DataSource setup failure......");
			e1.printStackTrace();
			System.exit(1);
		}
		
		AppServer server = new AppServer(config);
		try {
			server.start();
		} catch (Exception e) {
			System.out.println("ecAppServer start up failure because of:" + e.toString());
			e.printStackTrace();
			System.exit(1);
		}
		
		ServerRoot.startAppWebServer();

		
		/*try {
			server.start();
		} catch (Exception e) {
			log.error("ecAppServer Start Failure..........");
			System.out.println("ecAppServer Start up Failure..........");
			e.printStackTrace();
			System.exit(1);
		}*/
		//add shutdown hook if possible
		addShutdownHook(server);
	}
	
	
	
	/**
	 * ecAppServer使用方法说明
	 */	
	private static void usage() {
        System.err.println("Usage: java com.ecSolutions.ecAppServer [<options>]");
        System.err.println("  <options> := -default |");
        System.err.println("               -xml <XML configuration file> |");
        System.err.println("               -prop <properties configuration file>");
        System.out.println();
        System.out.println("There are three ways to start the ecAppServer.");
        System.out.println("    -default :: default configuration will be used.");
        System.out.println("    -xml     :: XML configuration will be used. User has to specify the file.");
        System.out.println("    -prop    :: properties configuration will be used. User has to specify the file.");
        System.out.println();
        System.out.println("In case of no option, default configuration will be used.");
    }
	
	/**
	 * ecAppServer shutdown前的hook,处理关闭前需要处理的业务逻辑
	 * @param server
	 */
	private static void addShutdownHook(final AppServer server) {
		//create shutdown hook
		Runnable shutdownHook = new Runnable() {
			public void run() {
				//可以将关闭应用服务器前需处理的业务添加在此
				//close database connections and destroy connection pool
				//close ecAppServer management server (web server)
				
				System.out.println("Stopping ecAppServer now, please waiting ......");
				server.stop();
				System.out.println("Stopping ecAppServer DataSource, please waiting ......");
				try {
					DbUtil.destroy();
				} catch (SQLException e) {
					log.error("Connection Pool destroy error" + e.toString());
				}
				
				ServerRoot.stopAppWebServer();
				System.out.println("ecAppServer Stop Completed  ......");
			}
		};
		// add shutdown hook
		Runtime runtime = Runtime.getRuntime();
		runtime.addShutdownHook(new Thread(shutdownHook));
	}
	

}

⌨️ 快捷键说明

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