会话线程安全吗?SMPP Logica Library

时间:2013-02-25 04:29:04

标签: java smpp

我想问...目前我正在使用SMPP Logica Library ...开发SMSC客户端......我正在使用session.submit向smsc服务器发送消息,发送消息差不多50条消息/秒,以及我想使用线程进行多次发送,因为我需要来自服务器的每个响应来获取交付报告...问题是..是session.submit是线程安全的吗?我应该在使用线程发送消息之前首先同步会话吗? 我用来发送消息的代码是

   {
        response = session.submit(sm);
                  SUBMIT_SM_RESP(response,mt);
    ........

    }
         private void SUBMIT_SM_RESP(SubmitSMResp pdu,MTData mtd) {

              log.info("CommandID From PDU "+pdu.getCommandId());
              //SubmitSMResp submitSMResp = new SubmitSMResp();
              if (pdu.getCommandId() == Data.SUBMIT_SM_RESP ){
                //  submitSMResp.setData(pdu.getData());
                  switch (pdu.getCommandStatus())
                  {
                  case 0:
                    log.info("Berhasil kirim MT; SeqNo=" + pdu.getSequenceNumber() + ";" + pdu.debugString());
                    break;
                  case 1031:
                    log.info("Error. Service not found; SeqNo=" + pdu.getSequenceNumber() + ";" +pdu.debugString());
                    break;
                  case 1032:
                    log.info("Error. Invalid TX Id; SeqNo=" + pdu.getSequenceNumber() + ";" +pdu.debugString());
                    break;


 case 1033:
                log.info("Error. Push limit exceeded; SeqNo=" + pdu.getSequenceNumber() + ";" + pdu.debugString());
                break;
              case 4107:
                log.info("Error. Content Whitelisted (Testingmode); SeqNo=" + pdu.getSequenceNumber() + ";" +pdu.debugString());
                break;
              case 1280:
                  log.info("Insuficient Balance(Charging); SeqNo=" + pdu.getSequenceNumber() + ";" +pdu.debugString());
                break;
              }

              log.debug("MT rec status: CommandID=SUBMIT_SM_RESP; SeqNo=" + pdu.getSequenceNumber() + "; CommandSts=" + pdu.getCommandStatus() + pdu.debugString());
              //MTData mt = (MTData)DataInstance.getInstance().getHmSeqMT().get(Integer.valueOf(pdu.getSequenceNumber()));
              MTData mt =mtd;
              String tid = null;
              if (mt == null) {
                  log.info("MT null");
             //   if (DataInstance.getInstance().getHmSeqTrxID().containsKey(Integer.valueOf(pdu.getSequenceNumber()))) {
    //              tid = (String)DataInstance.getInstance().getHmSeqTrxID().get(Integer.valueOf(pdu.getSequenceNumber()));
    //              mt = DataInstance.getInstance().getDbPrs().getMTTrxID(tid);
    //              log.info("MT rec status: CommandID=SUBMIT_SM_RESP; SeqNo=" + pdu.getSequenceNumber() + "; CommandSts=" + pdu.getCommandStatus() + "; trxid=" + tid + "; " + pdu.debugString());
            //      if (mt == null) {
                    log.info("MT rec status: CommandID=SUBMIT_SM_RESP; SeqNo=" + pdu.getSequenceNumber() + "; CommandSts=" + pdu.getCommandStatus() + "; trxid=" + tid + " n/a; " + pdu.debugString());
                    mt = DataInstance.getInstance().getDbPrs().getMTSeqNo(String.valueOf(pdu.getSequenceNumber()));

            //     }
              //  }
              }
              else {
                  tid = mt.getTransid();
                  }
            //  log.info(mt.getClass());
             log.info("Transaction ID >>> "+mt.getTransid());
              if (mt != null) {
                DataInstance.getInstance().getDbPrs().deleteMT(mt, 
                  String.valueOf(pdu.getCommandStatus()), DataInstance.getInstance().getTransX().operator);
                DataInstance.getInstance().getHmSeqMT().remove(Integer.valueOf(pdu.getSequenceNumber()));
              } else {
                log.info("MT Null,,,Can't Send DR");
                log.info("MT n/a: SeqNo=" + pdu.getSequenceNumber() + "; CommandSts=" + pdu.getCommandStatus() + pdu.debugString());
              }
          }
          else
          {
              log.info("Nilai Enquiry Link "+Data.ENQUIRE_LINK_RESP);
          }
        }

此致

丹茨

1 个答案:

答案 0 :(得分:0)

在同步模式下,它始终是线程安全的(就像您现在尝试的那样)。这是一个完全不同的故事,进入异步模式。