📄 cmppconnectionmanager.java
字号:
return true;
} catch (Exception e) {
System.out.println("wayoutsp loadCfgFile: "+e.toString() );
PublicConstants.writeLog.info("wayoutsp loadCfgFile: "+e,0);
return false;
}
}
/**
*
* @param sendDataBean sendDataBean
*/
public void sendToIsmg(SendDataBean sendDataBean){
ShortMsgCmpp cmpp_sm = new ShortMsgCmpp();
try {
cmpp_sm.headCmdID = CmppConstants.Cmpp_Submit;
cmpp_sm.headSeqcNo = ComConstants.getSeqNo();
//cmpp_sm.headSeqcNo = sendDataBean.headSeqcNo;
cmpp_sm.submit_destusr_tl=(byte)sendDataBean.getDestAddrNum();
cmpp_sm.msgMode = sendDataBean.registeredDelivery;
cmpp_sm.msgSubmitDest = sendDataBean.getDestAddrs();
cmpp_sm.msgSrcAddr = sendDataBean.srcAddr;
cmpp_sm.msgServiceType=sendDataBean.servieceType;
cmpp_sm.msgContent = sendDataBean.sendData;
cmpp_sm.msgLength = (byte) cmpp_sm.msgContent.getBytes().length;
cmpp_sm.msgFeeType=sendDataBean.feeType;
cmpp_sm.msgInfoFee=sendDataBean.infoFee;
cmpp_sm.msgPriority = sendDataBean.msgLevel;
cmpp_sm.feeTerminalId=sendDataBean.feeTerminalId;
cmpp_sm.msgFeeUserType = sendDataBean.feeUserType;
cmpp_sm.msgPkTotal=sendDataBean.pkTotal;
cmpp_sm.msgPkNumber=sendDataBean.pkNumber;
cmpp_sm.spId=sendDataBean.msgSrc;
cmpp_sm.msgLinkId = sendDataBean.linkId;
cmpp_sm.msgDataCoding = sendDataBean.dataCoding;
/**
* 以下是写死的固定值
*/
cmpp_sm.submit_msg_id=(long)0;
cmpp_sm.msgProtocolId = 0;
cmpp_sm.msgValidityPeriod = "";
cmpp_sm.msgSchedule = ""; //"0209041640000000+"""0000-0000-0000-0000-0"
cmpp_sm.msgDeliverTime = "";
cmpp_sm.msgReserve = "";
// if( !connectionSubmit.getStatus().equals(ComConstants.WORKING) )
// {
// connectionSubmit.disconnect() ;
// if(connectionSubmit.connect())
// connectionSubmit.Login() ;
// PublicFuction.threadSleep(100);
// }
// cmpp_sm.msgContent =com.wayout.wayoutsp.publics.BlackWordCheck.getInstance().ifExistBlackWord(cmpp_sm.msgContent);
// if(cmpp_sm.msgContent.length()<50){
// cmpp_sm.msgContent=ReplaceString.replace(cmpp_sm.msgContent,"<Adv_List>",BlackWordCheck.getInstance().getOneADWord());
// }
// if(!com.wayout.wayoutsp.publics.BlackListCheck.getInstance().ifExistUser(cmpp_sm.msgSubmitDest)){
if(send(cmpp_sm) == 0)
{
//PublicConstants.writeLog.info("发送目的地址: ",1);
for(int i=0;i<cmpp_sm.submit_destusr_tl;i++)
{
PublicConstants.writeLog.info("destAddr: "+cmpp_sm.msgSubmitDest[i],1);
}
PublicConstants.writeLog.info("\nsrcAddr: "+cmpp_sm.msgSrcAddr+"\n"+
"serviceType: "+cmpp_sm.msgServiceType+"\n"+
"msgContent: "+cmpp_sm.msgContent+"\n" +
"msgLinkid: "+cmpp_sm.msgLinkId+"\n" +
"Msg send succ !",2);
}
// }
} catch (Exception exp) {
PublicConstants.writeLog.info("Msg send error:\n"+
"destAddr: "+cmpp_sm.msgDestAddr+"\n"+
"msgContent: "+cmpp_sm.msgContent+"\n"+
exp.getMessage() ,0);
}
}
/**
* 发送Cmpp消息.
* @param cmpp_sm ShortMsgCmpp对象
* @return
* 0: 保存数据成功(含发送失败)
* -1: 目标spId为null
* -2: 保存数据到缓冲失败(溢出)
*/
public int send( ShortMsgCmpp cmpp_sm ) {
// if ( !connectionSubmit.getStatus().equals(ComConstants.WORKING) ) {
// PublicConstants.writeLog.error("Cmpp error Connection status:"+connectionSubmit.getStatus());
// //return -1;
// }
//System.out.println("Cmpp sended:"+connectionSubmit.mysign);
if (connectionSubmit.ifClosed()) {
connectionSubmit.disconnect();
if (connectionSubmit.connect()) {
connectionSubmit.Login();
System.out.println("connectionSubmit.reconnect() ok!");
PublicFuction.threadSleep(1000);
}
}
connectionSubmit.send(cmpp_sm);
// PublicFuction.threadSleep(5);
return 0;
}
/**
* 报文重发.
* @param bb 需重发的二进制报文
* @param spId 目标spId
*/
/* public void send( byte[] bb , String spId) {
PublicConstants.writeLog.info("Cmpp reSend to spId: "+spId,1);
CmppConnection mc = route(spId );
if ( mc == null ) {
Constants.writeLog.error("Cmpp Connection not found . DestId:"+spId);
return;
}
if ( mc.getBindType()==Constants.RECV_ONLY ) {
Constants.writeLog.error("Cmpp Resend to Recv_Only connection . losed ...");
return;
}
if ( !mc.getStatus().equals(Constants.WORKING) ) {
Constants.writeLog.error("Cmpp Resend error connection status: "+mc.getStatus() );
return;
}
mc.send(bb);
}
*/
/**
* 启动写数据库线程
*/
public void startSaveDataThread() {
saveCmppData = new CmppSaveData();
saveCmppData.start();
}
/**
* 启动管理器维护线程 <br>
* 1、连接维护 <br>
* 2、写数据库线程维护<br>
* 3、重发线程维护 <br>
*/
public void startMaintanceThread() {
String str;
Thread internalThread;
Runnable r = new Runnable() {
public void run() {
PublicConstants.writeLog.info("Cmpp maintance Thread started .",0 );
PublicFuction.threadSleep(5000) ;
int i =0;
while (! myShutdownFlag) {
try {
PublicFuction.threadSleep(1000) ;
if( ! saveCmppData.isAlive() ) {
saveCmppData.tStop();
PublicConstants.writeLog.error("cmpp savedata thread not alive ! restart ...") ;
startSaveDataThread();
}
if (!connectionSubmit.isAlive()) {
connectionSubmit.destroy();
connectionSubmit.start();
}
// if( !connectionSubmit.getStatus().equals(ComConstants.WORKING) )
// {
// connectionSubmit.disconnect() ;
// if(connectionSubmit.connect())
// connectionSubmit.Login() ;
// }
// {
// connectionDeliever.disconnect() ;
// if( connectionDeliever.connect() )
// connectionDeliever.Login() ;
// }
if ( i >=10 )
{
//System.out.println("NotDealMsgNum:"+connectionDeliever.getNotDealMsgNum());
System.out.println("NotSubmitMsgNum:"+connectionSubmit.getNotSubmitMsgNum());
i =0;
}
i++;
/*if(! sendThread.isAlive() ||! recvThread.isAlive())
{
connectIsmg();
}*/
//if( ! reSendThread.isAlive() ) {
// reSendThread.tStop();
// Constants.writeLog.error("cmpp reSend thread not alive ! restart ...") ;
// startReSendThread();
//}
} catch ( Exception e ) {
// in case ANY exception slips through
PublicConstants.writeLog.error("cmpp MaintanceThread: " + e.toString() );
}
}
}
};
internalThread = new Thread(r);
internalThread.start();
}
/**
* 启动重发线程
*/
public void startReSendThread() {
}
// save all CDR messages to the database
public boolean saveMsg(ShortMsgCmpp sm) {
return false;
}
public String getIsmgStatus() {
return "";
}
/**
* 关闭Cmpp连接管理器
* 1、关闭各Cmpp连接
* 2、清空路由表
* 3、关闭重发及写数据库线程
*/
public void shutdownCmpp() {
}
// public String getName() {
// return myname;
// }
public int getSize() {
return myconnection.size();
}
public Enumeration getCmppConnections() {
return myconnection.elements();
}
public static int testConnectionNo=0;
private String myname;
private int mysize; //路由表初始大小
private static Hashtable myconnection; //路由表
private ServerSocket mysvrsock; //本地服务socket
private boolean myShutdownFlag = false; //管理器关闭标志
private Timer timerMbcp = null; //流量统计定时器
private static CmppConnectionManager mbcpCM = null;
// private static Thread svrCmppThread; //服务线程
// private static CmppReSend reSendThread; //重发线程
public static CmppSaveData saveCmppData;//写数据库线程
private static CmppConnection connectionSubmit;
public static ConnectionServer connectionDeliever;
//private static CmppConnection serverConnection;
public static Thread svrCmppThread; //服务线程
//private static Thread sendThread;
//private static Thread recvThread;
}
class ChildThreadDeliver extends Thread
{
private Socket conn;
public ChildThreadDeliver(Socket sockets){
conn=sockets;
}
public void run()
{
try {
CmppConnectionManager.connectionDeliever.setupSocket(conn);
byte[] login = CmppConnectionManager.connectionDeliever.recv();
System.out.println("login......"+login.length);
if(login.length==1){
System.out.println("login...errooooooooo...");
}else{
CmppConnectionManager.connectionDeliever.handle(login);
}
// System.out.println("login_rep.....");
byte[] deliver = CmppConnectionManager.connectionDeliever.recv();
int deliverNum=0;
System.out.println("deliver...."+deliver.length);
while(deliver.length >1){
CmppConnectionManager.connectionDeliever.handle(deliver);
// System.out.println("deliver_rep.....");
deliver = CmppConnectionManager.connectionDeliever.recv();
deliverNum++;
System.out.println("deliver...."+deliver.length +"deliverNum"+deliverNum);
}
System.out.println("logout_rep...");
}
catch (Exception ex) {
System.out.println(" ,,,,,,,,,,Exception"+ex.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -