whyclj
2020-12-04 8efa8283867be10ad127b8ec9680e00a10e79dda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.base.Com;
import com.config.AppConfig;
import com.sql.MysqlConnPool;
 
public class main_Central_Monitor {
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    public final static double m_VersionNum = 1.101;
    public final static String m_Version = "Welcome To Use main_Central_Monitor V" 
                                            + m_VersionNum ;
    /**************************************************************************/
    /**************************************************************************/
    public static final int MysqlServer_Port = 3360;
    
    private static AppConfig m_AppConfig;
    
    private static MysqlConnPool GB_MysqlConnPool;
    
    private static Logger logger = null;
    
    static{
        System.setProperty("log4j.configurationFile", "log4j2_central_monitor.xml");
    }
    
     /*********************************************************************************************/
    /*********************************************************************************************/
    public static void main(String[] args) {
        
        logger = LogManager.getLogger(main_Central_Monitor.class);
        String ver = m_Version;        
        logger.info("main_MonitorServer_Motor Server Started At DateTime: " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "\t V"+ver);
        //´´½¨config.xmlÎļþ
        m_AppConfig = new AppConfig();
        
        logger.info("SQLserver IP£º" + m_AppConfig.getMysqlServerIp() + ", port: "+MysqlServer_Port);
        checkingMySQLServerStart();                //¼ì²âÊý¾Ý¿â·þÎñÊÇ·ñÆô¶¯
 
        
        //³õʼ»¯Á¬½Ó³ØÖеĸ÷ÖÖ²ÎÊýÐÅÏ¢
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port,m_AppConfig.getMysqlConnCountMax());
        
        
        /*********************************************************************************/
        /*********************************************************************************/
 
        
        
        
        while(true) {
            try {        
                Thread.sleep(5000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        /*********************************************************************************/
    }
    
    public static void checkingMySQLServerStart(){
        int MysqlServer_Port = 3360;
        logger.info("IP:"+m_AppConfig.getMysqlServerIp()+"\t port:"+MysqlServer_Port);            
        //³õʼ»¯Á¬½Ó³ØÖеĸ÷ÖÖ²ÎÊýÐÅÏ¢        m_AppConfig.getMysqlServerIp()
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 5);
        while(true){
            Connection conn = null;
            try {
                logger.info(" ¿ªÊ¼¼ì²âÊý¾Ý¿âÁ¬½Ó "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
                conn =  GB_MysqlConnPool.getConn();
                if(conn != null){
                    logger.info("¼ì²âÊý¾Ý¿âÁ¬½Ó³É¹¦");
                    break;
                }
            } catch (Exception e) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                    logger.error(e.toString(), e);
                }
                logger.info(" MySQL_FBSDEV not Start ... ");
            } finally {
                if(conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        logger.error(e.toString(), e);
                    }
                }
            }
        }
    }
}