?? smgpmaster.java
字號:
package com.zhanghao.smgp;
/**
* <p>Title: 湖南電信短信網關通訊程序</p>
* <p>Description: SMGPMaster是網關通訊程序的主線程,通過她初始化SMGP通訊的參數,啟動并維護收發線程</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: sunun Ltd.</p>
* @author zhanghao
* @version 1.0
*/
import java.io.InputStream;
import java.io.FileInputStream;
import java.util.Properties;
import com.zhanghao.common.util.*;
import com.zhanghao.common.database.*;
public class SMGPMaster extends Thread{
private String configProperty ="";
private SMGPSocketProcess socketProcess;
// /** 發送線程池 **/
// private SMGPSendThread[] SendThreadPool = new SMGPSendThread [1];
//
// /** 接收線程池 **/
// private SMGPReceiveThread[] ReceiveThreadPool = new SMGPReceiveThread[1];
private SMGPSendThread smgpSendThread;
private SMGPReceiveThread smgpReceiveThread;
public SMGPMaster() {
//加載配置參數
loadInitCfg();
//設置日志路徑
LogUtil.setLogPath(SMGParameter.LogFilePath);
//初始化連接池
initConnectionPool();
}
public void run(){
while(true){
//判斷數據庫是否連接
SMGPDBAccess.getInstance();
maintenanceProcess();
PublicFunction.sleep(1000);
}
}
/**初始化連接池 **/
public boolean initConnectionPool(){
//初始化數據庫連接池:
try{
ConnectionPool.initConnectionPool(
SMGParameter.DBDriver,
SMGParameter.Connect_URL,
SMGParameter.DBUser,
SMGParameter.DBPass,
SMGParameter.DBPoolSize,
20
);
Debug.outInfo("[SMGPMaster]"+PublicFunction.getFormatTime()+" 初始化數據庫連接池成功,大小"+SMGParameter.DBPoolSize+",超時間隔20秒");
return true;
}catch(Exception e){
Debug.outInfo("[SMGPMaster]"+PublicFunction.getFormatTime()+" 初始化數據庫連接池失敗 " +e.toString());
return false;
}
}
/** 維護收發線程組**/
public void maintenanceProcess(){
socketProcess = socketProcess.getInstance();
if(!socketProcess.isAvail){
try{
smgpReceiveThread.isAvail = false;
smgpSendThread.isAvail = false;
PublicFunction.sleep(500);
socketProcess.connectSMSG();
if(socketProcess.isAvail){
smgpReceiveThread = new SMGPReceiveThread();
smgpReceiveThread.start();
smgpSendThread = new SMGPSendThread();
smgpSendThread.start();
}
}
catch(Exception ex){
Debug.outError(ex);
}
}
}
/**
* 讀取配置文件
*/
public void loadInitCfg(){
String cfgFile = "";
try{
cfgFile = System.getProperties().getProperty(configProperty);
cfgFile = cfgFile == null ? "SMGP.cfg":cfgFile;
Debug.outDebug("Config file path:"+cfgFile);
InputStream is = new FileInputStream(cfgFile) ;
Properties pt = new Properties() ;
pt.load(is) ;
/** 更改SOCKET通訊配置參數 **/
SMGParameter.ServerIp = pt.getProperty("ServerIp", "127.0.0.1");
Debug.outDebug("ServerIp: \t" + SMGParameter.ServerIp);
SMGParameter.ServerPort = Integer.parseInt(pt.getProperty("ServerPort", "8890"));
Debug.outDebug("ServerPort: \t" + SMGParameter.ServerPort);
SMGParameter.SP_Id = pt.getProperty("SP_Id", "901234");
Debug.outDebug("SP_Id: \t" + SMGParameter.SP_Id);
SMGParameter.SP_Pwd = pt.getProperty("SP_Pwd", "1234");
Debug.outDebug("SP_Pwd: \t" + SMGParameter.SP_Pwd);
SMGParameter.LoginMode = Integer.parseInt(pt.getProperty("LoginMode", "2"));
Debug.outDebug("LoginMode: \t" + SMGParameter.LoginMode);
SMGParameter.Version = Integer.parseInt(pt.getProperty("Version", "2"));
Debug.outDebug("Version: \t" + SMGParameter.Version);
SMGParameter.ActiveTestTime = Integer.parseInt(pt.getProperty("ActiveTestTime", "30")) * 1000;
Debug.outDebug("ActiveTestTime: \t" + SMGParameter.ActiveTestTime);
SMGParameter.MTSpeed = Integer.parseInt(pt.getProperty("MTSpeed", "20"));
Debug.outDebug("MTSpeed: \t" + SMGParameter.MTSpeed);
/** 更改數據庫連接配置參數 **/
SMGParameter.DBType = Integer.parseInt(pt.getProperty("DBType", "1"));
Debug.outDebug("DBType: \t" + SMGParameter.DBType);
if(SMGParameter.DBType==1) SMGParameter.DBDriver ="oracle.jdbc.driver.OracleDriver";
if(SMGParameter.DBType==2) SMGParameter.DBDriver ="com.microsoft.jdbc.sqlserver.SQLServerDriver";
if(SMGParameter.DBType==3) SMGParameter.DBDriver ="com.sybase.jdbc.SybDriver";
Debug.outDebug("DBDriver: \t" + SMGParameter.DBDriver);
SMGParameter.Connect_URL = pt.getProperty("Connect_URL", "jdbc:microsoft:sqlserver://192.168.0.44:1433;DatabaseName=stock");
Debug.outDebug("Connect_URL:" + SMGParameter.Connect_URL);
SMGParameter.DBUser = pt.getProperty("DBUser", "sa");
Debug.outDebug("DBUser: \t" + SMGParameter.DBUser);
SMGParameter.DBPass = pt.getProperty("DBPass", "sa");
Debug.outDebug("DBPass: \t" + SMGParameter.DBPass);
SMGParameter.DBPoolSize = Integer.parseInt(pt.getProperty("DBPoolSize", "20"));
Debug.outDebug("DBPoolSize: \t" + SMGParameter.DBPoolSize);
SMGParameter.IfPrintDebug = Integer.parseInt(pt.getProperty("IfPrintDebug", "1"));
Debug.outDebug("IfPrintDebug: \t" + SMGParameter.IfPrintDebug);
SMGParameter.LogFilePath = pt.getProperty("LogFilePath", "sa");
Debug.outDebug("LogFilePath: \t" + SMGParameter.LogFilePath);
// SMGParameter.MTPrefixWord = new String(pt.getProperty("MTPrefixWord", "").getBytes("ISO-8859-1"),"GB2312");
}
catch(Exception ex){
Debug.outDebug("[SMGP] loadInitCfg error :" +ex) ;
}
}
public static void main(String args[]){
new SMGPMaster().start();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -