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.107D;
|
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();
|
}
|
}
|
}
|
}
|
}
|
}
|