|
@@ -1,6 +1,5 @@
|
|
|
package com.saga.thread.up;
|
|
|
|
|
|
-import java.net.UnknownHostException;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
@@ -14,24 +13,24 @@ import com.persagy.communication.util.IServerManager;
|
|
|
import com.saga.entity.PointSet;
|
|
|
import com.saga.entity.Record;
|
|
|
import com.saga.util.Constant;
|
|
|
-import com.saga.util.HBaseUtil;
|
|
|
|
|
|
public class SendThread extends Thread {
|
|
|
|
|
|
private IServerManager uploadServer = null;
|
|
|
- private String ip = null;
|
|
|
+ // private String ip = null;
|
|
|
private Map<String, String> pointMac_UP = new HashMap<String, String>();
|
|
|
|
|
|
public SendThread(IServerManager uploadServer) {
|
|
|
// TODO Auto-generated constructor stub
|
|
|
try {
|
|
|
- try {
|
|
|
- this.ip = Constant.getLocalHostLANAddress().getHostAddress() + ":" + Constant.TypePort.get("Down");
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- this.ip = "0.0.0.0" + ":" + Constant.TypePort.get("Down");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ // try {
|
|
|
+ // // this.ip = Constant.getLocalHostLANAddress().getHostAddress()
|
|
|
+ // // + ":" + Constant.TypePort.get("Down");
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // // TODO Auto-generated catch block
|
|
|
+ // // this.ip = "0.0.0.0" + ":" + Constant.TypePort.get("Down");
|
|
|
+ // e.printStackTrace();
|
|
|
+ // }
|
|
|
this.uploadServer = uploadServer;
|
|
|
this.uploadServer.Start();
|
|
|
LogUtil.info("SendThread" + ": " + this.uploadServer.Name() + " Created ...");
|
|
@@ -83,120 +82,133 @@ public class SendThread extends Thread {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void returnPointSet() {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- try {
|
|
|
- synchronized (Constant.pointSetList) {
|
|
|
- if (Constant.pointSetList.size() > 0) {
|
|
|
- Iterator<PointSet> it = Constant.pointSetList.iterator();
|
|
|
- while (it.hasNext()) {
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- PointSet ps = it.next();
|
|
|
- // String address =
|
|
|
- // Constant.CollectorPointSetList.get(ps.buildingSign +
|
|
|
- // ";"
|
|
|
- // + ps.ID + ";");
|
|
|
- // String address = ps.address;
|
|
|
-
|
|
|
- if (!ps.uploadName.equalsIgnoreCase(this.uploadServer.Name())) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (ps.address == null) {
|
|
|
- break;
|
|
|
- }
|
|
|
- String MAC = ps.mac;
|
|
|
- if (this.pointMac_UP.containsKey(ps.buildingSignUP + "-" + ps.meterSign)) {
|
|
|
- MAC = this.pointMac_UP.get(ps.buildingSignUP + "-" + ps.meterSign);
|
|
|
- }
|
|
|
- // 已得到控制设备的反馈状态,移除
|
|
|
- if (ps.recTime > 0 && ps.sendTime > 0 && (ps.status != null && ps.status.length() > 0)) {
|
|
|
- sb.append(ps.buildingSignUP).append(";").append(MAC).append(";").append("pointsetack")
|
|
|
- .append(";").append(Constant.format(new Date())).append(";").append(ps.ID)
|
|
|
- .append(";").append(ps.meterSign).append(";").append(ps.funcID).append(";")
|
|
|
- .append(ps.status).append(";");
|
|
|
- this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
|
|
|
- Constant.sendSend += sb.toString().length();
|
|
|
- HBaseUtil.BatchInsert_Set2(Constant.agent, Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
- LogUtil.info(
|
|
|
- this.uploadServer.Name() + " AppendToSend: " + ps.address + " " + sb.toString());
|
|
|
-
|
|
|
- String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
|
|
|
- HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
- Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, this.ip, ps.mac,
|
|
|
- ps.meterSign, String.valueOf(ps.funcID), "down", "pointsetack",
|
|
|
- String.valueOf(ps.ID), Constant.format(new Date()), "finish:finish:" + ps.status);
|
|
|
- synchronized (Constant.ps_ID2Status) {
|
|
|
- Constant.ps_ID2Status.put(id, "finish:finish:" + ps.status);
|
|
|
- }
|
|
|
-
|
|
|
- // CSVUtil.insert(Constant.setlog, new
|
|
|
- // StringBuffer(Constant.format_Log(new Date())
|
|
|
- // + ": "
|
|
|
- // + ps.meterSign + "." + ps.funcID + " set " +
|
|
|
- // ps.dataSet + " " + ps.status + "!"
|
|
|
- // + " Consuming:" + (ps.recTime - ps.sendTime <
|
|
|
- // 0 ? 0 : ps.recTime - ps.sendTime)
|
|
|
- // + "ms!" + "\r\n"));
|
|
|
- it.remove();
|
|
|
-
|
|
|
- } // 超时未得到设备的反馈状态,移除
|
|
|
- else if (ps.recTime == 0 && ps.sendTime > 0
|
|
|
- && (System.currentTimeMillis() - ps.sendTime > Constant.getWaitingtime())) {
|
|
|
- sb.append(ps.buildingSignUP).append(";").append(MAC).append(";").append("pointsetack")
|
|
|
- .append(";").append(Constant.format(new Date())).append(";").append(ps.ID)
|
|
|
- .append(";").append(ps.meterSign).append(";").append(ps.funcID).append(";")
|
|
|
- .append("fail:timeout").append(";");
|
|
|
- this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
|
|
|
- Constant.sendSend += sb.toString().length();
|
|
|
- HBaseUtil.BatchInsert_Set3(Constant.agent, Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
- LogUtil.info(
|
|
|
- this.uploadServer.Name() + " AppendToSend: " + ps.address + " " + sb.toString());
|
|
|
- String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
|
|
|
-
|
|
|
- // LogUtil.info("InsertPointCommunicationLog" + "
|
|
|
- // begin");
|
|
|
- HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
- Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, this.ip, ps.mac,
|
|
|
- ps.meterSign, String.valueOf(ps.funcID), "down", "pointsetack",
|
|
|
- String.valueOf(ps.ID), Constant.format(new Date()),
|
|
|
- "finish:finish:" + "fail:timeout");
|
|
|
-
|
|
|
- synchronized (Constant.ps_ID2Status) {
|
|
|
- Constant.ps_ID2Status.put(id, "finish:finish:" + "fail:timeout");
|
|
|
- }
|
|
|
- // LogUtil.info("InsertPointCommunicationLog" + "
|
|
|
- // end");
|
|
|
-
|
|
|
- // CSVUtil.insert(Constant.setlog,
|
|
|
- // new StringBuffer(
|
|
|
- // Constant.format_Log(new Date()) + ": " +
|
|
|
- // ps.meterSign + "." + ps.funcID
|
|
|
- // + " set " + ps.dataSet + " fail(timeout) " +
|
|
|
- // "!" + " Consuming:"
|
|
|
- // + (System.currentTimeMillis() - ps.sendTime)
|
|
|
- // + "ms!" + "\r\n"));
|
|
|
- it.remove();
|
|
|
- }
|
|
|
- if (sb.length() > 0) {
|
|
|
- // Constant.CollectorPointSetList.remove(ps.buildingSign
|
|
|
- // + ";" + ps.ID + ";");
|
|
|
- break;
|
|
|
- // CSVUtil.insert(Constant.setlog, new
|
|
|
- // StringBuffer(Constant.format_Log(new Date())
|
|
|
- // + ": "
|
|
|
- // + this.uploadClient.Name() + " AppendToSend:
|
|
|
- // " + sb.toString() + "\r\n"));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- LogUtil.error("SendThread.returnPointSet.Exception: " + e.toString());
|
|
|
- }
|
|
|
- }
|
|
|
+ // private void returnPointSet() {
|
|
|
+ // // TODO Auto-generated method stub
|
|
|
+ // try {
|
|
|
+ // synchronized (Constant.pointSetList) {
|
|
|
+ // if (Constant.pointSetList.size() > 0) {
|
|
|
+ // Iterator<PointSet> it = Constant.pointSetList.iterator();
|
|
|
+ // while (it.hasNext()) {
|
|
|
+ // StringBuffer sb = new StringBuffer();
|
|
|
+ // PointSet ps = it.next();
|
|
|
+ // // String address =
|
|
|
+ // // Constant.CollectorPointSetList.get(ps.buildingSign +
|
|
|
+ // // ";"
|
|
|
+ // // + ps.ID + ";");
|
|
|
+ // // String address = ps.address;
|
|
|
+ //
|
|
|
+ // if (!ps.uploadName.equalsIgnoreCase(this.uploadServer.Name())) {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (ps.address == null) {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // String MAC = ps.mac;
|
|
|
+ // if (this.pointMac_UP.containsKey(ps.buildingSignUP + "-" + ps.meterSign))
|
|
|
+ // {
|
|
|
+ // MAC = this.pointMac_UP.get(ps.buildingSignUP + "-" + ps.meterSign);
|
|
|
+ // }
|
|
|
+ // // 已得到控制设备的反馈状态,移除
|
|
|
+ // if (ps.recTime > 0 && ps.sendTime > 0 && (ps.status != null &&
|
|
|
+ // ps.status.length() > 0)) {
|
|
|
+ // sb.append(ps.buildingSignUP).append(";").append(MAC).append(";").append("pointsetack")
|
|
|
+ // .append(";").append(Constant.format(new
|
|
|
+ // Date())).append(";").append(ps.ID)
|
|
|
+ // .append(";").append(ps.meterSign).append(";").append(ps.funcID).append(";")
|
|
|
+ // .append(ps.status).append(";");
|
|
|
+ // this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
|
|
|
+ // Constant.sendSend += sb.toString().length();
|
|
|
+ // HBaseUtil.BatchInsert_Set2(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
+ // LogUtil.info(
|
|
|
+ // this.uploadServer.Name() + " AppendToSend: " + ps.address + " " +
|
|
|
+ // sb.toString());
|
|
|
+ //
|
|
|
+ // String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
|
|
|
+ // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, this.ip,
|
|
|
+ // ps.mac,
|
|
|
+ // ps.meterSign, String.valueOf(ps.funcID), "down", "pointsetack",
|
|
|
+ // String.valueOf(ps.ID), Constant.format(new Date()), "finish:finish:" +
|
|
|
+ // ps.status);
|
|
|
+ //
|
|
|
+ // synchronized (Constant.ps_ID2Status) {
|
|
|
+ // Constant.ps_ID2Status.put(id, "finish:finish:" + ps.status);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // CSVUtil.insert(Constant.setlog, new
|
|
|
+ // // StringBuffer(Constant.format_Log(new Date())
|
|
|
+ // // + ": "
|
|
|
+ // // + ps.meterSign + "." + ps.funcID + " set " +
|
|
|
+ // // ps.dataSet + " " + ps.status + "!"
|
|
|
+ // // + " Consuming:" + (ps.recTime - ps.sendTime <
|
|
|
+ // // 0 ? 0 : ps.recTime - ps.sendTime)
|
|
|
+ // // + "ms!" + "\r\n"));
|
|
|
+ // it.remove();
|
|
|
+ //
|
|
|
+ // } // 超时未得到设备的反馈状态,移除
|
|
|
+ // else if (ps.recTime == 0 && ps.sendTime > 0
|
|
|
+ // && (System.currentTimeMillis() - ps.sendTime >
|
|
|
+ // Constant.getWaitingtime())) {
|
|
|
+ // sb.append(ps.buildingSignUP).append(";").append(MAC).append(";").append("pointsetack")
|
|
|
+ // .append(";").append(Constant.format(new
|
|
|
+ // Date())).append(";").append(ps.ID)
|
|
|
+ // .append(";").append(ps.meterSign).append(";").append(ps.funcID).append(";")
|
|
|
+ // .append("fail:timeout").append(";");
|
|
|
+ // this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
|
|
|
+ // Constant.sendSend += sb.toString().length();
|
|
|
+ // HBaseUtil.BatchInsert_Set3(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
+ // LogUtil.info(
|
|
|
+ // this.uploadServer.Name() + " AppendToSend: " + ps.address + " " +
|
|
|
+ // sb.toString());
|
|
|
+ // String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
|
|
|
+ //
|
|
|
+ // // LogUtil.info("InsertPointCommunicationLog" + "
|
|
|
+ // // begin");
|
|
|
+ // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, this.ip,
|
|
|
+ // ps.mac,
|
|
|
+ // ps.meterSign, String.valueOf(ps.funcID), "down", "pointsetack",
|
|
|
+ // String.valueOf(ps.ID), Constant.format(new Date()),
|
|
|
+ // "finish:finish:" + "fail:timeout");
|
|
|
+ //
|
|
|
+ // synchronized (Constant.ps_ID2Status) {
|
|
|
+ // Constant.ps_ID2Status.put(id, "finish:finish:" + "fail:timeout");
|
|
|
+ // }
|
|
|
+ // // LogUtil.info("InsertPointCommunicationLog" + "
|
|
|
+ // // end");
|
|
|
+ //
|
|
|
+ // // CSVUtil.insert(Constant.setlog,
|
|
|
+ // // new StringBuffer(
|
|
|
+ // // Constant.format_Log(new Date()) + ": " +
|
|
|
+ // // ps.meterSign + "." + ps.funcID
|
|
|
+ // // + " set " + ps.dataSet + " fail(timeout) " +
|
|
|
+ // // "!" + " Consuming:"
|
|
|
+ // // + (System.currentTimeMillis() - ps.sendTime)
|
|
|
+ // // + "ms!" + "\r\n"));
|
|
|
+ // it.remove();
|
|
|
+ // }
|
|
|
+ // if (sb.length() > 0) {
|
|
|
+ // // Constant.CollectorPointSetList.remove(ps.buildingSign
|
|
|
+ // // + ";" + ps.ID + ";");
|
|
|
+ // break;
|
|
|
+ // // CSVUtil.insert(Constant.setlog, new
|
|
|
+ // // StringBuffer(Constant.format_Log(new Date())
|
|
|
+ // // + ": "
|
|
|
+ // // + this.uploadClient.Name() + " AppendToSend:
|
|
|
+ // // " + sb.toString() + "\r\n"));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // // TODO Auto-generated catch block
|
|
|
+ // LogUtil.error("SendThread.returnPointSet.Exception: " + e.toString());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
private void handlePopRece2(PacketEntity packageRece) {
|
|
|
// TODO Auto-generated method stub
|
|
@@ -225,12 +237,15 @@ public class SendThread extends Thread {
|
|
|
// Constant.id2status.put(id, "processing:rcvd");
|
|
|
|
|
|
try {
|
|
|
- HBaseUtil.Insert_ps_virtual_point_log(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], rList[5], Long.valueOf(rList[6]), this.getupdown(rList[2]),
|
|
|
- Constant.format(new Date()), Long.valueOf(rList[4]), rList[2], "processing:rcvd");
|
|
|
- } catch (UnknownHostException e1) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e1.printStackTrace();
|
|
|
+ // HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ // this.getupdown(rList[2]),
|
|
|
+ // Constant.format(new Date()), Long.valueOf(rList[4]),
|
|
|
+ // rList[2], "processing:rcvd");
|
|
|
+ Constant.Insert_agents_ps_virtual_point_log(rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ this.getupdown(rList[2]), System.currentTimeMillis(), Long.valueOf(rList[4]), rList[2],
|
|
|
+ "processing:rcvd");
|
|
|
} catch (Exception e1) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e1.printStackTrace();
|
|
@@ -292,18 +307,29 @@ public class SendThread extends Thread {
|
|
|
+ sb.toString());
|
|
|
// Constant.id2status.put(id, "finish:finish:" +
|
|
|
// "success");
|
|
|
- HBaseUtil.Insert_ps_virtual_point_log(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], rList[5], Long.valueOf(rList[6]), this.getupdown(rList[2]),
|
|
|
- Constant.format(new Date()), Long.valueOf(rList[4]), "pointreadack",
|
|
|
- "finish:finish:" + "success");
|
|
|
-
|
|
|
+ // HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ // this.getupdown(rList[2]),
|
|
|
+ // Constant.format(new Date()),
|
|
|
+ // Long.valueOf(rList[4]), "pointreadack",
|
|
|
+ // "finish:finish:" + "success");
|
|
|
+ Constant.Insert_agents_ps_virtual_point_log(rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ this.getupdown(rList[2]), System.currentTimeMillis(), Long.valueOf(rList[4]),
|
|
|
+ "pointreadack", "finish:finish:" + "success");
|
|
|
} else {
|
|
|
// Constant.id2status.put(id, "finish:finish:" +
|
|
|
// "fail");
|
|
|
- HBaseUtil.Insert_ps_virtual_point_log(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], rList[5], Long.valueOf(rList[6]), this.getupdown(rList[2]),
|
|
|
- Constant.format(new Date()), Long.valueOf(rList[4]), "pointreadack",
|
|
|
- "finish:finish:" + "fail");
|
|
|
+ // HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ // this.getupdown(rList[2]),
|
|
|
+ // Constant.format(new Date()),
|
|
|
+ // Long.valueOf(rList[4]), "pointreadack",
|
|
|
+ // "finish:finish:" + "fail");
|
|
|
+ Constant.Insert_agents_ps_virtual_point_log(rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ this.getupdown(rList[2]), System.currentTimeMillis(), Long.valueOf(rList[4]),
|
|
|
+ "pointreadack", "finish:finish:" + "fail");
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
@@ -321,18 +347,32 @@ public class SendThread extends Thread {
|
|
|
+ sb.toString());
|
|
|
// Constant.id2status.put(id, "finish:finish:" +
|
|
|
// "success");
|
|
|
- HBaseUtil.Insert_ps_virtual_point_log(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], rList[5], Long.valueOf(rList[6]), this.getupdown(rList[2]),
|
|
|
- Constant.format(new Date()), Long.valueOf(rList[4]), "realtimepointdataack",
|
|
|
- "finish:finish:" + "success");
|
|
|
+ // HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ // this.getupdown(rList[2]),
|
|
|
+ // Constant.format(new Date()),
|
|
|
+ // Long.valueOf(rList[4]),
|
|
|
+ // "realtimepointdataack",
|
|
|
+ // "finish:finish:" + "success");
|
|
|
+ Constant.Insert_agents_ps_virtual_point_log(rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ this.getupdown(rList[2]), System.currentTimeMillis(), Long.valueOf(rList[4]),
|
|
|
+ "realtimepointdataack", "finish:finish:" + "success");
|
|
|
|
|
|
} else {
|
|
|
// Constant.id2status.put(id, "finish:finish:" +
|
|
|
// "fail");
|
|
|
- HBaseUtil.Insert_ps_virtual_point_log(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], rList[5], Long.valueOf(rList[6]), this.getupdown(rList[2]),
|
|
|
- Constant.format(new Date()), Long.valueOf(rList[4]), "realtimepointdataack",
|
|
|
- "finish:finish:" + "fail");
|
|
|
+ // HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ // this.getupdown(rList[2]),
|
|
|
+ // Constant.format(new Date()),
|
|
|
+ // Long.valueOf(rList[4]),
|
|
|
+ // "realtimepointdataack",
|
|
|
+ // "finish:finish:" + "fail");
|
|
|
+ Constant.Insert_agents_ps_virtual_point_log(rList[0], rList[5], Long.valueOf(rList[6]),
|
|
|
+ this.getupdown(rList[2]), System.currentTimeMillis(), Long.valueOf(rList[4]),
|
|
|
+ "realtimepointdataack", "finish:finish:" + "fail");
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
@@ -379,14 +419,23 @@ public class SendThread extends Thread {
|
|
|
.append(ps.status).append(";");
|
|
|
this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
|
|
|
Constant.sendSend += sb.toString().length();
|
|
|
- HBaseUtil.BatchInsert_Set2(Constant.agent, Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
+ // HBaseUtil.BatchInsert_Set2(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
+ Constant.AgentsBatchInsert_Set2(Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
LogUtil.info(
|
|
|
this.uploadServer.Name() + " AppendToSend: " + ps.address + " " + sb.toString());
|
|
|
|
|
|
String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
|
|
|
- HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
- Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, ps.meterSign,
|
|
|
- Long.valueOf(ps.funcID), this.getupdown("pointsetack"), Constant.format(new Date()),
|
|
|
+ // HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSignUP),
|
|
|
+ // ps.buildingSignUP, ps.meterSign,
|
|
|
+ // Long.valueOf(ps.funcID),
|
|
|
+ // this.getupdown("pointsetack"),
|
|
|
+ // Constant.format(new Date()),
|
|
|
+ // Long.valueOf(ps.ID), "pointsetack",
|
|
|
+ // "finish:finish:" + ps.status);
|
|
|
+ Constant.Insert_agents_ps_virtual_point_log(ps.buildingSignUP, ps.meterSign,
|
|
|
+ Long.valueOf(ps.funcID), this.getupdown("pointsetack"), System.currentTimeMillis(),
|
|
|
Long.valueOf(ps.ID), "pointsetack", "finish:finish:" + ps.status);
|
|
|
|
|
|
synchronized (Constant.ps_ID2Status) {
|
|
@@ -412,16 +461,27 @@ public class SendThread extends Thread {
|
|
|
.append("fail:timeout").append(";");
|
|
|
this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
|
|
|
Constant.sendSend += sb.toString().length();
|
|
|
- HBaseUtil.BatchInsert_Set3(Constant.agent, Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
+ // HBaseUtil.BatchInsert_Set3(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
+ Constant.AgentsBatchInsert_Set3(Constant.BuildingDB.get(ps.buildingSign), ps);
|
|
|
+
|
|
|
LogUtil.info(
|
|
|
this.uploadServer.Name() + " AppendToSend: " + ps.address + " " + sb.toString());
|
|
|
String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
|
|
|
|
|
|
// LogUtil.info("InsertPointCommunicationLog" + "
|
|
|
// begin");
|
|
|
- HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
- Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, ps.meterSign,
|
|
|
- Long.valueOf(ps.funcID), this.getupdown("pointsetack"), Constant.format(new Date()),
|
|
|
+ // HBaseUtil.Insert_ps_virtual_point_log(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(ps.buildingSignUP),
|
|
|
+ // ps.buildingSignUP, ps.meterSign,
|
|
|
+ // Long.valueOf(ps.funcID),
|
|
|
+ // this.getupdown("pointsetack"),
|
|
|
+ // Constant.format(new Date()),
|
|
|
+ // Long.valueOf(ps.ID), "pointsetack",
|
|
|
+ // "finish:finish:" + "fail:timeout");
|
|
|
+
|
|
|
+ Constant.Insert_agents_ps_virtual_point_log(ps.buildingSignUP, ps.meterSign,
|
|
|
+ Long.valueOf(ps.funcID), this.getupdown("pointsetack"), System.currentTimeMillis(),
|
|
|
Long.valueOf(ps.ID), "pointsetack", "finish:finish:" + "fail:timeout");
|
|
|
|
|
|
synchronized (Constant.ps_ID2Status) {
|
|
@@ -460,150 +520,173 @@ public class SendThread extends Thread {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void handlePopRece(PacketEntity packageRece) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- if ((packageRece != null) && (packageRece.content.packetString != null)
|
|
|
- && (packageRece.content.packetString.length() > 0)) {
|
|
|
- LogUtil.info(this.uploadServer.Name() + " PopRece: " + packageRece.address + " "
|
|
|
- + packageRece.content.packetString);
|
|
|
- Constant.sendRec += packageRece.content.packetString.length();
|
|
|
- String results = packageRece.content.packetString.replace("(", "").replace(")", "").replace(" ", "");
|
|
|
- String[] resultArray = results.split("&");
|
|
|
-
|
|
|
- for (String result : resultArray) {
|
|
|
- String[] rList = result.split(";");
|
|
|
- if (rList.length > 6) {
|
|
|
- String MAC = rList[1];
|
|
|
-
|
|
|
- if (Constant.pointMAC.containsKey(rList[0] + "-" + rList[5])) {
|
|
|
- MAC = Constant.pointMAC.get(rList[0] + "-" + rList[5]);
|
|
|
- LogUtil.info("MAC:" + (rList[0] + "-" + rList[5]) + " " + rList[1] + "-->" + MAC);
|
|
|
- }
|
|
|
- String id = rList[0] + "-" + MAC + "-" + rList[4];
|
|
|
- String key = rList[0] + "-" + MAC + "-" + rList[5] + "." + rList[6];
|
|
|
- // Constant.id2time.put(id, System.currentTimeMillis());
|
|
|
- // Constant.id2point.put(id, key);
|
|
|
- // Constant.id2function.put(id, rList[2]);
|
|
|
- // Constant.id2status.put(id, "processing:rcvd");
|
|
|
-
|
|
|
- try {
|
|
|
- HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], this.ip, MAC, rList[5], (rList[6]), this.getupdown(rList[2]), rList[2],
|
|
|
- String.valueOf(rList[4]), Constant.format(new Date()), "processing:rcvd");
|
|
|
- } catch (UnknownHostException e1) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e1.printStackTrace();
|
|
|
- } catch (Exception e1) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e1.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- if ("pointset".equalsIgnoreCase(rList[2])) {
|
|
|
- // 1101070037;1;pointset;;123;1001;11;3.1
|
|
|
- synchronized (Constant.ps_ID2Time) {
|
|
|
- Constant.ps_ID2Time.put(id, System.currentTimeMillis());
|
|
|
- }
|
|
|
- synchronized (Constant.ps_ID2Point) {
|
|
|
- Constant.ps_ID2Point.put(id, key);
|
|
|
- }
|
|
|
- synchronized (Constant.ps_ID2Function) {
|
|
|
- Constant.ps_ID2Function.put(id, rList[2]);
|
|
|
- }
|
|
|
- synchronized (Constant.ps_ID2Status) {
|
|
|
- Constant.ps_ID2Status.put(id, "processing:rcvd");
|
|
|
- }
|
|
|
-
|
|
|
- PointSet ps = new PointSet();
|
|
|
- ps.uploadName = this.uploadServer.Name();
|
|
|
- ps.address = packageRece.address;
|
|
|
- ps.content = rList;
|
|
|
- ps.sendTime = 0;
|
|
|
- ps.recTime = 0;
|
|
|
- ps.buildingSign = rList[0];
|
|
|
- ps.buildingSignUP = rList[0];
|
|
|
- // 楼号有转换规则,且转换后的楼-表有数据才进行转换
|
|
|
- // 解决一楼多楼号时总有部分仪表无法下发的问题
|
|
|
- if (Constant.BuildingConv.containsKey(ps.buildingSign) && Constant.Meter_Collector_Control
|
|
|
- .containsKey(Constant.BuildingConv.get(ps.buildingSign) + "-" + ps.meterSign)) {
|
|
|
- ps.buildingSign = Constant.BuildingConv.get(ps.buildingSign);
|
|
|
- }
|
|
|
-
|
|
|
- ps.ID = Integer.valueOf(rList[4]);
|
|
|
- ps.meterSign = rList[5];
|
|
|
- ps.mac = MAC;
|
|
|
- this.pointMac_UP.put(ps.buildingSignUP + "-" + ps.meterSign, rList[1]);
|
|
|
- ps.funcID = Integer.valueOf(rList[6]);
|
|
|
- ps.dataSet = Double.valueOf(rList[7]);
|
|
|
- // String adress = packageRece.address;
|
|
|
- // String cmd = ps.buildingSign + ";" + ps.ID + ";";
|
|
|
- // +ps.meterSign + ";" + ps.funcID + ";"
|
|
|
- // + ps.dataSet;
|
|
|
-
|
|
|
- // Constant.CollectorPointSetList.put(cmd, adress);
|
|
|
- synchronized (Constant.pointSetList) {
|
|
|
- Constant.pointSetList.add(ps);
|
|
|
- }
|
|
|
-
|
|
|
- } else if (rList.length > 6 && "pointread".equalsIgnoreCase(rList[2])) {
|
|
|
- try {
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- sb = this.getCacheData(rList);
|
|
|
- if (sb != null && sb.toString().length() > 0) {
|
|
|
- this.uploadServer.AppendToSend(packageRece.address, new Packet(sb.toString()));
|
|
|
- LogUtil.info(this.uploadServer.Name() + " AppendToSend: " + packageRece.address + " "
|
|
|
- + sb.toString());
|
|
|
- // Constant.id2status.put(id, "finish:finish:" +
|
|
|
- // "success");
|
|
|
- HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], this.ip, rList[1], rList[5], (rList[6]), "down", "pointreadack",
|
|
|
- String.valueOf(rList[4]), Constant.format(new Date()),
|
|
|
- "finish:finish:" + "success");
|
|
|
- } else {
|
|
|
- // Constant.id2status.put(id, "finish:finish:" +
|
|
|
- // "fail");
|
|
|
- HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], this.ip, rList[1], rList[5], (rList[6]), "down", "pointreadack",
|
|
|
- String.valueOf(rList[4]), Constant.format(new Date()),
|
|
|
- "finish:finish:" + "fail");
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- LogUtil.error("SendThread.handlePopRece.pointread.Exception: " + e.toString());
|
|
|
- }
|
|
|
-
|
|
|
- } else if (rList.length > 6 && "realtimepointdata".equalsIgnoreCase(rList[2])) {
|
|
|
- try {
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- sb = this.getCacheData2(rList);
|
|
|
- if (sb != null && sb.toString().length() > 0) {
|
|
|
- this.uploadServer.AppendToSend(packageRece.address, new Packet(sb.toString()));
|
|
|
- LogUtil.info(this.uploadServer.Name() + " AppendToSend: " + packageRece.address + " "
|
|
|
- + sb.toString());
|
|
|
- // Constant.id2status.put(id, "finish:finish:" +
|
|
|
- // "success");
|
|
|
- HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
|
|
|
- "realtimepointdataack", String.valueOf(rList[4]), Constant.format(new Date()),
|
|
|
- "finish:finish:" + "success");
|
|
|
- } else {
|
|
|
- // Constant.id2status.put(id, "finish:finish:" +
|
|
|
- // "fail");
|
|
|
- HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
|
|
|
- rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
|
|
|
- "realtimepointdataack", String.valueOf(rList[4]), Constant.format(new Date()),
|
|
|
- "finish:finish:" + "fail");
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- LogUtil.error("SendThread.handlePopRece.realtimepointdata.Exception: " + e.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // private void handlePopRece(PacketEntity packageRece) {
|
|
|
+ // // TODO Auto-generated method stub
|
|
|
+ // if ((packageRece != null) && (packageRece.content.packetString != null)
|
|
|
+ // && (packageRece.content.packetString.length() > 0)) {
|
|
|
+ // LogUtil.info(this.uploadServer.Name() + " PopRece: " +
|
|
|
+ // packageRece.address + " "
|
|
|
+ // + packageRece.content.packetString);
|
|
|
+ // Constant.sendRec += packageRece.content.packetString.length();
|
|
|
+ // String results = packageRece.content.packetString.replace("(",
|
|
|
+ // "").replace(")", "").replace(" ", "");
|
|
|
+ // String[] resultArray = results.split("&");
|
|
|
+ //
|
|
|
+ // for (String result : resultArray) {
|
|
|
+ // String[] rList = result.split(";");
|
|
|
+ // if (rList.length > 6) {
|
|
|
+ // String MAC = rList[1];
|
|
|
+ //
|
|
|
+ // if (Constant.pointMAC.containsKey(rList[0] + "-" + rList[5])) {
|
|
|
+ // MAC = Constant.pointMAC.get(rList[0] + "-" + rList[5]);
|
|
|
+ // LogUtil.info("MAC:" + (rList[0] + "-" + rList[5]) + " " + rList[1] +
|
|
|
+ // "-->" + MAC);
|
|
|
+ // }
|
|
|
+ // String id = rList[0] + "-" + MAC + "-" + rList[4];
|
|
|
+ // String key = rList[0] + "-" + MAC + "-" + rList[5] + "." + rList[6];
|
|
|
+ // // Constant.id2time.put(id, System.currentTimeMillis());
|
|
|
+ // // Constant.id2point.put(id, key);
|
|
|
+ // // Constant.id2function.put(id, rList[2]);
|
|
|
+ // // Constant.id2status.put(id, "processing:rcvd");
|
|
|
+ //
|
|
|
+ // try {
|
|
|
+ // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], this.ip, MAC, rList[5], (rList[6]), this.getupdown(rList[2]),
|
|
|
+ // rList[2],
|
|
|
+ // String.valueOf(rList[4]), Constant.format(new Date()),
|
|
|
+ // "processing:rcvd");
|
|
|
+ // } catch (UnknownHostException e1) {
|
|
|
+ // // TODO Auto-generated catch block
|
|
|
+ // e1.printStackTrace();
|
|
|
+ // } catch (Exception e1) {
|
|
|
+ // // TODO Auto-generated catch block
|
|
|
+ // e1.printStackTrace();
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if ("pointset".equalsIgnoreCase(rList[2])) {
|
|
|
+ // // 1101070037;1;pointset;;123;1001;11;3.1
|
|
|
+ // synchronized (Constant.ps_ID2Time) {
|
|
|
+ // Constant.ps_ID2Time.put(id, System.currentTimeMillis());
|
|
|
+ // }
|
|
|
+ // synchronized (Constant.ps_ID2Point) {
|
|
|
+ // Constant.ps_ID2Point.put(id, key);
|
|
|
+ // }
|
|
|
+ // synchronized (Constant.ps_ID2Function) {
|
|
|
+ // Constant.ps_ID2Function.put(id, rList[2]);
|
|
|
+ // }
|
|
|
+ // synchronized (Constant.ps_ID2Status) {
|
|
|
+ // Constant.ps_ID2Status.put(id, "processing:rcvd");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // PointSet ps = new PointSet();
|
|
|
+ // ps.uploadName = this.uploadServer.Name();
|
|
|
+ // ps.address = packageRece.address;
|
|
|
+ // ps.content = rList;
|
|
|
+ // ps.sendTime = 0;
|
|
|
+ // ps.recTime = 0;
|
|
|
+ // ps.buildingSign = rList[0];
|
|
|
+ // ps.buildingSignUP = rList[0];
|
|
|
+ // // 楼号有转换规则,且转换后的楼-表有数据才进行转换
|
|
|
+ // // 解决一楼多楼号时总有部分仪表无法下发的问题
|
|
|
+ // if (Constant.BuildingConv.containsKey(ps.buildingSign) &&
|
|
|
+ // Constant.Meter_Collector_Control
|
|
|
+ // .containsKey(Constant.BuildingConv.get(ps.buildingSign) + "-" +
|
|
|
+ // ps.meterSign)) {
|
|
|
+ // ps.buildingSign = Constant.BuildingConv.get(ps.buildingSign);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // ps.ID = Integer.valueOf(rList[4]);
|
|
|
+ // ps.meterSign = rList[5];
|
|
|
+ // ps.mac = MAC;
|
|
|
+ // this.pointMac_UP.put(ps.buildingSignUP + "-" + ps.meterSign, rList[1]);
|
|
|
+ // ps.funcID = Integer.valueOf(rList[6]);
|
|
|
+ // ps.dataSet = Double.valueOf(rList[7]);
|
|
|
+ // // String adress = packageRece.address;
|
|
|
+ // // String cmd = ps.buildingSign + ";" + ps.ID + ";";
|
|
|
+ // // +ps.meterSign + ";" + ps.funcID + ";"
|
|
|
+ // // + ps.dataSet;
|
|
|
+ //
|
|
|
+ // // Constant.CollectorPointSetList.put(cmd, adress);
|
|
|
+ // synchronized (Constant.pointSetList) {
|
|
|
+ // Constant.pointSetList.add(ps);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // } else if (rList.length > 6 && "pointread".equalsIgnoreCase(rList[2])) {
|
|
|
+ // try {
|
|
|
+ // StringBuffer sb = new StringBuffer();
|
|
|
+ // sb = this.getCacheData(rList);
|
|
|
+ // if (sb != null && sb.toString().length() > 0) {
|
|
|
+ // this.uploadServer.AppendToSend(packageRece.address, new
|
|
|
+ // Packet(sb.toString()));
|
|
|
+ // LogUtil.info(this.uploadServer.Name() + " AppendToSend: " +
|
|
|
+ // packageRece.address + " "
|
|
|
+ // + sb.toString());
|
|
|
+ // // Constant.id2status.put(id, "finish:finish:" +
|
|
|
+ // // "success");
|
|
|
+ // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
|
|
|
+ // "pointreadack",
|
|
|
+ // String.valueOf(rList[4]), Constant.format(new Date()),
|
|
|
+ // "finish:finish:" + "success");
|
|
|
+ // } else {
|
|
|
+ // // Constant.id2status.put(id, "finish:finish:" +
|
|
|
+ // // "fail");
|
|
|
+ // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
|
|
|
+ // "pointreadack",
|
|
|
+ // String.valueOf(rList[4]), Constant.format(new Date()),
|
|
|
+ // "finish:finish:" + "fail");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // e.printStackTrace();
|
|
|
+ // LogUtil.error("SendThread.handlePopRece.pointread.Exception: " +
|
|
|
+ // e.toString());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // } else if (rList.length > 6 &&
|
|
|
+ // "realtimepointdata".equalsIgnoreCase(rList[2])) {
|
|
|
+ // try {
|
|
|
+ // StringBuffer sb = new StringBuffer();
|
|
|
+ // sb = this.getCacheData2(rList);
|
|
|
+ // if (sb != null && sb.toString().length() > 0) {
|
|
|
+ // this.uploadServer.AppendToSend(packageRece.address, new
|
|
|
+ // Packet(sb.toString()));
|
|
|
+ // LogUtil.info(this.uploadServer.Name() + " AppendToSend: " +
|
|
|
+ // packageRece.address + " "
|
|
|
+ // + sb.toString());
|
|
|
+ // // Constant.id2status.put(id, "finish:finish:" +
|
|
|
+ // // "success");
|
|
|
+ // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
|
|
|
+ // "realtimepointdataack", String.valueOf(rList[4]), Constant.format(new
|
|
|
+ // Date()),
|
|
|
+ // "finish:finish:" + "success");
|
|
|
+ // } else {
|
|
|
+ // // Constant.id2status.put(id, "finish:finish:" +
|
|
|
+ // // "fail");
|
|
|
+ // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
|
|
|
+ // Constant.BuildingDB.get(rList[0]),
|
|
|
+ // rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
|
|
|
+ // "realtimepointdataack", String.valueOf(rList[4]), Constant.format(new
|
|
|
+ // Date()),
|
|
|
+ // "finish:finish:" + "fail");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // e.printStackTrace();
|
|
|
+ // LogUtil.error("SendThread.handlePopRece.realtimepointdata.Exception: " +
|
|
|
+ // e.toString());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
private String getupdown(String function) {
|
|
|
// TODO Auto-generated method stub
|