package main;
|
import java.sql.Connection;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
import com.base.Com;
|
import com.config.AppConfig;
|
import com.data.Motor_inf;
|
import com.data.Comm.Central_DataParsing_Thread_SQL;
|
import com.data.Comm.Central_Data_SocketServer_Thread;
|
import com.data.Comm.Central_Data_Task_SQL;
|
import com.data.history.Central_Data_RealRecord_Thread;
|
import com.sql.MysqlConnPool;
|
|
public class main_Central_Monitor {
|
/**************************************************************************/
|
/**************************************************************************/
|
/**************************************************************************/
|
/**************************************************************************/
|
/**************************************************************************/
|
public final static double m_VersionNum = 1.102;
|
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;
|
|
private static List<Motor_inf> motors = new ArrayList<>();
|
|
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());
|
|
/*********************************************************************************/
|
/*********************************************************************************/
|
Central_Data_Task_SQL.init(GB_MysqlConnPool); //´´½¨¿â±í
|
|
Central_DataParsing_Thread_SQL.loadDeviceData(GB_MysqlConnPool, motors); //¼ÓÔØ¼¯ÖÐ¼à¿ØÏµÍ³É豸ÐÅÏ¢
|
|
|
/********************* ʵʱÊý¾Ý¶ÁÈ¡Ïß³Ì ************************************************************/
|
{
|
Central_Data_SocketServer_Thread server = new Central_Data_SocketServer_Thread(GB_MysqlConnPool, motors);
|
server.start();
|
}
|
|
/********************* ÀúʷʵʱÊý¾Ý¼Ç¼Ïß³Ì ************************************************************/
|
{
|
Central_Data_RealRecord_Thread record_thread = new Central_Data_RealRecord_Thread(GB_MysqlConnPool, motors);
|
record_thread.start();
|
}
|
|
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);
|
}
|
}
|
}
|
}
|
}
|
}
|