DELL
2025-01-15 c5d336ee11991456b69d00257124ea1627e985b7
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main;
 
import com.base.Com;
import com.config.AppConfig;
import com.del.TmpFileUtil;
import com.dev.lock.comm.Lock_ServerSocket_Thread;
import com.dev.lock.data.ElectLock_Array;
import com.sql.MysqlConnPool;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.TimeZone;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
public class main_ElectLock_Monitor {
    public static final boolean app_debug = false;
    public static final double m_VersionNum = 3.109D;
    public static final String m_Version = "Welcome To Use main_ElectLock_Monitor V" + m_VersionNum + " RC_20180324";
    public static int MysqlServer_Port;
    private static AppConfig m_AppConfig;
    private static MysqlConnPool GB_MysqlConnPool;
    private static Logger logger;
    private static ElectLock_Array GB_ElLock_Array;
    
 
    
    
    static {
        System.setProperty("log4j.configurationFile", "log4j2_electlock_dev_x64.xml");
    }
    public static void main(String[] args) {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        GB_ElLock_Array = new ElectLock_Array();
        
        logger = LogManager.getLogger(main_ElectLock_Monitor.class);
        String ver = "Welcome To Use BattMonitorFBS9600S V"+m_VersionNum+" RC_20180324";
 
        ver = ver + " app_for_FBS9600S_only";
 
        logger.info("Server Started At DateTime: " + Com.getDateTimeFormat(new Date(), "yyyy-MM-dd HH:mm:ss"));
 
        m_AppConfig = new AppConfig();
 
        logger.info("SQLserver IP:" + m_AppConfig.getSqlServerIp() + ", port: " + m_AppConfig.getSqlServerPort());
 
        checkingMySQLServerStart();
        
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getSqlServerIp(), m_AppConfig.getSqlServerPort(),m_AppConfig.getSqlConnCountMax());
 
        GB_ElLock_Array.initEleLockData(GB_MysqlConnPool);
        
//        Sql_Mysql sql_ck = new Sql_Mysql(GB_MysqlConnPool.getConn());
//        try {
//            //sql_ck.checkAndCreateDB();
//        } catch (SQLException e1) {
//            e1.printStackTrace();
//        } finally {
//            sql_ck.close_con();
//        }
        
        Lock_ServerSocket_Thread server_thread = new Lock_ServerSocket_Thread(GB_MysqlConnPool,GB_ElLock_Array, m_AppConfig);
        server_thread.start();
 
        
        
        //FBS9600_State_SQL.updateProcess_StartTime(GB_MysqlConnPool, m_VersionNum);
        Date last_time = new Date(0);
        while (true) {
            try {
                
                Date now = new Date();
                long timelong = (now.getTime()-last_time.getTime())/1000;
                if(timelong > 24*3600) {
                    //每天删除一次临时文件e4j
                    TmpFileUtil.delTmpFile();
                    last_time = now;
                }
                Thread.sleep(3000L);
                //FBS9600_State_SQL.updateProcess_ProcessTime(GB_MysqlConnPool);            
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void checkingMySQLServerStart(){
        logger.info(" MySQL server_source_ip:"+m_AppConfig.getSqlServerIp()+"\t server_source_port"+m_AppConfig.getSqlServerPort());            
        //初始化连接池中的各种参数信息        m_AppConfig.getMysqlServerIp()
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getSqlServerIp(), m_AppConfig.getSqlServerPort(), 5);
        while(true){
            Connection conn = null;
            try {
                logger.info(" 开始检测数据库连接 ");
                conn =  GB_MysqlConnPool.getConn();
                if(conn != null){
                    logger.info("检测数据库连接成功 ");
                    break;
                }else {
                    logger.info("连接数据库失败,稍后重新连接....");
                }
            } catch (Exception e) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
                System.out.println(" MySQL not Start ... ");
            } finally {
                if(conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}