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

📄 cmpp3mo.java

📁 java支持的短信平台
💻 JAVA
字号:
package com.khan.sms.cmpp3control;

import com.khan.util.*;
import com.khan.sms.cmpp3.*;
import com.khan.db.*;
import com.khan.datetime.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Cmpp3MO implements Runnable {
  static boolean flag = true;
  RecvQueue rq = null;
  SendQueue sq = null;
  CmppParam cp = null;


  public Cmpp3MO(CmppParam cp, RecvQueue rq, SendQueue sq) {
    this.cp = cp;
    this.rq = rq;
    this.sq = sq;
    common.Assert("debug:Cmpp3MO 处理线程建立");
  }


  public static void stopThread() {
    flag = false;
  }


  //0 DELIVRD, 1 EXPIRED, 2 DELETED, 3 UNDELIV, 4 ACCEPTD, 5 UNKNOWN, 6 REJECTD
  private int parseStatusReport(String status) {
    int result = 5;

    if (status != null) {
      return result;
    }

    status = status.trim();

    if (status.equals("DELIVRD")) {
      result = 0;
    } else if (status.equals("EXPIRED")) {
      result = 1;
    } else if (status.equals("DELETED")) {
      result = 2;
    } else if (status.equals("UNDELIV")) {
      result = 3;
    } else if (status.equals("ACCEPTD")) {
      result = 4;
    } else if (status.equals("REJECTD")) {
      result = 6;
    } else if (status.equals("UNKNOWN")) {
      result = 7;
    } else { //其他错误,从日志中查找
      result = 8;
    }

    return result;
  }

  private void processMO(Cmpp3Data data) {
    int command = data.CommandID;
    if (command == Cmpp3Command.CMPP_DELIVER) {
      Cmpp3Deliver cd = (Cmpp3Deliver) data;
      if (cd.IsReport == 0) { //普通MO, 插入上行表
        DBPoolCon dbp = null;
        String sqlstr = "Insert into SP_MO(Msg_ID, OrgAddr, "
                        + "DestAddr, ServiceID, "
                        + "MsgFmt, UserData_Len, "
                        + "UserData, PID, "
                        + "UDHI, SeqID ,LinkID"
                        + ") "
                        + "Values('" + cd.Msg_ID.toString() + "','" + cd.Src_Terminal + "',"
                        + "'" + cd.Dest_ID + "','" + cd.Service_ID + "',"
                        + " " + cd.Msg_FMT + "," + cd.Msg_Length + ", "
                        + "'" + cd.Msg_Content + "', " + cd.Tp_PID + ","
                        + " " + cd.Tp_UDHI + ", '" + cd.getSeqID() + "','"
                        + new String(cd.LinkID) + "')";
        try {
          dbp = cp.Cmpp_DB.get();
          common.PoolExcuteSql(dbp, sqlstr);
        } finally {
          cp.Cmpp_DB.release(dbp);
        }
        cp.LogMain.logOut(cd.toString());
      } else { //状态报告

        DBPoolCon dbp = cp.Cmpp_DB.get();
        String sqlstr = "Update SP_Mt Set SendResult = 1,"
                        + "ReportStatus=" + parseStatusReport(cd.Statu_Report.Stat)
                        + " Where RespMsgID='" + cd.Statu_Report.Msg_Id.toString() + "'";
        try {
          common.PoolExcuteSql(dbp, sqlstr);
          //common.Assert(sqlstr); //test
        } finally {
          cp.Cmpp_DB.release(dbp);
        }
        cp.LogMain.logOut(cd.Statu_Report.toString());
      }
    } else if (command == Cmpp3Command.CMPP_SUBMIT_RESP) {
      Cmpp3SubmitResp csr = (Cmpp3SubmitResp) data;
      sq.remove(csr.getSeqID());

      DBPoolCon dbp = null;
      String sqlstr = "Update SP_Mt Set SendResult = " + csr.Result
                      + ", SendTime = '" + SMPTime.getSqlServerDateString(SMPTime.getNow())
                      + "', RespMsgID = '" + csr.Msg_Id + "'"
                      + " Where ID=" + csr.getSeqID();
      try {
        dbp = cp.Cmpp_DB.get();
        common.PoolExcuteSql(dbp, sqlstr);
      } finally {
        cp.Cmpp_DB.release(dbp);
      }
    }

  }


  public void run() {
    common.Assert("debug:" + Thread.currentThread().getName() + "线程启动!");
    common.sleep(cp.SEND_SLEEP);
    try {
      while (flag) {
        Cmpp3Data data = rq.get();
        if (data != null) {
          processMO(data);
        }
        common.sleep(10);
      }

      if (!flag) { //确保收到退出指令后,MO队列中的数据能被处理
        Cmpp3Data data = rq.get();
        //System.out.println("Debug:MO CommondID"+MsgID.toHexString(MsgID.toByteArray(data.CommandID)));
        while (data != null) {
          processMO(data);
          data = rq.get();
        }
      }
    } finally {
      common.Assert("debug:" + Thread.currentThread().getName() + "线程停止!");
    }
  }


  protected void finalize() {
    common.Assert("debug:" + Thread.currentThread().getName() + "线程被注销!");
  }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -