作者 朱兆平

去除5秒一次限制

@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 package com.airport; 6 package com.airport;
7 7
8 import com.airport.core.AgentSender; 8 import com.airport.core.AgentSender;
  9 +import com.airport.core.IMFNoDelaySender;
9 import com.airport.core.IMFReader; 10 import com.airport.core.IMFReader;
10 import com.airport.core.IMFSender; 11 import com.airport.core.IMFSender;
11 import com.airport.util.ConfigUtils; 12 import com.airport.util.ConfigUtils;
@@ -51,8 +52,9 @@ public class Main { @@ -51,8 +52,9 @@ public class Main {
51 52
52 //数据仓库给九州的发送程序 53 //数据仓库给九州的发送程序
53 Timer timer = new Timer(); 54 Timer timer = new Timer();
54 - IMFSender CangKu2Jiuzhou = new IMFSender(client,"data/fid_index.txt");  
55 - timer.schedule(CangKu2Jiuzhou, 10000L, 1200000L); 55 + IMFNoDelaySender CangKu2Jiuzhou = new IMFNoDelaySender(client,"data/fid_index.txt");
  56 + CangKu2Jiuzhou.start();
  57 +// timer.schedule(CangKu2Jiuzhou, 10000L, 1200000L);
56 58
57 } 59 }
58 } 60 }
  1 +//
  2 +// Source code recreated from a .class file by IntelliJ IDEA
  3 +// (powered by Fernflower decompiler)
  4 +//
  5 +
  6 +package com.airport.core;
  7 +
  8 +import com.airport.bean.MessageBak;
  9 +import com.airport.bean.XMLHeader;
  10 +import com.airport.dao.Dao;
  11 +import com.airport.dao.impl.DaoImpl;
  12 +import com.airport.util.ConfigUtils;
  13 +import com.airport.util.SystemBean;
  14 +import com.airport.util.Utils;
  15 +import com.airport.util.parse.IMFXMLMaker;
  16 +import com.airport.util.parse.XMPParse;
  17 +import com.caac.imf.api.IMFClient;
  18 +import org.apache.commons.lang.StringUtils;
  19 +import org.apache.log4j.Logger;
  20 +
  21 +import java.util.Iterator;
  22 +import java.util.List;
  23 +import java.util.Map;
  24 +import java.util.TimerTask;
  25 +
  26 +public class IMFNoDelaySender extends Thread{
  27 + private static final Logger logger = Logger.getLogger(IMFSender.class);
  28 + private Dao dao = (DaoImpl)SystemBean.getBean("dao");
  29 + private IMFClient client;
  30 + private String indexFileName; //记录发送数据的节点
  31 +
  32 + public IMFNoDelaySender(IMFClient client, String fileName) {
  33 + this.indexFileName = fileName;
  34 + this.client = client;
  35 + }
  36 +
  37 + public void run() {
  38 + try {
  39 +
  40 + if (this.client == null) {
  41 + logger.info("IMFClient has been closed");
  42 + return;
  43 + }
  44 +
  45 + while(true) {
  46 + //初始化读取
  47 + logger.info("job start:");
  48 + int lastFID = Utils.readFIDIndex(this.indexFileName);
  49 + int maxFID = this.dao.getMaxFID();
  50 + logger.info("lastFID=" + lastFID + " maxFID=" + maxFID);
  51 + int is_ok = 0;
  52 +
  53 + if (maxFID > lastFID) {
  54 + List<MessageBak> list = this.dao.getRecordByFID(lastFID); //查询大于[FID]350的报文
  55 + Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP;
  56 + Iterator var7 = list.iterator();
  57 +
  58 + while(var7.hasNext()) {
  59 + MessageBak m = (MessageBak)var7.next();
  60 + if (is_ok != 0) {
  61 + logger.error("记录FID时发生异常,发送消息任务被迫中断");
  62 + return;
  63 + }
  64 +
  65 + if (m.getContent() != null) {
  66 + int times = 0;
  67 + //配置文件里面有几个sender 这里循环几次
  68 + for(Iterator var10 = map.keySet().iterator(); var10.hasNext(); Thread.sleep((long)ConfigUtils.SEND_MESSAGE_INTERVAL)) {
  69 + Integer key = (Integer)var10.next();
  70 + XMLHeader header = (XMLHeader)map.get(key);
  71 + logger.info("key=" + key + " value=" + ((XMLHeader)map.get(key)).toString());
  72 + logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length());
  73 +
  74 +
  75 + //初始化最终发布报文内容的存储器
  76 + String sendMsg = "";
  77 + String xmlStr = m.getContent();
  78 +//_____________________________________解析华东的报文-------------------------------------------------------------------------------------------
  79 + if (xmlStr.contains("<MessageType>IS1</MessageType>")){
  80 + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","IS1");
  81 + haiguanXml.setIMFContent(m.getContent());
  82 + sendMsg = haiguanXml.finalXmlStr();
  83 + }else if(xmlStr.contains("<MessageType>ES1</MessageType>") ){
  84 + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","ES1");
  85 + haiguanXml.setIMFContent(m.getContent());
  86 + sendMsg = haiguanXml.finalXmlStr();
  87 + }else if(xmlStr.contains("<MessageType>CLR</MessageType>")){
  88 + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","CLR");
  89 + haiguanXml.setIMFContent(m.getContent());
  90 + sendMsg = haiguanXml.finalXmlStr();
  91 + }else if(xmlStr.contains("<MessageType>RSC</MessageType>")){
  92 + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","RSC");
  93 + haiguanXml.setIMFContent(m.getContent());
  94 + sendMsg = haiguanXml.finalXmlStr();
  95 + } else {
  96 +//_____________________________________解析天信达的报文,读取配置文件,替换相关参数-------------------------------------------------------------------------------------------
  97 + sendMsg= Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR");
  98 + sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); //替换报文主类型
  99 +
  100 + String stype = tranlateXML(m.getContent());
  101 + sendMsg = Utils.searchReplace(sendMsg, stype, "STYP");
  102 + sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR");
  103 + }
  104 +//_____________________________________给多式联运的航空报文,读取配置文件,生成新的META,并把最原始的报文封装到新报文的content里面--------------------------------------------------------------------
  105 +// String sndr = header.getSndr();
  106 +// String type = header.getType();
  107 +// String styp = header.getStype();
  108 +//
  109 +// IMFXMLMaker newXml = new IMFXMLMaker(sndr,Integer.toString(m.getFid()),type,styp);
  110 +// newXml.setIMFContent(m.getContent());
  111 +// sendMsg = newXml.finalXmlStr();
  112 +
  113 + if (!"".equals(sendMsg)) {
  114 + logger.info("开始发送数据 XML:" + sendMsg);
  115 + String is_send_ok = this.client.sendMSG(sendMsg);
  116 + logger.info("is_send_ok=" + is_send_ok);
  117 + is_ok = Utils.writeFIDIndex(this.indexFileName, m.getRownum_()); //发送成功写入节点文件
  118 + logger.debug("FID:" + m.getFid() + " 缓存成功");
  119 + ++times;
  120 + } else {
  121 + logger.error("查找替换节点数据出现异常,可能找不到这个节点,原始XML=" + m.getContent());
  122 + }
  123 + }
  124 +
  125 +// this.dao.update(m.getFid(), times);
  126 + } else {
  127 + logger.info("FID=" + m.getFid() + "XML is null ");
  128 + }
  129 + }
  130 + }
  131 + }
  132 +
  133 + }catch (Exception var14) {
  134 + var14.printStackTrace();
  135 + logger.info(var14.getMessage());
  136 + }
  137 + }
  138 +
  139 + private static String tranlateXML(String xml) throws Exception {
  140 + String stype = XMPParse.getNodeValueFromXmlString(xml, "/MSG/META/STYP");
  141 + if (!StringUtils.isBlank(stype)) {
  142 + if (ConfigUtils.XTYPE_MAP.containsKey(stype)) {
  143 + stype = (String)ConfigUtils.XTYPE_MAP.get(stype);
  144 + } else {
  145 + logger.info("stype=" + stype + " 在对应关系里找不到这个KEY");
  146 + }
  147 + } else {
  148 + logger.info(" 在XML找不到STYPE这个节点");
  149 + stype = "";
  150 + }
  151 +
  152 + return stype;
  153 + }
  154 +}
@@ -27,7 +27,7 @@ public class IMFSender extends TimerTask { @@ -27,7 +27,7 @@ public class IMFSender extends TimerTask {
27 private static final Logger logger = Logger.getLogger(IMFSender.class); 27 private static final Logger logger = Logger.getLogger(IMFSender.class);
28 private Dao dao = (DaoImpl)SystemBean.getBean("dao"); 28 private Dao dao = (DaoImpl)SystemBean.getBean("dao");
29 private IMFClient client; 29 private IMFClient client;
30 - private String indexFileName; 30 + private String indexFileName; //记录发送数据的节点
31 31
32 public IMFSender(IMFClient client, String fileName) { 32 public IMFSender(IMFClient client, String fileName) {
33 this.indexFileName = fileName; 33 this.indexFileName = fileName;
@@ -46,6 +46,7 @@ public class IMFSender extends TimerTask { @@ -46,6 +46,7 @@ public class IMFSender extends TimerTask {
46 int maxFID = this.dao.getMaxFID(); 46 int maxFID = this.dao.getMaxFID();
47 logger.info("lastFID=" + lastFID + " maxFID=" + maxFID); 47 logger.info("lastFID=" + lastFID + " maxFID=" + maxFID);
48 int is_ok = 0; 48 int is_ok = 0;
  49 +
49 if (maxFID > lastFID) { 50 if (maxFID > lastFID) {
50 List<MessageBak> list = this.dao.getRecordByFID(lastFID); //查询大于[FID]350的报文 51 List<MessageBak> list = this.dao.getRecordByFID(lastFID); //查询大于[FID]350的报文
51 Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP; 52 Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP;
@@ -111,7 +112,7 @@ public class IMFSender extends TimerTask { @@ -111,7 +112,7 @@ public class IMFSender extends TimerTask {
111 logger.info("开始发送数据 XML:" + sendMsg); 112 logger.info("开始发送数据 XML:" + sendMsg);
112 String is_send_ok = this.client.sendMSG(sendMsg); 113 String is_send_ok = this.client.sendMSG(sendMsg);
113 logger.info("is_send_ok=" + is_send_ok); 114 logger.info("is_send_ok=" + is_send_ok);
114 - is_ok = Utils.writeFIDIndex(this.indexFileName, m.getRownum_()); 115 + is_ok = Utils.writeFIDIndex(this.indexFileName, m.getRownum_()); //发送成功写入节点文件
115 logger.debug("FID:" + m.getFid() + " 缓存成功"); 116 logger.debug("FID:" + m.getFid() + " 缓存成功");
116 ++times; 117 ++times;
117 } else { 118 } else {
@@ -122,7 +122,7 @@ public class DaoImpl implements Dao { @@ -122,7 +122,7 @@ public class DaoImpl implements Dao {
122 public List<MessageBak> getRecordByFID(int fid) { 122 public List<MessageBak> getRecordByFID(int fid) {
123 //从配置文件读取sql语句 123 //从配置文件读取sql语句
124 String sql_select=ConfigUtils.SQl; 124 String sql_select=ConfigUtils.SQl;
125 - String sql = String.format(sql_select, fid, fid, ConfigUtils.RECORD_COUNT); //这里修改从FID_INDEX文件读取的FID ,改为取搜索结果的rownum 125 + String sql = String.format(sql_select, fid, fid, ConfigUtils.RECORD_COUNT); //这里修改从FID_INDEX文件读取的FID ,改为取搜索结果的rownum,此处FID代表ROWNUM
126 logger.info(sql); 126 logger.info(sql);
127 final LobHandler lobHandler = new DefaultLobHandler(); 127 final LobHandler lobHandler = new DefaultLobHandler();
128 final ArrayList xmlList = new ArrayList(); 128 final ArrayList xmlList = new ArrayList();