⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smgpmaster.java

📁 中国电信小灵通短信平台SP端程序
💻 JAVA
字号:
package com.pansonlu.smgp;

/**
 * <p>Title: 湖南电信短信网关通讯程序</p>
 * <p>Description: SMGPMaster是网关通讯程序的主线程,通过她初始化SMGP通讯的参数,启动并维护收发线程</p>
 * <p>Copyright: Copyright (c) 2008</p>
 * <p>Company: sunrise Ltd.</p>
 * @author pansonlu
 * @version 1.0
 */

import java.io.InputStream;
import java.io.FileInputStream;
import java.util.Properties;

import com.pansonlu.common.util.*;
import com.pansonlu.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 + -