2008-05-26
RequestWoker.java
package com.msp.smg;
import java.util.List;
import org.apache.log4j.Logger;
import com.logica.smpp.Connection;
import com.logica.smpp.Data;
import com.logica.smpp.Receiver;
import com.logica.smpp.Session;
import com.logica.smpp.TCPIPConnection;
import com.logica.smpp.pdu.BindRequest;
import com.logica.smpp.pdu.BindResponse;
import com.logica.smpp.pdu.BindTransmitter;
import com.logica.smpp.pdu.Response;
import com.logica.smpp.pdu.SubmitSM;
import com.logica.smpp.pdu.UnbindResp;
import com.msp.smg.Queue;
public class RequestWorker extends Thread {
private final static Logger logger = Logger.getLogger(RequestWorker.class);
private boolean isRuning = true;
private boolean isConnectSMSC = false;
private boolean isBound = false;
private Session session = null;
private String sysId = "";
private String syspwd = "";
private String smscIP = "";
private int smscPort = 0;
private Receiver receiver = null;
ResponseWorker responseWorker = null;
private List<SendSM> sendsmList;
/**
* 连接到短信中心
*/
private void connectSMSC() {
try {
Connection conn = new TCPIPConnection(smscIP, smscPort);
session = new Session(conn);
isConnectSMSC = true;
} catch (Exception ex) {
isConnectSMSC = false;
ex.printStackTrace();
}
}
/**
* 实现绑定到短信中心的功能
*/
private void bindSMSC() {
if (isConnectSMSC && session != null) {
try {
BindRequest bindReq = new BindTransmitter();
bindReq.setSystemId(sysId);
bindReq.setPassword(syspwd);
BindResponse bindResponse = null;
bindResponse = session.bind(bindReq);
if (bindResponse.getCommandStatus() == Data.ESME_ROK) {
receiver = session.getReceiver();
if (responseWorker == null) {
responseWorker = new ResponseWorker();
}
responseWorker.setReceiver(receiver);
responseWorker.start();
isBound = true;
} else {
isBound = false;
}
} catch (Exception ex) {
isBound = false;
ex.printStackTrace();
}
} else {
logger.info("连接到短信中心的connection失效!");
}
}
public SendSM getSendSM() {
SendSM sendsm = null;
try {
if (sendsmList != null && sendsmList.size() > 0) {
sendsm = (SendSM) sendsmList.remove(0);
}
} catch (Exception e) {
sendsm = null;
}
return sendsm;
}
public void run() {
SendSM sendsm = null;
while (isRuning) {
try {
// System.out.println("smscIP=" + smscIP + ",smscPort=" +
// smscPort
// + ",sysId=" + sysId + ",syspwd=" + syspwd);
/*
* while (!isConnectSMSC) { this.connectSMSC(); } if (!isBound) {
* this.bindSMSC(); } while (isBound && this.getSendSM() !=
* null) { sendShortMessage(sendsm); } ; this.unBind();
*/
} finally {
isRuning = true;
}
}
}
/*
* 发送短信
*/
public void sendShortMessage(SendSM sendsm) {
SubmitSM request = new SubmitSM();
try {
request.setSourceAddr(sendsm.getSourceAddr());
request.setDestAddr(sendsm.getDescAddr());
request.setShortMessage(sendsm.getShortMessage());
session.submit(request);
// getStatus(response);
} catch (Exception e) {
logger.info(e.getMessage(), e);
}
}
public void unBind() {
try {
UnbindResp response = session.unbind();
getStatus(response);
} catch (Exception e) {
e.printStackTrace();
}
}
public void getStatus(Response response) {
if (response.getCommandStatus() == Data.ESME_ROK) {
//
} else {
}
}
public void setSmscIP(String smscIP) {
this.smscIP = smscIP;
}
public void setSmscPort(int smscPort) {
this.smscPort = smscPort;
}
public void setSysId(String sysId) {
this.sysId = sysId;
}
public void setSyspwd(String syspwd) {
this.syspwd = syspwd;
}
}
发表评论
- 浏览: 16927 次
- 性别:


- 详细资料
搜索本博客
我的相册
睿睿和他妈妈
共 4 张
共 4 张
最近加入圈子
链接
最新评论
-
用lucene对时间索引后搜索 ...
unique5945 写道caocao 写道那是因为RangeQuery内部被r ...
-- by caocao -
用lucene对时间索引后搜索 ...
caocao 写道那是因为RangeQuery内部被rewrite成许多Term ...
-- by unique5945 -
Linux上NFS共享
/etc/fstab的格式: fs_spec fs_file fs ...
-- by yinhj -
Linux上NFS共享
exportfs命令: 如果我们在启动了NFS之后又修改了/etc/expor ...
-- by yinhj -
用lucene对时间索引后搜索 ...
那是因为RangeQuery内部被rewrite成许多TermQuery,时间精 ...
-- by caocao






评论排行榜