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

📄 smsreceivethread.java

📁 短信
💻 JAVA
字号:
package com.asiainfo.batchsend.sms.sms;

import org.apache.log4j.Logger;

import com.asiainfo.batchsend.sms.sms.cmpp.CMPP_Service;
import com.asiainfo.batchsend.sms.sms.cmpp.type.CMPP2;
import com.asiainfo.batchsend.sms.sms.cmpp.type.CMPP3;
import com.asiainfo.batchsend.sms.sms.cmpp.type.CMPP_DR;
import com.asiainfo.batchsend.sms.sms.cmpp.type.CMPP_YX;
import com.asiainfo.batchsend.sms.sms.cmpp.type.CMPP_HW;
import com.asiainfo.batchsend.sms.sms.cmpp.type.CMPP_SX;
import com.asiainfo.batchsend.util.SmsUtil;

/**
 * <p>Title: 短信网关接收线程</p>
 * <p>Description: 负责从短信网关中接收数据存入sms_received表中</p>
 * <p>Company: Asiainfo Technologies(China),Inc </p>
 * <p>Date: Nov 6, 2007 3:55:51 PM </p>
 * <p>Email to: jiangyl@asiainfo.com </p>
 * @author jiangyl
 * @version 1.0
 */

public class SmsReceiveThread extends Thread {
	private static final Logger log = Logger.getLogger(SmsReceiveThread.class);

	private CMPP_Service cmpp = null;
	private SmsChannelConfig config = null; 
	private int verson = 0;

	private boolean safeExit = false;

	public void safeExit() {
		this.safeExit = true;
	}
	
	public SmsReceiveThread(String channelId) {
		super("SMS-SmsReceiveThread");
	    //从配置文件中获取 网关类型
		config = SmsUtil.getSmsConfig(channelId);
		String gatewaytype = config.getGatewaytype().trim();
		if(gatewaytype.equals("CMPP2")){
			this.cmpp = new CMPP2();
			this.verson = 0x20;
		} else if(gatewaytype.equals("CMPP3")){
			this.cmpp = new CMPP3();
			this.verson = 0x30;
		} else if(gatewaytype.equals("DR")){
			this.cmpp = new CMPP_DR();
			this.verson = 0x12;
		} else if(gatewaytype.equals("YX")){
			this.cmpp = new CMPP_YX();
			this.verson = 0x30;
		} else if(gatewaytype.equals("HW")){
			this.cmpp = new CMPP_HW();
			this.verson = 0x30;
		} else if(gatewaytype.equals("SX")){
			this.cmpp = new CMPP_SX();
			this.verson = 0x30;
		}  
	}

	public void run() {		
		while ( !safeExit ){
			try {
				int stat = this.cmpp.initCMPP(config.getISMG_ADDR(), config.getICP_ID(),config.getICP_ID(),	config.getICP_PASS(), "", this.verson,config.getISMG_PORT(), "MO", config.getChannelId());
				log.info("接收线程短信网关链接状态 status = " + stat);
				if (stat==0) {			
					if (this.cmpp.activeTest()) {//获取接收包信息
						log.info("短信接收子线程" + currentThread().getName() + " 连接成功");
					}
					while ( !this.safeExit) {						
						this.cmpp.deliver();
			            try{
			            	Thread.sleep(1000);
			            }catch (Exception ex) {
			            }
	                }
					log.info("短信接收子线程" + currentThread().getName()+ "已经成功退出");
				 }else{
					 log.info("短信接收子线程建立短信网关的连接失败");
				 }
	
			} catch (Exception ex) {
				log.error("短信接收子线程" + currentThread().getName() + "出错",ex);			
			} finally {
				try{
					this.cmpp.quit();
				} catch(Exception e){
					e.printStackTrace();
				}	
				log.info("以" + config.getICP_ID() + "/" + config.getICP_PASS() + "建立到短信网关(" + config.getISMG_ADDR() + ":" + config.getISMG_PORT()	+ ")的连接已经退出.");
			}
		}

	}	

}

⌨️ 快捷键说明

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