|
@@ -2,19 +2,24 @@ package com.saga.thread.common;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
|
|
|
import org.zillion.util.log.LogUtil;
|
|
|
|
|
|
import com.saga.entity.Record;
|
|
|
+import com.saga.entity.Report;
|
|
|
import com.saga.util.Constant;
|
|
|
|
|
|
public class SaveThread extends Thread {
|
|
|
// private List<String> pointCommunicationList = new ArrayList<String>();
|
|
|
// private String ip = null;
|
|
|
- private List<String> streportList = new ArrayList<String>();
|
|
|
- private List<Record> strecordList = new ArrayList<Record>();
|
|
|
+
|
|
|
+ private Map<String, List<String>> streportList = new HashMap<String, List<String>>();
|
|
|
+ private List<Report> strecordList = new ArrayList<Report>();
|
|
|
|
|
|
public SaveThread() {
|
|
|
try {
|
|
@@ -68,7 +73,15 @@ public class SaveThread extends Thread {
|
|
|
synchronized (Constant.CollectReportList) {
|
|
|
if (Constant.CollectReportList.size() > 0) {
|
|
|
LogUtil.info("Constant.CollectReportList:" + Constant.CollectReportList.size());
|
|
|
- this.streportList.addAll(Constant.CollectReportList);
|
|
|
+ for (Entry<String, List<String>> cr : Constant.CollectReportList.entrySet()) {
|
|
|
+ if (!this.streportList.containsKey(cr.getKey())) {
|
|
|
+ this.streportList.put(cr.getKey(), new ArrayList<String>());
|
|
|
+ }
|
|
|
+ this.streportList.get(cr.getKey()).addAll(cr.getValue());
|
|
|
+ Constant.collectReportCount += cr.getValue().size();
|
|
|
+ LogUtil.info("ReportList." + cr.getKey() + ":" + cr.getValue().size());
|
|
|
+ }
|
|
|
+
|
|
|
Constant.CollectReportList.clear();
|
|
|
// Constant.CollectReportList = new ArrayList<String>();
|
|
|
LogUtil.info("Constant.CollectReportList:" + Constant.CollectReportList.size());
|
|
@@ -82,128 +95,142 @@ public class SaveThread extends Thread {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- Constant.collectReportCount += this.streportList.size();
|
|
|
- LogUtil.info("ReportList:" + this.streportList.size());
|
|
|
- int seq = 0;
|
|
|
|
|
|
- while (this.streportList.size() > 0) {
|
|
|
- seq++;
|
|
|
- LogUtil.info("ReportList:" + this.streportList.size() + " seq:" + seq);
|
|
|
- int no = 5000 > this.streportList.size() ? this.streportList.size() : 5000;
|
|
|
- if (no == 5000 || seq > 1) {
|
|
|
- LogUtil.info("ReportList:" + this.streportList.size() + " seq:" + seq);
|
|
|
- }
|
|
|
- String b = this.streportList.get(0).replace("(", "").replace(")", "").replace("", "");
|
|
|
- if (b == null || b.length() == 0) {
|
|
|
- this.streportList.remove(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- b = this.streportList.get(0).replace("(", "").replace(")", "").replace(" ", "").split(";")[0];
|
|
|
+ int seq = 0;
|
|
|
+ Map<String, String> recvlist = new HashMap<String, String>();
|
|
|
+ for (Entry<String, List<String>> rl : this.streportList.entrySet()) {
|
|
|
+ recvlist.put(rl.getKey(), rl.getKey());
|
|
|
+ }
|
|
|
+ for (Entry<String, String> r : recvlist.entrySet()) {
|
|
|
+ while (this.streportList.get(r.getKey()).size() > 0) {
|
|
|
+ seq++;
|
|
|
+ LogUtil.info("ReportList:" + this.streportList.get(r.getKey()).size() + " seq:" + seq);
|
|
|
+ int no = 5000 > this.streportList.get(r.getKey()).size() ? this.streportList.get(r.getKey()).size()
|
|
|
+ : 5000;
|
|
|
+ if (no == 5000 || seq > 1) {
|
|
|
+ LogUtil.info("ReportList:" + this.streportList.get(r.getKey()).size() + " seq:" + seq);
|
|
|
+ }
|
|
|
+ String b = this.streportList.get(r.getKey()).get(0).replace("(", "").replace(")", "").replace("",
|
|
|
+ "");
|
|
|
+ if (b == null || b.length() == 0) {
|
|
|
+ this.streportList.get(r.getKey()).remove(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ b = this.streportList.get(r.getKey()).get(0).replace("(", "").replace(")", "").replace(" ", "")
|
|
|
+ .split(";")[0];
|
|
|
|
|
|
- while (Constant.RecordListToDB.size() > 0) {
|
|
|
- if (Constant.RecordListToDB.size() == 0) {
|
|
|
- break;
|
|
|
- } else {
|
|
|
- Thread.sleep(3L);
|
|
|
+ while (Constant.RecordListToDB.size() > 0) {
|
|
|
+ if (Constant.RecordListToDB.size() == 0) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ Thread.sleep(3L);
|
|
|
+ }
|
|
|
+ Thread.sleep(1L);
|
|
|
}
|
|
|
- Thread.sleep(1L);
|
|
|
- }
|
|
|
|
|
|
- // recordList = new ArrayList<Record>();
|
|
|
- if (this.strecordList.size() > 0) {
|
|
|
- LogUtil.warn("SaveThread.recordList " + this.strecordList.size());
|
|
|
- this.strecordList.clear();
|
|
|
- System.gc();
|
|
|
- }
|
|
|
- Iterator<String> it = this.streportList.iterator();
|
|
|
- int c = 0;
|
|
|
- synchronized (Constant.ps_PointStatusUp) {
|
|
|
- while (it.hasNext()) {
|
|
|
- try {
|
|
|
- String report = it.next().replace("(", "").replace(")", "").replace(" ", "");
|
|
|
- if (c < no) {
|
|
|
- if (report != null) {
|
|
|
- String[] rList = report.replace("(", "").replace(")", "").replace(" ", "")
|
|
|
- .split(";");
|
|
|
- if (rList != null && rList.length > 8) {
|
|
|
- String building = rList[0];
|
|
|
- if (!building.equalsIgnoreCase(b)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- //String mac = rList[1];
|
|
|
- String function = rList[2];
|
|
|
- Date time = Constant.parse(rList[3]);
|
|
|
- String meter = rList[5];
|
|
|
- int count = Integer.valueOf(rList[6]);
|
|
|
- // String id = rList[4];
|
|
|
+ // recordList = new ArrayList<Record>();
|
|
|
+ if (this.strecordList.size() > 0) {
|
|
|
+ LogUtil.warn("SaveThread.recordList " + this.strecordList.size());
|
|
|
+ this.strecordList.clear();
|
|
|
+ System.gc();
|
|
|
+ }
|
|
|
+ Iterator<String> it = this.streportList.get(r.getKey()).iterator();
|
|
|
+ int c = 0;
|
|
|
+ synchronized (Constant.ps_PointStatusUp) {
|
|
|
+ while (it.hasNext()) {
|
|
|
+ try {
|
|
|
+ String report = it.next().replace("(", "").replace(")", "").replace(" ", "");
|
|
|
+ if (c < no) {
|
|
|
+ if (report != null) {
|
|
|
+ String[] rList = report.replace("(", "").replace(")", "").replace(" ", "")
|
|
|
+ .split(";");
|
|
|
+ if (rList != null && rList.length > 8) {
|
|
|
+ String building = rList[0];
|
|
|
+ if (!building.equalsIgnoreCase(b)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String mac = rList[1];
|
|
|
+ String function = rList[2];
|
|
|
+ Date time = Constant.parse(rList[3]);
|
|
|
+ String meter = rList[5];
|
|
|
+ int count = Integer.valueOf(rList[6]);
|
|
|
+ int id = Integer.valueOf(rList[4]);
|
|
|
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- Record record = new Record();
|
|
|
- if ("report".equalsIgnoreCase(function)) {
|
|
|
- record.funcID = Integer.valueOf(rList[7 + 2 * i]);
|
|
|
- record.data = Double.valueOf(rList[8 + 2 * i]);
|
|
|
- // synchronized
|
|
|
- // (Constant.pointListUp) {
|
|
|
- Constant.ps_PointStatusUp.put(
|
|
|
- building + "-" + meter + "." + record.funcID,
|
|
|
- System.currentTimeMillis());
|
|
|
- // }
|
|
|
+ for (int i = 0; i < count; i++) {
|
|
|
+ Report report2 = new Report();
|
|
|
+ Record record = new Record();
|
|
|
+ if ("report".equalsIgnoreCase(function)) {
|
|
|
+ record.funcID = Integer.valueOf(rList[7 + 2 * i]);
|
|
|
+ record.data = Double.valueOf(rList[8 + 2 * i]);
|
|
|
+ // synchronized
|
|
|
+ // (Constant.pointListUp) {
|
|
|
+ Constant.ps_PointStatusUp.put(
|
|
|
+ building + "-" + meter + "." + record.funcID,
|
|
|
+ System.currentTimeMillis());
|
|
|
+ // }
|
|
|
|
|
|
- } else if ("reportaddtion".equalsIgnoreCase(function)) {
|
|
|
- record.funcID = Integer.valueOf(rList[7 + 3 * i]);
|
|
|
- record.data = Double.valueOf(rList[8 + 3 * i]);
|
|
|
- record.addtion = "null".equalsIgnoreCase(rList[9 + i * 3]) ? ""
|
|
|
- : (rList[9 + i * 3]);
|
|
|
- // synchronized
|
|
|
- // (Constant.pointListUp) {
|
|
|
- Constant.ps_PointStatusUp.put(
|
|
|
- building + "-" + meter + "." + record.funcID,
|
|
|
- System.currentTimeMillis());
|
|
|
+ } else if ("reportaddtion".equalsIgnoreCase(function)) {
|
|
|
+ record.funcID = Integer.valueOf(rList[7 + 3 * i]);
|
|
|
+ record.data = Double.valueOf(rList[8 + 3 * i]);
|
|
|
+ record.addtion = "null".equalsIgnoreCase(rList[9 + i * 3]) ? ""
|
|
|
+ : (rList[9 + i * 3]);
|
|
|
+ // synchronized
|
|
|
+ // (Constant.pointListUp) {
|
|
|
+ Constant.ps_PointStatusUp.put(
|
|
|
+ building + "-" + meter + "." + record.funcID,
|
|
|
+ System.currentTimeMillis());
|
|
|
|
|
|
- // }
|
|
|
- }
|
|
|
+ // }
|
|
|
+ }
|
|
|
|
|
|
- record.buildingSign = building;
|
|
|
- record.meterSign = meter;
|
|
|
- record.receivetime = time;
|
|
|
+ record.buildingSign = building;
|
|
|
+ record.meterSign = meter;
|
|
|
+ record.receivetime = time;
|
|
|
+ report2.record = record;
|
|
|
|
|
|
- this.strecordList.add(record);
|
|
|
+ report2.ReportID = id;
|
|
|
+ report2.mac = mac;
|
|
|
+ report2.UploadName = r.getKey();
|
|
|
+ report2.ReportType = function;
|
|
|
+ this.strecordList.add(report2);
|
|
|
|
|
|
+ }
|
|
|
+ it.remove();
|
|
|
+ // LogUtil.info("HBase.BatchInsert "
|
|
|
+ // +
|
|
|
+ // report);
|
|
|
+ } else {
|
|
|
+ it.remove();
|
|
|
}
|
|
|
- it.remove();
|
|
|
- // LogUtil.info("HBase.BatchInsert "
|
|
|
- // +
|
|
|
- // report);
|
|
|
+
|
|
|
} else {
|
|
|
it.remove();
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
- it.remove();
|
|
|
+ break;
|
|
|
}
|
|
|
- } else {
|
|
|
- break;
|
|
|
+ c++;
|
|
|
+ // Thread.sleep(1L);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ it.remove();
|
|
|
+ LogUtil.error("SaveThread.run.Exception: " + e.toString());
|
|
|
}
|
|
|
- c++;
|
|
|
- // Thread.sleep(1L);
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- it.remove();
|
|
|
- LogUtil.error("SaveThread.run.Exception: " + e.toString());
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- Constant.RecordListToDB.addAll(this.strecordList);
|
|
|
- Constant.report2DBCount += this.strecordList.size();
|
|
|
- LogUtil.info("Constant.RecordListToDB add " + this.strecordList.size());
|
|
|
- // recordList = new ArrayList<Record>();
|
|
|
- this.strecordList.clear();
|
|
|
+ Constant.RecordListToDB.addAll(this.strecordList);
|
|
|
+ Constant.report2DBCount += this.strecordList.size();
|
|
|
+ LogUtil.info("Constant.RecordListToDB add " + this.strecordList.size());
|
|
|
+ // recordList = new ArrayList<Record>();
|
|
|
+ this.strecordList.clear();
|
|
|
|
|
|
- Thread.sleep(1L);
|
|
|
+ Thread.sleep(1L);
|
|
|
|
|
|
- // Thread.sleep(Constant.Millisecond.SECOND_1);
|
|
|
+ // Thread.sleep(Constant.Millisecond.SECOND_1);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if (this.streportList.size() > 0) {
|
|
|
LogUtil.warn("SaveThread.reportList " + streportList.size());
|
|
|
this.streportList.clear();
|