精华帖 (1) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-02-02
08年了,我也把07年所做的工作总结一下。望各位朋友不吝指教。
一、名词解释 SMPP:短消息点对点协议,SMPP协议是一个国际标准,有SMS论坛制定,官方网址为smsforum.net,截至2006年7月2日,最新版本是5.0。曾经流行的版本是3.3、3.4。SMPP协议向后兼容的。
二、简要介绍
主要程序介绍:
三、主体程序介绍 while (keepRunning) { System.out.println(); System.out.println("- 1 start listener"); System.out.println("- 2 stop listener"); System.out.println("- 3 client"); System.out.println("- 4 start deliverMessage"); System.out.println("- 5 stop deliverMessage"); System.out.println("- 0 exit"); System.out.print("> "); optionInt = -1; try { option = keyboard.readLine(); optionInt = Integer.parseInt(option); } catch (Exception e) { optionInt = -1; } switch (optionInt) { case 1: startlistener(); break; case 2: stoplistener(); break; case 3: listclienter(); break; case 4: startdeliverMessage(); break; case 5: stopdeliverMessage();
public synchronized void start() throws IOException { debug.write("going to start SMSCListener on port " + port); if (!isReceiving) { serverConn = new com.logica.smpp.TCPIPConnection(port); serverConn.setReceiveTimeout(getAcceptTimeout()); serverConn.open(); keepReceiving = true; if (asynchronous) { debug.write("starting listener in separate thread."); Thread serverThread = new Thread(this); serverThread.start(); debug.write("listener started in separate thread."); } else { debug.write("going to listen in the context of current thread."); run(); } } else { debug.write("already receiving, not starting the listener."); } }
try { Connection connection = null; serverConn.setReceiveTimeout(getAcceptTimeout()); connection = serverConn.accept(); if (connection != null) { SMSCSession session = new SMSCSession(connection); session.setHashSet(hashSet); Thread thread = new Thread(session); thread.start(); sessionFactory.register(session); debug.write("SMSCListener launched a session on the accepted connection."); } else { debug.write("no connection accepted this time."); } } catch (InterruptedIOException e) { debug.write("InterruptedIOException accepting, timeout? -> " + e); } catch (IOException e) { event.write(e, "IOException accepting connection"); keepReceiving = false; }
if (calendar.getTimeInMillis() < (enquire_LinkTime + enquire_LinkTimeout * 1000)) { //判断是否连接超时 try { debug.write("SMSCSession going to receive a PDU"); pdu = receiver.receive(getReceiveTimeout()); } catch (Exception e) { debug .write("SMSCSession caught exception receiving PDU " + e.getMessage()); } if (pdu != null) { if (pdu.isRequest()) { debug.write("SMSCSession got request " + pdu.debugString()); requestWorker.clientRequest((Request) pdu); } else if (pdu.isResponse()) { debug.write("SMSCSession got response " + pdu.debugString()); requestWorker.clientResponse((Response) pdu); } else { debug .write("SMSCSession not reqest nor response => not doing anything."); } } }else { keepReceiving=false; }
// TODO 根据业务规则进行用户合法性验证 commandStatus = checkIdentity((BindRequest) request); if (commandStatus == 0) { // authenticated System.out.println(request.debugString()); BindResponse bindResponse = (BindResponse) request .getResponse(); serverResponse(bindResponse); // success => bound bound = true; } else { // system id not authenticated // get the response response = request.getResponse(); // set it the error command status response.setCommandStatus(commandStatus); // and send it to the client via serverResponse serverResponse(response); // bind failed, stopping the session session.stop(); }
if (isOutTime(sendsm.getDealTime())) {// dealTime如果没有填写,此时永远处理不到 sendsm.setState(SendSM.STATE_SMSC_FAIL); reportFailQueue.put(sendsm, 100); //分类保存 if (sendsm.getMessageType() == SendSM.MESSAGETYPE_CORP) { reportQueue.put(sendsm, 100); } else if (sendsm.getMessageType() == SendSM.MESSAGETYPE_CLIENT) { reportQueue_P.put(sendsm, 100); } } else { // 重新压回接收队列 deliverQueue.put(sendsm, 100); }
while (list != null && list.size() > 0) { try { sendsm = list.remove(list.size() - 1); if (sendsm != null) { deliverSM = this.convertSendsm(sendsm); } else { deliverSM = null; } if (deliverSM != null) { if (session.send(deliverSM)) { SMSCLog.SendLog(deliverSM); sendsm.setSequenceNumber(String .valueOf(deliverSM .getSequenceNumber())); sendsm.setDealTime(DataFormat.yyyy_MM_dd_HH_mm_ss .format(new Date())); deliverQueue.put(sendsm, 1000); } } Thread.sleep(intervalTime); } catch (Exception e) { log.error(e.getMessage(), e); } }
count = saveQueue.drainTo(list, batchSize); if (logger.isDebugEnabled()) { logger.debug("get element count["+count+"] from saveQeueue."); } if (count > 0) { int total = batchSave.batachSave(list); if (logger.isDebugEnabled()) { logger.debug("Save ["+total+"] records."); } } if (count < batchSize) { if (logger.isDebugEnabled()) { logger.debug("sleep "+sleepTime); } //小于0, 休眠 Thread.sleep(sleepTime); } else { Thread.yield(); //让其他程序有机会运行 }
因为时间比较紧,系统是在logica smsc的基础修改完成的,本人1周完成。主是加入了业务所需要的东西。因涉及非技术问题,此处只取了一部份代码。
ps: 做这个项目的时候,主要是为适应xx省smsc经过huiway改造之后的话单分检,大家开始都没有注意有可能出现这种情况,时间紧(大约只有1周时间),压力大(自己以前还没有smsc角色的程序,对smpp中的DeliverSM消息不太熟,后来果然在上面载了跟头,测试时总发现下发出去的消息是乱码,反复测试,编码格式也换了9种,后来才发现有个DeliverSM中的setDataCoding没有设置,郁闷),经过自己的努力和同事的帮助。基本上在一周内完成,包括测试用例。 现在这个系统已上线,到目前为止已正常运行2个月,从未出现过大问题。运行平台为redhat enterprise 4。
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 3128 次