?? smgpreceivethread.java
字號:
package com.zhanghao.smgp;/** * <p>Title: SMGP Interface</p> * <p>Description: 湖南移動短信網關通訊程序</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: sunun tech ltd.</p> * @author zhanghao * @version 1.0 */import java.io.*;import java.net.*;import com.zhanghao.common.util.*;public class SMGPReceiveThread extends Thread{ /** 該線程運行標志 true 在運行,false停止 **/ public static boolean isAvail = false; private static DataInputStream inputStream; private static DataOutputStream outputStream; /** 初始化構造器 * 使用SMGPSocketProcess唯一的實例的輸入流和輸出流**/ public SMGPReceiveThread() { inputStream = SMGPSocketProcess.getInstance().inputStream; outputStream = SMGPSocketProcess.getInstance().outputStream; isAvail = true; } public void run(){ Debug.outInfo("[SMGPMaster]"+PublicFunction.getFormatTime()+" MO線程("+SMGParameter.ServerPort+")->接收線程啟動 ..."); while(SMGPSocketProcess.getInstance().isAvail && isAvail){ try{ byte[] recByte = PublicFunction.recv(inputStream); SMGP deliverMsg = new SMGP(); deliverMsg.parsePack(recByte); switch(deliverMsg.RequestID){ case SMGP.SMGP_DELIVER: //將Deliver消息保存在接收緩沖中,由SMGPSocketProcess的SMGPMODataSaveThread //線程將MO數據保存在數據庫中 synchronized(SMGPDBAccess.getInstance().vctMOData){ SMGPDBAccess.getInstance().vctMOData.addElement(deliverMsg); } //回應Deliver消息 SMGP deliverRespMsg = new SMGP(SMGP.SMGP_DELIVER_RESP); deliverRespMsg.MsgID = deliverMsg.MsgID; deliverRespMsg.SequenceID = deliverMsg.SequenceID; deliverRespMsg.Status = 0; PublicFunction.send(outputStream, deliverRespMsg.pack()); break; case SMGP.SMGP_ACTIVE_TEST_RESP: //鏈路測試響應,無處理 //System.out.println("SMGP.SMGP_ACTIVE_TEST_RESP"); break; case SMGP.SMGP_SUBMIT_RESP: if(deliverMsg.Status ==0){ //SMGPDBAccess.getInstance().saveRespRelate(deliverMsg); Debug.outInfo("[SMGPMaster]發送短信成功,SequenceID:" +deliverMsg.SequenceID+" Relat MsgID: "+deliverMsg.BCDMsgID); } else{ Debug.outInfo("[SMGPMaster]發送短信失敗,錯誤狀態碼:" +deliverMsg.Status+" MsgID:" +deliverMsg.SequenceID+"") ; } //處理成功下發的響應信息 //SMGPDBAccess.getInstance().dealProccessMsg(deliverMsg); synchronized(SMGPDBAccess.getInstance().vctRespMsg){ SMGPDBAccess.getInstance().vctRespMsg.addElement(deliverMsg); } break; } } catch(Exception ex){ destory(ex); } } // end while } /** 銷毀線程 **/ public void destory(Exception ex){ if(ex !=null){ ex.printStackTrace(); Debug.outInfo("[SMGP]MO連接(收)線程異常停止,異常原因:" + ex.getMessage()); } else{ Debug.outInfo("[SMGP]MO連接(收)線程異常停止"); } SMGPSocketProcess.getInstance().disclose(); this.isAvail = false; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -